2000-06-23 22:15:35 +02:00
|
|
|
/*
|
|
|
|
* Spec file parser
|
|
|
|
*
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
|
|
|
* Copyright 1995 Martin von Loewis
|
2004-02-17 21:36:16 +01:00
|
|
|
* Copyright 1995, 1996, 1997, 2004 Alexandre Julliard
|
2000-06-23 22:15:35 +02:00
|
|
|
* Copyright 1997 Eric Youngdale
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
2002-03-10 00:29:33 +01: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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
|
|
|
|
2001-10-14 18:18:52 +02:00
|
|
|
#include "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-06-23 22:15:35 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-11-12 04:45:55 +01:00
|
|
|
#include "winbase.h"
|
2000-06-23 22:15:35 +02:00
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
int current_line = 0;
|
|
|
|
|
|
|
|
static char ParseBuffer[512];
|
2001-02-15 22:27:06 +01:00
|
|
|
static char TokenBuffer[512];
|
2000-06-23 22:15:35 +02:00
|
|
|
static char *ParseNext = ParseBuffer;
|
|
|
|
static FILE *input_file;
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
static const char *separator_chars;
|
|
|
|
static const char *comment_chars;
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
static const char * const TypeNames[TYPE_NBTYPES] =
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
"variable", /* TYPE_VARIABLE */
|
2000-06-23 22:15:35 +02:00
|
|
|
"pascal", /* TYPE_PASCAL */
|
|
|
|
"equate", /* TYPE_ABS */
|
|
|
|
"stub", /* TYPE_STUB */
|
|
|
|
"stdcall", /* TYPE_STDCALL */
|
|
|
|
"cdecl", /* TYPE_CDECL */
|
|
|
|
"varargs", /* TYPE_VARARGS */
|
2003-03-17 05:56:10 +01:00
|
|
|
"extern" /* TYPE_EXTERN */
|
2000-06-23 22:15:35 +02:00
|
|
|
};
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
static const char * const FlagNames[] =
|
|
|
|
{
|
|
|
|
"norelay", /* FLAG_NORELAY */
|
2002-07-28 19:54:31 +02:00
|
|
|
"noname", /* FLAG_NONAME */
|
2003-08-27 04:20:44 +02:00
|
|
|
"ret16", /* FLAG_RET16 */
|
2000-11-26 05:31:48 +01:00
|
|
|
"ret64", /* FLAG_RET64 */
|
|
|
|
"i386", /* FLAG_I386 */
|
2001-12-15 00:14:22 +01:00
|
|
|
"register", /* FLAG_REGISTER */
|
2003-07-28 21:19:48 +02:00
|
|
|
"private", /* FLAG_PRIVATE */
|
2000-11-26 05:31:48 +01:00
|
|
|
NULL
|
|
|
|
};
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2001-02-15 22:27:06 +01:00
|
|
|
static int IsNumberString(const char *s)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
while (*s) if (!isdigit(*s++)) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
inline static int is_token_separator( char ch )
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
return strchr( separator_chars, ch ) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static int is_token_comment( char ch )
|
|
|
|
{
|
|
|
|
return strchr( comment_chars, ch ) != NULL;
|
2000-11-26 05:31:48 +01:00
|
|
|
}
|
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
/* get the next line from the input file, or return 0 if at eof */
|
|
|
|
static int get_next_line(void)
|
|
|
|
{
|
|
|
|
ParseNext = ParseBuffer;
|
|
|
|
current_line++;
|
|
|
|
return (fgets(ParseBuffer, sizeof(ParseBuffer), input_file) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * GetToken( int allow_eol )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
char *p = ParseNext;
|
|
|
|
char *token = TokenBuffer;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* remove initial white space */
|
|
|
|
p = ParseNext;
|
|
|
|
while (isspace(*p)) p++;
|
2001-02-15 22:27:06 +01:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (*p == '\\' && p[1] == '\n') /* line continuation */
|
|
|
|
{
|
|
|
|
if (!get_next_line())
|
|
|
|
{
|
|
|
|
if (!allow_eol) error( "Unexpected end of file\n" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
if ((*p == '\0') || is_token_comment(*p))
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
if (!allow_eol) error( "Declaration not terminated properly\n" );
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-15 22:27:06 +01:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*
|
|
|
|
* Find end of token.
|
|
|
|
*/
|
2001-02-15 22:27:06 +01:00
|
|
|
if (is_token_separator(*p))
|
|
|
|
{
|
|
|
|
/* a separator is always a complete token */
|
|
|
|
*token++ = *p++;
|
|
|
|
}
|
|
|
|
else while (*p != '\0' && !is_token_separator(*p) && !isspace(*p))
|
|
|
|
{
|
|
|
|
if (*p == '\\') p++;
|
|
|
|
if (*p) *token++ = *p++;
|
|
|
|
}
|
|
|
|
*token = '\0';
|
2000-06-23 22:15:35 +02:00
|
|
|
ParseNext = p;
|
2001-02-15 22:27:06 +01:00
|
|
|
return TokenBuffer;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
static ORDDEF *add_entry_point( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
if (spec->nb_entry_points == spec->alloc_entry_points)
|
|
|
|
{
|
|
|
|
spec->alloc_entry_points += 128;
|
|
|
|
spec->entry_points = xrealloc( spec->entry_points,
|
|
|
|
spec->alloc_entry_points * sizeof(*spec->entry_points) );
|
|
|
|
}
|
|
|
|
return &spec->entry_points[spec->nb_entry_points++];
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_variable
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse a variable definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_variable( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
char *endptr;
|
|
|
|
int *value_array;
|
|
|
|
int n_values;
|
|
|
|
int value_array_size;
|
2003-03-17 01:02:11 +01:00
|
|
|
const char *token;
|
2001-02-15 22:27:06 +01:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type == SPEC_WIN32)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'variable' not supported in Win32, use 'extern' instead\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-17 01:02:11 +01:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
if (*token != '(')
|
|
|
|
{
|
|
|
|
error( "Expected '(' got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
n_values = 0;
|
|
|
|
value_array_size = 25;
|
|
|
|
value_array = xmalloc(sizeof(*value_array) * value_array_size);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
for (;;)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0)))
|
|
|
|
{
|
|
|
|
free( value_array );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
if (*token == ')')
|
|
|
|
break;
|
|
|
|
|
|
|
|
value_array[n_values++] = strtol(token, &endptr, 0);
|
|
|
|
if (n_values == value_array_size)
|
|
|
|
{
|
|
|
|
value_array_size += 25;
|
2002-06-01 01:06:46 +02:00
|
|
|
value_array = xrealloc(value_array,
|
2000-06-23 22:15:35 +02:00
|
|
|
sizeof(*value_array) * value_array_size);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
if (endptr == NULL || *endptr != '\0')
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Expected number value, got '%s'\n", token );
|
|
|
|
free( value_array );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
odp->u.var.n_values = n_values;
|
|
|
|
odp->u.var.values = xrealloc(value_array, sizeof(*value_array) * n_values);
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_export
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse an exported function definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_export( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-11-11 01:38:37 +01:00
|
|
|
unsigned int i;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
switch(spec->type)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
case SPEC_WIN16:
|
2000-11-26 05:31:48 +01:00
|
|
|
if (odp->type == TYPE_STDCALL)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'stdcall' not supported for Win16\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case SPEC_WIN32:
|
2003-08-27 04:20:44 +02:00
|
|
|
if (odp->type == TYPE_PASCAL)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'pascal' not supported for Win32\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
if (*token != '(')
|
|
|
|
{
|
|
|
|
error( "Expected '(' got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-10-01 03:33:50 +02:00
|
|
|
for (i = 0; i < sizeof(odp->u.func.arg_types); i++)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) return 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
if (*token == ')')
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!strcmp(token, "word"))
|
|
|
|
odp->u.func.arg_types[i] = 'w';
|
|
|
|
else if (!strcmp(token, "s_word"))
|
|
|
|
odp->u.func.arg_types[i] = 's';
|
|
|
|
else if (!strcmp(token, "long") || !strcmp(token, "segptr"))
|
|
|
|
odp->u.func.arg_types[i] = 'l';
|
|
|
|
else if (!strcmp(token, "ptr"))
|
|
|
|
odp->u.func.arg_types[i] = 'p';
|
|
|
|
else if (!strcmp(token, "str"))
|
|
|
|
odp->u.func.arg_types[i] = 't';
|
|
|
|
else if (!strcmp(token, "wstr"))
|
|
|
|
odp->u.func.arg_types[i] = 'W';
|
|
|
|
else if (!strcmp(token, "segstr"))
|
|
|
|
odp->u.func.arg_types[i] = 'T';
|
|
|
|
else if (!strcmp(token, "double"))
|
|
|
|
{
|
|
|
|
odp->u.func.arg_types[i++] = 'l';
|
2000-10-01 03:33:50 +02:00
|
|
|
if (i < sizeof(odp->u.func.arg_types)) odp->u.func.arg_types[i] = 'l';
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error( "Unknown argument type '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type == SPEC_WIN32)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
if (strcmp(token, "long") &&
|
|
|
|
strcmp(token, "ptr") &&
|
|
|
|
strcmp(token, "str") &&
|
|
|
|
strcmp(token, "wstr") &&
|
|
|
|
strcmp(token, "double"))
|
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
error( "Type '%s' not supported for Win32\n", token );
|
|
|
|
return 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((*token != ')') || (i >= sizeof(odp->u.func.arg_types)))
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Too many arguments\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
odp->u.func.arg_types[i] = '\0';
|
2000-11-26 05:31:48 +01:00
|
|
|
if (odp->type == TYPE_VARARGS)
|
|
|
|
odp->flags |= FLAG_NORELAY; /* no relay debug possible for varags entry point */
|
2003-03-18 06:30:54 +01:00
|
|
|
|
|
|
|
if (!(token = GetToken(1)))
|
2002-12-15 02:22:40 +01:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!strcmp( odp->name, "@" ))
|
|
|
|
{
|
|
|
|
error( "Missing handler name for anonymous function\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
odp->link_name = xstrdup( odp->name );
|
2002-12-15 02:22:40 +01:00
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
odp->link_name = xstrdup( token );
|
|
|
|
if (strchr( odp->link_name, '.' ))
|
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type == SPEC_WIN16)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Forwarded functions not supported for Win16\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
odp->flags |= FLAG_FORWARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_equate
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse an 'equate' definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_equate( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
char *endptr;
|
2003-03-18 06:30:54 +01:00
|
|
|
int value;
|
|
|
|
const char *token;
|
2001-02-15 22:27:06 +01:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type == SPEC_WIN32)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'equate' not supported for Win32\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
value = strtol(token, &endptr, 0);
|
|
|
|
if (endptr == NULL || *endptr != '\0')
|
|
|
|
{
|
|
|
|
error( "Expected number value, got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
odp->u.abs.value = value;
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_stub
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse a 'stub' definition in a .spec file
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_stub( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
odp->u.func.arg_types[0] = '\0';
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name = xstrdup("");
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_extern
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse an 'extern' definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_extern( ORDDEF *odp, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
const char *token;
|
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type == SPEC_WIN16)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'extern' not supported for Win16, use 'variable' instead\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(1)))
|
|
|
|
{
|
|
|
|
if (!strcmp( odp->name, "@" ))
|
|
|
|
{
|
|
|
|
error( "Missing handler name for anonymous extern\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
odp->link_name = xstrdup( odp->name );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
odp->link_name = xstrdup( token );
|
|
|
|
if (strchr( odp->link_name, '.' )) odp->flags |= FLAG_FORWARD;
|
|
|
|
}
|
|
|
|
return 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_flags
|
2000-11-26 05:31:48 +01:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse the optional flags for an entry point in a .spec file.
|
2000-11-26 05:31:48 +01:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static const char *parse_spec_flags( ORDDEF *odp )
|
2000-11-26 05:31:48 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-11-26 05:31:48 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) break;
|
2000-11-26 05:31:48 +01:00
|
|
|
for (i = 0; FlagNames[i]; i++)
|
|
|
|
if (!strcmp( FlagNames[i], token )) break;
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!FlagNames[i])
|
|
|
|
{
|
|
|
|
error( "Unknown flag '%s'\n", token );
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-11-26 05:31:48 +01:00
|
|
|
odp->flags |= 1 << i;
|
|
|
|
token = GetToken(0);
|
2003-03-18 06:30:54 +01:00
|
|
|
} while (token && *token == '-');
|
2000-11-26 05:31:48 +01:00
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_ordinal
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse an ordinal definition in a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
static int parse_spec_ordinal( int ordinal, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
ORDDEF *odp = add_entry_point( spec );
|
2000-12-16 00:04:40 +01:00
|
|
|
memset( odp, 0, sizeof(*odp) );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
for (odp->type = 0; odp->type < TYPE_NBTYPES; odp->type++)
|
|
|
|
if (TypeNames[odp->type] && !strcmp( token, TypeNames[odp->type] ))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (odp->type >= TYPE_NBTYPES)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
2003-09-26 06:32:19 +02:00
|
|
|
error( "Expected type after ordinal, found '%s' instead\n", token );
|
|
|
|
goto error;
|
2003-03-18 06:30:54 +01:00
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(0))) goto error;
|
2004-02-17 21:36:16 +01:00
|
|
|
if (*token == '-' && !(token = parse_spec_flags( odp ))) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->name = xstrdup( token );
|
2000-06-23 22:15:35 +02:00
|
|
|
odp->lineno = current_line;
|
|
|
|
odp->ordinal = ordinal;
|
|
|
|
|
|
|
|
switch(odp->type)
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
case TYPE_VARIABLE:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_variable( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_PASCAL:
|
|
|
|
case TYPE_STDCALL:
|
|
|
|
case TYPE_VARARGS:
|
|
|
|
case TYPE_CDECL:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_export( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_ABS:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_equate( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_STUB:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_stub( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
case TYPE_EXTERN:
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_extern( odp, spec )) goto error;
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( 0 );
|
|
|
|
}
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
#ifndef __i386__
|
|
|
|
if (odp->flags & FLAG_I386)
|
|
|
|
{
|
|
|
|
/* ignore this entry point on non-Intel archs */
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->nb_entry_points--;
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
2000-11-26 05:31:48 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
if (ordinal != -1)
|
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!ordinal)
|
|
|
|
{
|
|
|
|
error( "Ordinal 0 is not valid\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (ordinal >= MAX_ORDINALS)
|
|
|
|
{
|
|
|
|
error( "Ordinal number %d too large\n", ordinal );
|
|
|
|
goto error;
|
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
if (ordinal > spec->limit) spec->limit = ordinal;
|
|
|
|
if (ordinal < spec->base) spec->base = ordinal;
|
2000-06-23 22:15:35 +02:00
|
|
|
odp->ordinal = ordinal;
|
|
|
|
}
|
|
|
|
|
2005-05-07 20:47:22 +02:00
|
|
|
if (spec->type == SPEC_WIN32 && odp->flags & FLAG_REGISTER)
|
|
|
|
{
|
|
|
|
error( "-register flag not supported for Win32 entry points\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2004-08-27 21:40:53 +02:00
|
|
|
if (odp->type == TYPE_STDCALL && !(odp->flags & FLAG_PRIVATE))
|
|
|
|
{
|
|
|
|
if (!strcmp( odp->name, "DllRegisterServer" ) ||
|
|
|
|
!strcmp( odp->name, "DllUnregisterServer" ) ||
|
|
|
|
!strcmp( odp->name, "DllGetClassObject" ) ||
|
|
|
|
!strcmp( odp->name, "DllCanUnloadNow" ))
|
|
|
|
{
|
|
|
|
warning( "Function %s should be marked private\n", odp->name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-28 19:54:31 +02:00
|
|
|
if (!strcmp( odp->name, "@" ) || odp->flags & FLAG_NONAME)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
if (ordinal == -1)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Nameless function needs an explicit ordinal number\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type != SPEC_WIN32)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "Nameless functions not supported for Win16\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
2002-07-28 19:54:31 +02:00
|
|
|
if (!strcmp( odp->name, "@" )) free( odp->name );
|
|
|
|
else odp->export_name = odp->name;
|
|
|
|
odp->name = NULL;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
error:
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->nb_entry_points--;
|
2003-03-18 06:30:54 +01:00
|
|
|
free( odp->name );
|
|
|
|
return 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-12 04:45:55 +01:00
|
|
|
static int name_compare( const void *name1, const void *name2 )
|
|
|
|
{
|
2004-05-18 23:27:44 +02:00
|
|
|
const ORDDEF *odp1 = *(const ORDDEF * const *)name1;
|
|
|
|
const ORDDEF *odp2 = *(const ORDDEF * const *)name2;
|
2000-11-12 04:45:55 +01:00
|
|
|
return strcmp( odp1->name, odp2->name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
2004-02-11 07:41:01 +01:00
|
|
|
* assign_names
|
2000-11-12 04:45:55 +01:00
|
|
|
*
|
2004-02-11 07:41:01 +01:00
|
|
|
* Build the name array and catch duplicates.
|
2000-11-12 04:45:55 +01:00
|
|
|
*/
|
2004-02-11 07:41:01 +01:00
|
|
|
static void assign_names( DLLSPEC *spec )
|
2000-11-12 04:45:55 +01:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
spec->nb_names = 0;
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
if (spec->entry_points[i].name) spec->nb_names++;
|
|
|
|
if (!spec->nb_names) return;
|
2000-11-12 04:45:55 +01:00
|
|
|
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->names = xmalloc( spec->nb_names * sizeof(spec->names[0]) );
|
|
|
|
for (i = j = 0; i < spec->nb_entry_points; i++)
|
|
|
|
if (spec->entry_points[i].name) spec->names[j++] = &spec->entry_points[i];
|
2000-11-12 04:45:55 +01:00
|
|
|
|
|
|
|
/* sort the list of names */
|
2004-02-11 07:41:01 +01:00
|
|
|
qsort( spec->names, spec->nb_names, sizeof(spec->names[0]), name_compare );
|
2000-11-12 04:45:55 +01:00
|
|
|
|
|
|
|
/* check for duplicate names */
|
2004-02-11 07:41:01 +01:00
|
|
|
for (i = 0; i < spec->nb_names - 1; i++)
|
2000-11-12 04:45:55 +01:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
if (!strcmp( spec->names[i]->name, spec->names[i+1]->name ))
|
2000-11-12 04:45:55 +01:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
current_line = max( spec->names[i]->lineno, spec->names[i+1]->lineno );
|
2003-03-18 06:30:54 +01:00
|
|
|
error( "'%s' redefined\n%s:%d: First defined here\n",
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->names[i]->name, input_file_name,
|
|
|
|
min( spec->names[i]->lineno, spec->names[i+1]->lineno ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* assign_ordinals
|
|
|
|
*
|
|
|
|
* Build the ordinal array.
|
|
|
|
*/
|
|
|
|
static void assign_ordinals( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int i, count, ordinal;
|
|
|
|
|
|
|
|
/* start assigning from base, or from 1 if no ordinal defined yet */
|
|
|
|
if (spec->base == MAX_ORDINALS) spec->base = 1;
|
|
|
|
if (spec->limit < spec->base) spec->limit = spec->base;
|
|
|
|
|
|
|
|
count = max( spec->limit + 1, spec->base + spec->nb_entry_points );
|
|
|
|
spec->ordinals = xmalloc( count * sizeof(spec->ordinals[0]) );
|
|
|
|
memset( spec->ordinals, 0, count * sizeof(spec->ordinals[0]) );
|
|
|
|
|
|
|
|
/* fill in all explicitly specified ordinals */
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ordinal = spec->entry_points[i].ordinal;
|
|
|
|
if (ordinal == -1) continue;
|
|
|
|
if (spec->ordinals[ordinal])
|
|
|
|
{
|
|
|
|
current_line = max( spec->entry_points[i].lineno, spec->ordinals[ordinal]->lineno );
|
|
|
|
error( "ordinal %d redefined\n%s:%d: First defined here\n",
|
|
|
|
ordinal, input_file_name,
|
|
|
|
min( spec->entry_points[i].lineno, spec->ordinals[ordinal]->lineno ) );
|
|
|
|
}
|
|
|
|
else spec->ordinals[ordinal] = &spec->entry_points[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now assign ordinals to the rest */
|
|
|
|
for (i = 0, ordinal = spec->base; i < spec->nb_names; i++)
|
|
|
|
{
|
|
|
|
if (spec->names[i]->ordinal != -1) continue; /* already has an ordinal */
|
|
|
|
while (spec->ordinals[ordinal]) ordinal++;
|
|
|
|
if (ordinal >= MAX_ORDINALS)
|
|
|
|
{
|
|
|
|
current_line = spec->names[i]->lineno;
|
|
|
|
fatal_error( "Too many functions defined (max %d)\n", MAX_ORDINALS );
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
spec->names[i]->ordinal = ordinal;
|
|
|
|
spec->ordinals[ordinal] = spec->names[i];
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
2004-02-11 07:41:01 +01:00
|
|
|
if (ordinal > spec->limit) spec->limit = ordinal;
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
2004-02-17 21:36:16 +01:00
|
|
|
* parse_spec_file
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2004-02-17 21:36:16 +01:00
|
|
|
* Parse a .spec file.
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
2004-02-17 21:36:16 +01:00
|
|
|
int parse_spec_file( FILE *file, DLLSPEC *spec )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
input_file = file;
|
2002-08-28 00:32:01 +02:00
|
|
|
current_line = 0;
|
2002-06-21 21:15:45 +02:00
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
comment_chars = "#;";
|
|
|
|
separator_chars = "()-";
|
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
while (get_next_line())
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2003-03-18 06:30:54 +01:00
|
|
|
if (!(token = GetToken(1))) continue;
|
2002-12-08 00:54:12 +01:00
|
|
|
if (strcmp(token, "@") == 0)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
2004-02-11 07:41:01 +01:00
|
|
|
if (spec->type != SPEC_WIN32)
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "'@' ordinals not supported for Win16\n" );
|
|
|
|
continue;
|
|
|
|
}
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_ordinal( -1, spec )) continue;
|
2003-03-18 06:30:54 +01:00
|
|
|
}
|
|
|
|
else if (IsNumberString(token))
|
|
|
|
{
|
2004-02-17 21:36:16 +01:00
|
|
|
if (!parse_spec_ordinal( atoi(token), spec )) continue;
|
2003-03-18 06:30:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error( "Expected ordinal declaration, got '%s'\n", token );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((token = GetToken(1))) error( "Syntax error near '%s'\n", token );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
current_line = 0; /* no longer parsing the input file */
|
2004-02-11 07:41:01 +01:00
|
|
|
assign_names( spec );
|
|
|
|
assign_ordinals( spec );
|
2003-03-18 06:30:54 +01:00
|
|
|
return !nb_errors;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2002-05-14 22:54:58 +02:00
|
|
|
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_def_library
|
|
|
|
*
|
|
|
|
* Parse a LIBRARY declaration in a .def file.
|
|
|
|
*/
|
|
|
|
static int parse_def_library( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
const char *token = GetToken(1);
|
|
|
|
|
|
|
|
if (!token) return 1;
|
|
|
|
if (strcmp( token, "BASE" ))
|
|
|
|
{
|
|
|
|
free( spec->file_name );
|
|
|
|
spec->file_name = xstrdup( token );
|
|
|
|
if (!(token = GetToken(1))) return 1;
|
|
|
|
}
|
|
|
|
if (strcmp( token, "BASE" ))
|
|
|
|
{
|
|
|
|
error( "Expected library name or BASE= declaration, got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
if (strcmp( token, "=" ))
|
|
|
|
{
|
|
|
|
error( "Expected '=' after BASE, got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
/* FIXME: do something with base address */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_def_stack_heap_size
|
|
|
|
*
|
|
|
|
* Parse a STACKSIZE or HEAPSIZE declaration in a .def file.
|
|
|
|
*/
|
|
|
|
static int parse_def_stack_heap_size( int is_stack, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
const char *token = GetToken(0);
|
|
|
|
char *end;
|
|
|
|
unsigned long size;
|
|
|
|
|
|
|
|
if (!token) return 0;
|
|
|
|
size = strtoul( token, &end, 0 );
|
|
|
|
if (*end)
|
|
|
|
{
|
|
|
|
error( "Invalid number '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (is_stack) spec->stack_size = size / 1024;
|
|
|
|
else spec->heap_size = size / 1024;
|
|
|
|
if (!(token = GetToken(1))) return 1;
|
|
|
|
if (strcmp( token, "," ))
|
|
|
|
{
|
|
|
|
error( "Expected ',' after size, got '%s'\n", token );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(token = GetToken(0))) return 0;
|
|
|
|
/* FIXME: do something with reserve size */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_def_export
|
|
|
|
*
|
|
|
|
* Parse an export declaration in a .def file.
|
|
|
|
*/
|
|
|
|
static int parse_def_export( char *name, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int i, args;
|
|
|
|
const char *token = GetToken(1);
|
|
|
|
|
|
|
|
ORDDEF *odp = add_entry_point( spec );
|
|
|
|
memset( odp, 0, sizeof(*odp) );
|
|
|
|
|
|
|
|
odp->lineno = current_line;
|
|
|
|
odp->ordinal = -1;
|
|
|
|
odp->name = name;
|
|
|
|
args = remove_stdcall_decoration( odp->name );
|
|
|
|
if (args == -1) odp->type = TYPE_CDECL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
odp->type = TYPE_STDCALL;
|
|
|
|
args /= sizeof(int);
|
|
|
|
if (args >= sizeof(odp->u.func.arg_types))
|
|
|
|
{
|
|
|
|
error( "Too many arguments in stdcall function '%s'\n", odp->name );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < args; i++) odp->u.func.arg_types[i] = 'l';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for optional internal name */
|
|
|
|
|
|
|
|
if (token && !strcmp( token, "=" ))
|
|
|
|
{
|
|
|
|
if (!(token = GetToken(0))) goto error;
|
|
|
|
odp->link_name = xstrdup( token );
|
|
|
|
remove_stdcall_decoration( odp->link_name );
|
|
|
|
token = GetToken(1);
|
|
|
|
}
|
2004-11-21 16:39:51 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
odp->link_name = xstrdup( name );
|
|
|
|
}
|
2004-02-17 21:36:16 +01:00
|
|
|
|
|
|
|
/* check for optional ordinal */
|
|
|
|
|
|
|
|
if (token && token[0] == '@')
|
|
|
|
{
|
|
|
|
int ordinal;
|
|
|
|
|
|
|
|
if (!IsNumberString( token+1 ))
|
|
|
|
{
|
|
|
|
error( "Expected number after '@', got '%s'\n", token+1 );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ordinal = atoi( token+1 );
|
|
|
|
if (!ordinal)
|
|
|
|
{
|
|
|
|
error( "Ordinal 0 is not valid\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (ordinal >= MAX_ORDINALS)
|
|
|
|
{
|
|
|
|
error( "Ordinal number %d too large\n", ordinal );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (ordinal > spec->limit) spec->limit = ordinal;
|
|
|
|
if (ordinal < spec->base) spec->base = ordinal;
|
|
|
|
odp->ordinal = ordinal;
|
|
|
|
token = GetToken(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for other optional keywords */
|
|
|
|
|
|
|
|
if (token && !strcmp( token, "NONAME" ))
|
|
|
|
{
|
|
|
|
if (odp->ordinal == -1)
|
|
|
|
{
|
|
|
|
error( "NONAME requires an ordinal\n" );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
odp->export_name = odp->name;
|
|
|
|
odp->name = NULL;
|
|
|
|
odp->flags |= FLAG_NONAME;
|
|
|
|
token = GetToken(1);
|
|
|
|
}
|
|
|
|
if (token && !strcmp( token, "PRIVATE" ))
|
|
|
|
{
|
|
|
|
odp->flags |= FLAG_PRIVATE;
|
|
|
|
token = GetToken(1);
|
|
|
|
}
|
|
|
|
if (token && !strcmp( token, "DATA" ))
|
|
|
|
{
|
|
|
|
odp->type = TYPE_EXTERN;
|
|
|
|
token = GetToken(1);
|
|
|
|
}
|
|
|
|
if (token)
|
|
|
|
{
|
|
|
|
error( "Garbage text '%s' found at end of export declaration\n", token );
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
error:
|
|
|
|
spec->nb_entry_points--;
|
|
|
|
free( odp->name );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_def_file
|
|
|
|
*
|
|
|
|
* Parse a .def file.
|
|
|
|
*/
|
|
|
|
int parse_def_file( FILE *file, DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
const char *token;
|
|
|
|
int in_exports = 0;
|
|
|
|
|
|
|
|
input_file = file;
|
|
|
|
current_line = 0;
|
|
|
|
|
|
|
|
comment_chars = ";";
|
|
|
|
separator_chars = ",=";
|
|
|
|
|
|
|
|
while (get_next_line())
|
|
|
|
{
|
|
|
|
if (!(token = GetToken(1))) continue;
|
|
|
|
|
|
|
|
if (!strcmp( token, "LIBRARY" ) || !strcmp( token, "NAME" ))
|
|
|
|
{
|
|
|
|
if (!parse_def_library( spec )) continue;
|
|
|
|
goto end_of_line;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "STACKSIZE" ))
|
|
|
|
{
|
|
|
|
if (!parse_def_stack_heap_size( 1, spec )) continue;
|
|
|
|
goto end_of_line;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "HEAPSIZE" ))
|
|
|
|
{
|
|
|
|
if (!parse_def_stack_heap_size( 0, spec )) continue;
|
|
|
|
goto end_of_line;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "EXPORTS" ))
|
|
|
|
{
|
|
|
|
in_exports = 1;
|
|
|
|
if (!(token = GetToken(1))) continue;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "IMPORTS" ))
|
|
|
|
{
|
|
|
|
in_exports = 0;
|
|
|
|
if (!(token = GetToken(1))) continue;
|
|
|
|
}
|
|
|
|
else if (!strcmp( token, "SECTIONS" ))
|
|
|
|
{
|
|
|
|
in_exports = 0;
|
|
|
|
if (!(token = GetToken(1))) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_exports) continue; /* ignore this line */
|
|
|
|
if (!parse_def_export( xstrdup(token), spec )) continue;
|
|
|
|
|
|
|
|
end_of_line:
|
|
|
|
if ((token = GetToken(1))) error( "Syntax error near '%s'\n", token );
|
|
|
|
}
|
|
|
|
|
|
|
|
current_line = 0; /* no longer parsing the input file */
|
|
|
|
assign_names( spec );
|
|
|
|
assign_ordinals( spec );
|
|
|
|
return !nb_errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-14 22:54:58 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* add_debug_channel
|
|
|
|
*/
|
|
|
|
static void add_debug_channel( const char *name )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_debug_channels; i++)
|
|
|
|
if (!strcmp( debug_channels[i], name )) return;
|
|
|
|
|
|
|
|
debug_channels = xrealloc( debug_channels, (nb_debug_channels + 1) * sizeof(*debug_channels));
|
|
|
|
debug_channels[nb_debug_channels++] = xstrdup(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_debug_channels
|
|
|
|
*
|
|
|
|
* Parse a source file and extract the debug channel definitions.
|
|
|
|
*/
|
2003-03-18 06:30:54 +01:00
|
|
|
int parse_debug_channels( const char *srcdir, const char *filename )
|
2002-05-14 22:54:58 +02:00
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
int eol_seen = 1;
|
|
|
|
|
2002-08-01 20:34:12 +02:00
|
|
|
file = open_input_file( srcdir, filename );
|
2002-05-14 22:54:58 +02:00
|
|
|
while (fgets( ParseBuffer, sizeof(ParseBuffer), file ))
|
|
|
|
{
|
|
|
|
char *channel, *end, *p = ParseBuffer;
|
|
|
|
|
|
|
|
p = ParseBuffer + strlen(ParseBuffer) - 1;
|
|
|
|
if (!eol_seen) /* continuation line */
|
|
|
|
{
|
|
|
|
eol_seen = (*p == '\n');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((eol_seen = (*p == '\n'))) *p = 0;
|
|
|
|
|
|
|
|
p = ParseBuffer;
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
if (!memcmp( p, "WINE_DECLARE_DEBUG_CHANNEL", 26 ) ||
|
|
|
|
!memcmp( p, "WINE_DEFAULT_DEBUG_CHANNEL", 26 ))
|
|
|
|
{
|
|
|
|
p += 26;
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
if (*p != '(')
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "invalid debug channel specification '%s'\n", ParseBuffer );
|
|
|
|
goto next;
|
|
|
|
}
|
2002-05-14 22:54:58 +02:00
|
|
|
p++;
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
if (!isalpha(*p))
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "invalid debug channel specification '%s'\n", ParseBuffer );
|
|
|
|
goto next;
|
|
|
|
}
|
2002-05-14 22:54:58 +02:00
|
|
|
channel = p;
|
|
|
|
while (isalnum(*p) || *p == '_') p++;
|
|
|
|
end = p;
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
if (*p != ')')
|
2003-03-18 06:30:54 +01:00
|
|
|
{
|
|
|
|
error( "invalid debug channel specification '%s'\n", ParseBuffer );
|
|
|
|
goto next;
|
|
|
|
}
|
2002-05-14 22:54:58 +02:00
|
|
|
*end = 0;
|
|
|
|
add_debug_channel( channel );
|
|
|
|
}
|
2003-03-18 06:30:54 +01:00
|
|
|
next:
|
2002-05-14 22:54:58 +02:00
|
|
|
current_line++;
|
|
|
|
}
|
2002-08-01 20:34:12 +02:00
|
|
|
close_input_file( file );
|
2003-03-18 06:30:54 +01:00
|
|
|
return !nb_errors;
|
2002-05-14 22:54:58 +02:00
|
|
|
}
|