1996-10-23 09:59:13 -07:00
|
|
|
/*
|
|
|
|
* Generate include file dependencies
|
|
|
|
*
|
|
|
|
* Copyright 1996 Alexandre Julliard
|
2002-03-09 16:29:33 -07:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 05:49:52 -07:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1996-10-23 09:59:13 -07:00
|
|
|
*/
|
|
|
|
|
2002-04-26 12:05:15 -07:00
|
|
|
#include "config.h"
|
2003-03-20 14:08:28 -07:00
|
|
|
#define NO_LIBWINE_PORT
|
2002-04-26 12:05:15 -07:00
|
|
|
#include "wine/port.h"
|
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
#include <assert.h>
|
1996-10-23 09:59:13 -07:00
|
|
|
#include <ctype.h>
|
2006-08-01 03:13:57 -07:00
|
|
|
#include <errno.h>
|
1996-10-23 09:59:13 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-04-06 21:00:16 -07:00
|
|
|
#include <stdarg.h>
|
1996-10-23 09:59:13 -07:00
|
|
|
#include <string.h>
|
2002-08-17 11:28:43 -07:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2006-08-01 03:13:57 -07:00
|
|
|
#include "wine/list.h"
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
/* Max first-level includes per file */
|
2002-02-15 12:57:27 -07:00
|
|
|
#define MAX_INCLUDES 200
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
typedef struct _INCL_FILE
|
|
|
|
{
|
2006-08-01 03:13:57 -07:00
|
|
|
struct list entry;
|
1996-10-23 09:59:13 -07:00
|
|
|
char *name;
|
|
|
|
char *filename;
|
2000-11-05 22:32:59 -07:00
|
|
|
struct _INCL_FILE *included_by; /* file that included this one */
|
|
|
|
int included_line; /* line where this file was included */
|
2002-02-15 12:57:27 -07:00
|
|
|
int system; /* is it a system include (#include <name>) */
|
1996-10-23 09:59:13 -07:00
|
|
|
struct _INCL_FILE *owner;
|
|
|
|
struct _INCL_FILE *files[MAX_INCLUDES];
|
|
|
|
} INCL_FILE;
|
|
|
|
|
2006-08-01 03:13:57 -07:00
|
|
|
static struct list sources = LIST_INIT(sources);
|
|
|
|
static struct list includes = LIST_INIT(includes);
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
typedef struct _INCL_PATH
|
|
|
|
{
|
2006-08-01 03:13:57 -07:00
|
|
|
struct list entry;
|
|
|
|
const char *name;
|
1996-10-23 09:59:13 -07:00
|
|
|
} INCL_PATH;
|
|
|
|
|
2006-08-01 03:13:57 -07:00
|
|
|
static struct list paths = LIST_INIT(paths);
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
static const char *SrcDir = NULL;
|
|
|
|
static const char *OutputFileName = "Makefile";
|
|
|
|
static const char *Separator = "### Dependencies";
|
|
|
|
static const char *ProgramName;
|
2006-08-01 03:16:29 -07:00
|
|
|
static int input_line;
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
static const char Usage[] =
|
|
|
|
"Usage: %s [options] [files]\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -Idir Search for include files in directory 'dir'\n"
|
|
|
|
" -Cdir Search for source files in directory 'dir'\n"
|
|
|
|
" -fxxx Store output in file 'xxx' (default: Makefile)\n"
|
|
|
|
" -sxxx Use 'xxx' as separator (default: \"### Dependencies\")\n";
|
|
|
|
|
|
|
|
|
2004-04-06 21:00:16 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* xmalloc
|
|
|
|
*/
|
2006-08-01 03:16:29 -07:00
|
|
|
static void *xmalloc( size_t size )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
|
|
|
void *res;
|
|
|
|
if (!(res = malloc (size ? size : 1)))
|
2004-04-06 21:00:16 -07:00
|
|
|
fatal_error( "%s: Virtual memory exhausted.\n", ProgramName );
|
1996-10-23 09:59:13 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* xrealloc
|
|
|
|
*/
|
|
|
|
void *xrealloc (void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
void *res;
|
|
|
|
assert( size );
|
|
|
|
if (!(res = realloc( ptr, size )))
|
|
|
|
fatal_error( "%s: Virtual memory exhausted.\n", ProgramName );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* xstrdup
|
|
|
|
*/
|
|
|
|
static char *xstrdup( const char *str )
|
|
|
|
{
|
|
|
|
char *res = strdup( str );
|
2004-04-06 21:00:16 -07:00
|
|
|
if (!res) fatal_error( "%s: Virtual memory exhausted.\n", ProgramName );
|
1996-10-23 09:59:13 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-10 17:38:56 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* get_extension
|
|
|
|
*/
|
|
|
|
static char *get_extension( char *filename )
|
|
|
|
{
|
|
|
|
char *ext = strrchr( filename, '.' );
|
|
|
|
if (ext && strchr( ext, '/' )) ext = NULL;
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* get_line
|
|
|
|
*/
|
|
|
|
static char *get_line( FILE *file )
|
|
|
|
{
|
|
|
|
static char *buffer;
|
|
|
|
static unsigned int size;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
size = 1024;
|
|
|
|
buffer = xmalloc( size );
|
|
|
|
}
|
|
|
|
if (!fgets( buffer, size, file )) return NULL;
|
|
|
|
input_line++;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char *p = buffer + strlen(buffer);
|
|
|
|
/* if line is larger than buffer, resize buffer */
|
|
|
|
while (p == buffer + size - 1 && p[-1] != '\n')
|
|
|
|
{
|
|
|
|
buffer = xrealloc( buffer, size * 2 );
|
|
|
|
fgets( buffer + size - 1, size + 1, file );
|
|
|
|
p = buffer + strlen(buffer);
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
if (p > buffer && p[-1] == '\n')
|
|
|
|
{
|
|
|
|
*(--p) = 0;
|
|
|
|
if (p > buffer && p[-1] == '\r') *(--p) = 0;
|
|
|
|
if (p > buffer && p[-1] == '\\')
|
|
|
|
{
|
|
|
|
*(--p) = 0;
|
|
|
|
/* line ends in backslash, read continuation line */
|
|
|
|
fgets( p, size - (p - buffer), file );
|
|
|
|
input_line++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-05 22:32:59 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* is_generated
|
|
|
|
*
|
|
|
|
* Test if a given file type is generated during the make process
|
|
|
|
*/
|
|
|
|
static int is_generated( const char *name )
|
|
|
|
{
|
|
|
|
static const char * const extensions[] = { ".tab.h", ".mc.rc" };
|
2000-11-10 17:38:37 -07:00
|
|
|
size_t i, len = strlen(name);
|
2000-11-05 22:32:59 -07:00
|
|
|
for (i = 0; i < sizeof(extensions)/sizeof(extensions[0]); i++)
|
|
|
|
{
|
|
|
|
if (len <= strlen(extensions[i])) continue;
|
|
|
|
if (!strcmp( name + len - strlen(extensions[i]), extensions[i] )) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* add_include_path
|
|
|
|
*
|
|
|
|
* Add a directory to the include path.
|
|
|
|
*/
|
|
|
|
static void add_include_path( const char *name )
|
|
|
|
{
|
|
|
|
INCL_PATH *path = xmalloc( sizeof(*path) );
|
2006-08-01 03:13:57 -07:00
|
|
|
list_add_tail( &paths, &path->entry );
|
1996-10-23 09:59:13 -07:00
|
|
|
path->name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* add_src_file
|
|
|
|
*
|
|
|
|
* Add a source file to the list.
|
|
|
|
*/
|
|
|
|
static INCL_FILE *add_src_file( const char *name )
|
|
|
|
{
|
|
|
|
INCL_FILE *file = xmalloc( sizeof(*file) );
|
|
|
|
memset( file, 0, sizeof(*file) );
|
|
|
|
file->name = xstrdup(name);
|
2006-08-01 03:13:57 -07:00
|
|
|
list_add_tail( &sources, &file->entry );
|
1996-10-23 09:59:13 -07:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* add_include
|
|
|
|
*
|
|
|
|
* Add an include file if it doesn't already exists.
|
|
|
|
*/
|
2002-02-15 12:57:27 -07:00
|
|
|
static INCL_FILE *add_include( INCL_FILE *pFile, const char *name, int line, int system )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2006-08-01 03:13:57 -07:00
|
|
|
INCL_FILE *include;
|
2004-04-06 21:00:16 -07:00
|
|
|
char *ext;
|
1996-10-23 09:59:13 -07:00
|
|
|
int pos;
|
|
|
|
|
|
|
|
for (pos = 0; pos < MAX_INCLUDES; pos++) if (!pFile->files[pos]) break;
|
|
|
|
if (pos >= MAX_INCLUDES)
|
2004-04-06 21:00:16 -07:00
|
|
|
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" ))
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2004-04-06 21:00:16 -07:00
|
|
|
if ((ext = strrchr( pFile->filename, '.' )) && !strcmp( ext, ".h" ))
|
|
|
|
fatal_error( "%s:%d: config.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 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 );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
2006-08-01 03:13:57 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( include, &includes, INCL_FILE, entry )
|
|
|
|
if (!strcmp( name, include->name )) goto found;
|
|
|
|
|
|
|
|
include = xmalloc( sizeof(INCL_FILE) );
|
|
|
|
memset( include, 0, sizeof(INCL_FILE) );
|
|
|
|
include->name = xstrdup(name);
|
|
|
|
include->included_by = pFile;
|
|
|
|
include->included_line = line;
|
|
|
|
include->system = system || pFile->system;
|
|
|
|
list_add_tail( &includes, &include->entry );
|
|
|
|
found:
|
|
|
|
pFile->files[pos] = include;
|
|
|
|
return include;
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* open_src_file
|
|
|
|
*/
|
|
|
|
static FILE *open_src_file( INCL_FILE *pFile )
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
|
2002-12-10 18:30:14 -07:00
|
|
|
/* first try name as is */
|
|
|
|
if ((file = fopen( pFile->name, "r" )))
|
|
|
|
{
|
|
|
|
pFile->filename = xstrdup( pFile->name );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
/* now try in source dir */
|
1996-10-23 09:59:13 -07:00
|
|
|
if (SrcDir)
|
|
|
|
{
|
|
|
|
pFile->filename = xmalloc( strlen(SrcDir) + strlen(pFile->name) + 2 );
|
|
|
|
strcpy( pFile->filename, SrcDir );
|
|
|
|
strcat( pFile->filename, "/" );
|
|
|
|
strcat( pFile->filename, pFile->name );
|
2002-12-10 18:30:14 -07:00
|
|
|
file = fopen( pFile->filename, "r" );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
2002-12-10 18:30:14 -07:00
|
|
|
if (!file)
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2002-12-10 18:30:14 -07:00
|
|
|
perror( pFile->name );
|
1996-10-23 09:59:13 -07:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* open_include_file
|
|
|
|
*/
|
|
|
|
static FILE *open_include_file( INCL_FILE *pFile )
|
|
|
|
{
|
|
|
|
FILE *file = NULL;
|
|
|
|
INCL_PATH *path;
|
|
|
|
|
2006-08-01 03:13:57 -07:00
|
|
|
errno = ENOENT;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( path, &paths, INCL_PATH, entry )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
|
|
|
char *filename = xmalloc(strlen(path->name) + strlen(pFile->name) + 2);
|
|
|
|
strcpy( filename, path->name );
|
|
|
|
strcat( filename, "/" );
|
|
|
|
strcat( filename, pFile->name );
|
|
|
|
if ((file = fopen( filename, "r" )))
|
|
|
|
{
|
|
|
|
pFile->filename = filename;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free( filename );
|
|
|
|
}
|
2002-02-15 12:57:27 -07:00
|
|
|
if (!file && pFile->system) return NULL; /* ignore system files we cannot find */
|
|
|
|
|
2000-12-13 14:27:26 -07:00
|
|
|
/* try in src file directory */
|
|
|
|
if (!file)
|
|
|
|
{
|
2002-05-14 11:36:54 -07:00
|
|
|
char *p = strrchr(pFile->included_by->filename, '/');
|
2000-12-13 14:27:26 -07:00
|
|
|
if (p)
|
|
|
|
{
|
2002-05-14 11:36:54 -07:00
|
|
|
int l = p - pFile->included_by->filename + 1;
|
2000-12-13 14:27:26 -07:00
|
|
|
char *filename = xmalloc(l + strlen(pFile->name) + 1);
|
2002-05-14 11:36:54 -07:00
|
|
|
memcpy( filename, pFile->included_by->filename, l );
|
2000-12-13 14:27:26 -07:00
|
|
|
strcpy( filename + l, pFile->name );
|
|
|
|
if ((file = fopen( filename, "r" ))) pFile->filename = filename;
|
|
|
|
else free( filename );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
if (!file)
|
|
|
|
{
|
2002-02-15 12:57:27 -07:00
|
|
|
if (pFile->included_by->system) return NULL; /* ignore if included by a system file */
|
2006-08-01 03:13:57 -07:00
|
|
|
perror( pFile->name );
|
2000-11-05 22:32:59 -07:00
|
|
|
while (pFile->included_by)
|
|
|
|
{
|
|
|
|
fprintf( stderr, " %s was first included from %s:%d\n",
|
|
|
|
pFile->name, pFile->included_by->name, pFile->included_line );
|
|
|
|
pFile = pFile->included_by;
|
|
|
|
}
|
1996-10-23 09:59:13 -07:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2003-04-10 17:38:56 -07:00
|
|
|
* parse_idl_file
|
1996-10-23 09:59:13 -07:00
|
|
|
*/
|
2003-04-10 17:38:56 -07:00
|
|
|
static void parse_idl_file( INCL_FILE *pFile, FILE *file )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2006-08-01 03:16:29 -07:00
|
|
|
char *buffer, *include;
|
2000-11-05 22:32:59 -07:00
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
input_line = 0;
|
|
|
|
while ((buffer = get_line( file )))
|
2000-11-05 22:32:59 -07:00
|
|
|
{
|
2003-06-20 14:31:13 -07:00
|
|
|
char quote;
|
2003-04-10 17:38:56 -07:00
|
|
|
char *p = buffer;
|
|
|
|
while (*p && isspace(*p)) p++;
|
2003-06-20 14:31:13 -07:00
|
|
|
|
|
|
|
if (!strncmp( p, "import", 6 ))
|
|
|
|
{
|
|
|
|
p += 6;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (*p != '\"') continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*p++ != '#') continue;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (strncmp( p, "include", 7 )) continue;
|
|
|
|
p += 7;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (*p != '\"' && *p != '<' ) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
quote = *p++;
|
|
|
|
if (quote == '<') quote = '>';
|
2003-04-10 17:38:56 -07:00
|
|
|
include = p;
|
2003-06-20 14:31:13 -07:00
|
|
|
while (*p && (*p != quote)) p++;
|
2004-04-06 21:00:16 -07:00
|
|
|
if (!*p) fatal_error( "%s:%d: Malformed #include or import directive\n",
|
2006-08-01 03:16:29 -07:00
|
|
|
pFile->filename, input_line );
|
2003-04-10 17:38:56 -07:00
|
|
|
*p = 0;
|
2006-08-01 03:16:29 -07:00
|
|
|
add_include( pFile, include, input_line, (quote == '>') );
|
2000-11-05 22:32:59 -07:00
|
|
|
}
|
2003-04-10 17:38:56 -07:00
|
|
|
}
|
2000-11-05 22:32:59 -07:00
|
|
|
|
2003-04-10 17:38:56 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_c_file
|
|
|
|
*/
|
|
|
|
static void parse_c_file( INCL_FILE *pFile, FILE *file )
|
|
|
|
{
|
2006-08-01 03:16:29 -07:00
|
|
|
char *buffer, *include;
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
input_line = 0;
|
|
|
|
while ((buffer = get_line( file )))
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2002-02-15 12:57:27 -07:00
|
|
|
char quote;
|
1996-10-23 09:59:13 -07:00
|
|
|
char *p = buffer;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (*p++ != '#') continue;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (strncmp( p, "include", 7 )) continue;
|
|
|
|
p += 7;
|
|
|
|
while (*p && isspace(*p)) p++;
|
2002-02-15 12:57:27 -07:00
|
|
|
if (*p != '\"' && *p != '<' ) continue;
|
|
|
|
quote = *p++;
|
|
|
|
if (quote == '<') quote = '>';
|
1996-10-23 09:59:13 -07:00
|
|
|
include = p;
|
2002-02-15 12:57:27 -07:00
|
|
|
while (*p && (*p != quote)) p++;
|
2004-04-06 21:00:16 -07:00
|
|
|
if (!*p) fatal_error( "%s:%d: Malformed #include directive\n",
|
2006-08-01 03:16:29 -07:00
|
|
|
pFile->filename, input_line );
|
1996-10-23 09:59:13 -07:00
|
|
|
*p = 0;
|
2006-08-01 03:16:29 -07:00
|
|
|
add_include( pFile, include, input_line, (quote == '>') );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
2003-04-10 17:38:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_file
|
|
|
|
*/
|
|
|
|
static void parse_file( INCL_FILE *pFile, int src )
|
|
|
|
{
|
|
|
|
char *ext;
|
|
|
|
FILE *file;
|
|
|
|
|
|
|
|
if (is_generated( pFile->name ))
|
|
|
|
{
|
|
|
|
/* file is generated during make, don't try to open it */
|
|
|
|
pFile->filename = xstrdup( pFile->name );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = src ? open_src_file( pFile ) : open_include_file( pFile );
|
|
|
|
if (!file) return;
|
|
|
|
ext = get_extension( pFile->name );
|
|
|
|
if (ext && !strcmp( ext, ".idl" )) parse_idl_file( pFile, file );
|
|
|
|
else parse_c_file( pFile, file );
|
1996-11-02 07:24:07 -07:00
|
|
|
fclose(file);
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* output_include
|
|
|
|
*/
|
|
|
|
static void output_include( FILE *file, INCL_FILE *pFile,
|
|
|
|
INCL_FILE *owner, int *column )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pFile->owner == owner) return;
|
2002-02-15 12:57:27 -07:00
|
|
|
if (!pFile->filename) return;
|
1996-10-23 09:59:13 -07:00
|
|
|
pFile->owner = owner;
|
|
|
|
if (*column + strlen(pFile->filename) + 1 > 70)
|
|
|
|
{
|
|
|
|
fprintf( file, " \\\n" );
|
|
|
|
*column = 0;
|
|
|
|
}
|
|
|
|
fprintf( file, " %s", pFile->filename );
|
|
|
|
*column += strlen(pFile->filename) + 1;
|
|
|
|
for (i = 0; i < MAX_INCLUDES; i++)
|
|
|
|
if (pFile->files[i]) output_include( file, pFile->files[i],
|
|
|
|
owner, column );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-28 10:43:24 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* output_src
|
|
|
|
*/
|
|
|
|
static void output_src( FILE *file, INCL_FILE *pFile, int *column )
|
|
|
|
{
|
2000-03-19 14:20:16 -07:00
|
|
|
char *obj = xstrdup( pFile->name );
|
2003-04-10 17:38:56 -07:00
|
|
|
char *ext = get_extension( obj );
|
1997-09-28 10:43:24 -07:00
|
|
|
if (ext)
|
|
|
|
{
|
2000-10-23 14:39:39 -07:00
|
|
|
*ext++ = 0;
|
|
|
|
if (!strcmp( ext, "y" )) /* yacc file */
|
1997-09-28 10:43:24 -07:00
|
|
|
{
|
2005-09-28 11:17:08 -07:00
|
|
|
*column += fprintf( file, "%s.tab.o: %s.tab.c", obj, obj );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
2000-10-23 14:39:39 -07:00
|
|
|
else if (!strcmp( ext, "l" )) /* lex file */
|
1997-09-28 10:43:24 -07:00
|
|
|
{
|
2002-02-14 12:47:29 -07:00
|
|
|
*column += fprintf( file, "%s.o: %s.c", LEX_OUTPUT_ROOT, LEX_OUTPUT_ROOT );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
2000-10-23 14:39:39 -07:00
|
|
|
else if (!strcmp( ext, "rc" )) /* resource file */
|
1997-09-28 10:43:24 -07:00
|
|
|
{
|
2000-10-23 14:39:39 -07:00
|
|
|
*column += fprintf( file, "%s.res: %s", obj, pFile->filename );
|
|
|
|
}
|
2000-11-05 22:32:59 -07:00
|
|
|
else if (!strcmp( ext, "mc" )) /* message file */
|
2000-10-23 14:39:39 -07:00
|
|
|
{
|
2000-11-05 22:32:59 -07:00
|
|
|
*column += fprintf( file, "%s.mc.rc: %s", obj, pFile->filename );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
2003-04-10 17:38:56 -07:00
|
|
|
else if (!strcmp( ext, "idl" )) /* IDL file */
|
|
|
|
{
|
|
|
|
*column += fprintf( file, "%s.h: %s", obj, pFile->filename );
|
|
|
|
}
|
1997-09-28 10:43:24 -07:00
|
|
|
else
|
|
|
|
{
|
2000-10-23 14:39:39 -07:00
|
|
|
*column += fprintf( file, "%s.o: %s", obj, pFile->filename );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free( obj );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* output_dependencies
|
|
|
|
*/
|
|
|
|
static void output_dependencies(void)
|
|
|
|
{
|
|
|
|
INCL_FILE *pFile;
|
|
|
|
int i, column;
|
|
|
|
FILE *file = NULL;
|
2006-08-01 03:16:29 -07:00
|
|
|
char *buffer;
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
if (Separator && ((file = fopen( OutputFileName, "r+" ))))
|
|
|
|
{
|
2006-08-01 03:16:29 -07:00
|
|
|
while ((buffer = get_line( file )))
|
1996-10-23 09:59:13 -07:00
|
|
|
if (!strncmp( buffer, Separator, strlen(Separator) )) break;
|
|
|
|
ftruncate( fileno(file), ftell(file) );
|
Release 970120
Sun Jan 19 11:46:48 1997 Alexandre Julliard <julliard@lrc.epfl.ch>
* [loader/module.c]
Fixed LoadModule() to always call the DLL initialization code.
* [windows/event.c]
Moved all the keyboard stuff to windows/keyboard.c
* [tools/build.c]
Fixed Win32 register functions.
Sat Jan 18 22:24:41 1997 David Makepeace <D.Makepeace@mailbox.uq.oz.au>
* [tools/makedep.c]
Fixed bug which causes SEGV on Solaris x86.
Fri Jan 17 18:32:27 1997 Frans van Dorsselaer <dorssel@rulhmpc49.LeidenUniv.nl>
* [controls/edit.c]
Implemented WM_UNDO, WM_CONTEXTMENU (temporary using WM_RBUTTONUP),
WM_COMMAND, WM_INITPOPUPMENU, WM_SYSKEYDOWN.
Fixed EM_SETSEL and some minor bugs (features).
Hence: fully functional undo and a win95 menu with the right mouse
button.
* [include/resources.h] [resources/TODO] [resources/sysres_??.rc]
Added a context menu for the edit control.
Translations, please ...
Fri Jan 17 08:29:52 1997 David Faure <david.faure@ifhamy.insa-lyon.fr>
* [windows/event.c]
Move EVENT_ToAscii to windows/keyboard.c (where name ToAscii)
Fixed Keypad keys 0-9 and . in EVENT_event_to_vkey.
Added 3-state handling of toggle keys (CapsLock, NumLock) in order
to make them work with any X server.
Toggle keys now generate WM_KEYDOWN and WM_KEYUP on each pressing.
* [include/keyboard.h]
Totally replaced the file (formerly containing the vkcase definitions)
by the declaration of 'extern' variables contained by event.c and used
by keyboard.c
* [windows/keyboard.c]
Started to rewrite VkKeyScan and MapVirtualKey, to make them use the
table keyc2vkey or X functions only.
ToAscii : added keypad 0-9 and . special case.
Changed toggle keys active mask from 0x80 to 0x1.
* [misc/keyboard.c]
File deleted. Contents moved to windows/keyboard.c.
* [misc/main.c]
Added putenv XKB_DISABLE to disable XKB extension (which, when
present, causes AltGr to change keyboard group instead of being a
modifier).
Tue Jan 14 22:56:43 1997 Philippe De Muyter <phdm@info.ucl.ac.be>
* [windows/event.c]
Do not assume NumLockMask is Mod2Mask, but compute it by scanning
output of XGetModifierMapping for XK_Num_Lock.
Tue Jan 14 15:49:49 1997 Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
* [loader/pe_*.c] [include/peexe.h] [include/resource32.h]
[debugger/*.c]
General clean up.
Changed defines/structures to match Windows NT SDK.
* [loader/main.c]
Don't crash on empty command-line.
* [windows/winpos.c]
winpos.c made win32 clean.
* [misc/ntdll.c]
Some string conversion additions.
* [files/file.c]
GetFileAttributes/GetTempFileName fixed.
* [misc/ver.c]
VerInstallFile implemented.
Mon Jan 13 15:03:11 1997 Philippe De Muyter <phdm@info.ucl.ac.be>
* [tools/build.c]: Use PREFIX also in stabs messages.
Mon Jan 13 10:40:33 1997 John Harvey <john@division.co.uk>
* [graphics/win16drv/*] [include/win16drv.h]
Many fixes and some new features.
* [graphics/x11drv/font.c] [graphics/x11drv/init.c]
[include/x11drv.h] [objects/font.c]
GetTextMetrics() moved to graphics driver.
* [if1632/gdi.spec] [misc/fontengine.c] [misc/Makefile.in]
New dummy EngineEnumerateFont, EngineRealizeFont functions.
* [include/windows.h]
TEXTFORM16 and FONTINFO16 structure definitions moved here from
include/win16drv.h
1997-01-20 12:43:45 -07:00
|
|
|
fseek( file, 0L, SEEK_END );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
if (!file)
|
|
|
|
{
|
2000-12-04 20:57:35 -07:00
|
|
|
if (!(file = fopen( OutputFileName, Separator ? "a" : "w" )))
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
|
|
|
perror( OutputFileName );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2006-08-01 03:13:57 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( pFile, &sources, INCL_FILE, entry )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
1997-09-28 10:43:24 -07:00
|
|
|
column = 0;
|
|
|
|
output_src( file, pFile, &column );
|
1996-10-23 09:59:13 -07:00
|
|
|
for (i = 0; i < MAX_INCLUDES; i++)
|
|
|
|
if (pFile->files[i]) output_include( file, pFile->files[i],
|
|
|
|
pFile, &column );
|
|
|
|
fprintf( file, "\n" );
|
|
|
|
}
|
1996-11-02 07:24:07 -07:00
|
|
|
fclose(file);
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_option
|
|
|
|
*/
|
|
|
|
static void parse_option( const char *opt )
|
|
|
|
{
|
|
|
|
switch(opt[1])
|
|
|
|
{
|
|
|
|
case 'I':
|
|
|
|
if (opt[2]) add_include_path( opt + 2 );
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
if (opt[2]) SrcDir = opt + 2;
|
|
|
|
else SrcDir = NULL;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
if (opt[2]) OutputFileName = opt + 2;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (opt[2]) Separator = opt + 2;
|
|
|
|
else Separator = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf( stderr, "Unknown option '%s'\n", opt );
|
|
|
|
fprintf( stderr, Usage, ProgramName );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* main
|
|
|
|
*/
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
INCL_FILE *pFile;
|
|
|
|
|
|
|
|
ProgramName = argv[0];
|
|
|
|
while (argc > 1)
|
|
|
|
{
|
|
|
|
if (*argv[1] == '-') parse_option( argv[1] );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pFile = add_src_file( argv[1] );
|
|
|
|
parse_file( pFile, 1 );
|
|
|
|
}
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
2006-08-01 03:13:57 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( pFile, &includes, INCL_FILE, entry ) parse_file( pFile, 0 );
|
|
|
|
if (!list_empty( &sources )) output_dependencies();
|
1996-10-23 09:59:13 -07:00
|
|
|
return 0;
|
|
|
|
}
|