2000-06-23 22:15:35 +02:00
|
|
|
/*
|
|
|
|
* Spec file parser
|
|
|
|
*
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
|
|
|
* Copyright 1995 Martin von Loewis
|
|
|
|
* Copyright 1995, 1996, 1997 Alexandre Julliard
|
|
|
|
* Copyright 1997 Eric Youngdale
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
#include "config.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 SPEC_TYPE SpecType = SPEC_INVALID;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
"pascal16", /* TYPE_PASCAL_16 */
|
|
|
|
"pascal", /* TYPE_PASCAL */
|
|
|
|
"equate", /* TYPE_ABS */
|
|
|
|
"register", /* TYPE_REGISTER */
|
|
|
|
"interrupt", /* TYPE_INTERRUPT */
|
|
|
|
"stub", /* TYPE_STUB */
|
|
|
|
"stdcall", /* TYPE_STDCALL */
|
|
|
|
"cdecl", /* TYPE_CDECL */
|
|
|
|
"varargs", /* TYPE_VARARGS */
|
|
|
|
"extern", /* TYPE_EXTERN */
|
|
|
|
"forward" /* TYPE_FORWARD */
|
|
|
|
};
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
static const char * const FlagNames[] =
|
|
|
|
{
|
|
|
|
"noimport", /* FLAG_NOIMPORT */
|
|
|
|
"norelay", /* FLAG_NORELAY */
|
|
|
|
"ret64", /* FLAG_RET64 */
|
|
|
|
"i386", /* FLAG_I386 */
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
return (ch == '(' || ch == ')' || ch == '-');
|
|
|
|
}
|
|
|
|
|
2001-02-15 22:27:06 +01:00
|
|
|
static const char * GetTokenInLine(void)
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove initial white space.
|
|
|
|
*/
|
2001-02-15 22:27:06 +01:00
|
|
|
while (isspace(*p)) p++;
|
|
|
|
|
|
|
|
if ((*p == '\0') || (*p == '#')) return NULL;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-02-15 22:27:06 +01:00
|
|
|
static const char * GetToken( int allow_eof )
|
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
|
|
|
|
|
|
|
while ((token = GetTokenInLine()) == NULL)
|
|
|
|
{
|
|
|
|
ParseNext = ParseBuffer;
|
2001-02-15 22:27:06 +01:00
|
|
|
current_line++;
|
|
|
|
if (fgets(ParseBuffer, sizeof(ParseBuffer), input_file) == NULL)
|
|
|
|
{
|
|
|
|
if (!allow_eof) fatal_error( "Unexpected end of file\n" );
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-05 05:49:13 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* ParseDebug
|
|
|
|
*
|
|
|
|
* Parse a debug channel definition.
|
|
|
|
*/
|
|
|
|
static void ParseDebug(void)
|
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token = GetToken(0);
|
2000-11-05 05:49:13 +01:00
|
|
|
if (*token != '(') fatal_error( "Expected '(' got '%s'\n", token );
|
2000-11-26 05:31:48 +01:00
|
|
|
for (;;)
|
2000-11-05 05:49:13 +01:00
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
2000-11-05 05:49:13 +01:00
|
|
|
if (*token == ')') break;
|
|
|
|
debug_channels = xrealloc( debug_channels,
|
|
|
|
(nb_debug_channels + 1) * sizeof(*debug_channels));
|
|
|
|
debug_channels[nb_debug_channels++] = xstrdup(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-14 23:18:22 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* ParseIgnore
|
|
|
|
*
|
|
|
|
* Parse an 'ignore' definition.
|
|
|
|
*/
|
|
|
|
static void ParseIgnore(void)
|
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token = GetToken(0);
|
2000-12-14 23:18:22 +01:00
|
|
|
if (*token != '(') fatal_error( "Expected '(' got '%s'\n", token );
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
token = GetToken(0);
|
|
|
|
if (*token == ')') break;
|
|
|
|
add_ignore_symbol( token );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* ParseVariable
|
|
|
|
*
|
|
|
|
* Parse a variable definition.
|
|
|
|
*/
|
|
|
|
static void ParseVariable( ORDDEF *odp )
|
|
|
|
{
|
|
|
|
char *endptr;
|
|
|
|
int *value_array;
|
|
|
|
int n_values;
|
|
|
|
int value_array_size;
|
2001-02-15 22:27:06 +01:00
|
|
|
|
|
|
|
const char *token = GetToken(0);
|
2000-06-23 22:15:35 +02:00
|
|
|
if (*token != '(') fatal_error( "Expected '(' got '%s'\n", token );
|
|
|
|
|
|
|
|
n_values = 0;
|
|
|
|
value_array_size = 25;
|
|
|
|
value_array = xmalloc(sizeof(*value_array) * value_array_size);
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
for (;;)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(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;
|
|
|
|
value_array = xrealloc(value_array,
|
|
|
|
sizeof(*value_array) * value_array_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endptr == NULL || *endptr != '\0')
|
|
|
|
fatal_error( "Expected number value, got '%s'\n", token );
|
|
|
|
}
|
|
|
|
|
|
|
|
odp->u.var.n_values = n_values;
|
|
|
|
odp->u.var.values = xrealloc(value_array, sizeof(*value_array) * n_values);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* ParseExportFunction
|
|
|
|
*
|
|
|
|
* Parse a function definition.
|
|
|
|
*/
|
|
|
|
static void ParseExportFunction( ORDDEF *odp )
|
|
|
|
{
|
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
|
|
|
|
|
|
|
switch(SpecType)
|
|
|
|
{
|
|
|
|
case SPEC_WIN16:
|
2000-11-26 05:31:48 +01:00
|
|
|
if (odp->type == TYPE_STDCALL)
|
2000-06-23 22:15:35 +02:00
|
|
|
fatal_error( "'stdcall' not supported for Win16\n" );
|
|
|
|
if (odp->type == TYPE_VARARGS)
|
|
|
|
fatal_error( "'varargs' not supported for Win16\n" );
|
|
|
|
break;
|
|
|
|
case SPEC_WIN32:
|
|
|
|
if ((odp->type == TYPE_PASCAL) || (odp->type == TYPE_PASCAL_16))
|
|
|
|
fatal_error( "'pascal' not supported for Win32\n" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
2000-06-23 22:15:35 +02:00
|
|
|
if (*token != '(') fatal_error( "Expected '(' got '%s'\n", token );
|
|
|
|
|
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
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(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
|
|
|
}
|
|
|
|
else fatal_error( "Unknown variable type '%s'\n", token );
|
|
|
|
|
|
|
|
if (SpecType == SPEC_WIN32)
|
|
|
|
{
|
|
|
|
if (strcmp(token, "long") &&
|
|
|
|
strcmp(token, "ptr") &&
|
|
|
|
strcmp(token, "str") &&
|
|
|
|
strcmp(token, "wstr") &&
|
|
|
|
strcmp(token, "double"))
|
|
|
|
{
|
|
|
|
fatal_error( "Type '%s' not supported for Win32\n", token );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((*token != ')') || (i >= sizeof(odp->u.func.arg_types)))
|
|
|
|
fatal_error( "Too many arguments\n" );
|
|
|
|
|
|
|
|
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 */
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name = xstrdup( GetToken(0) );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* ParseEquate
|
|
|
|
*
|
|
|
|
* Parse an 'equate' definition.
|
|
|
|
*/
|
|
|
|
static void ParseEquate( ORDDEF *odp )
|
|
|
|
{
|
|
|
|
char *endptr;
|
2001-02-15 22:27:06 +01:00
|
|
|
|
|
|
|
const char *token = GetToken(0);
|
2000-06-23 22:15:35 +02:00
|
|
|
int value = strtol(token, &endptr, 0);
|
|
|
|
if (endptr == NULL || *endptr != '\0')
|
|
|
|
fatal_error( "Expected number value, got '%s'\n", token );
|
|
|
|
if (SpecType == SPEC_WIN32)
|
|
|
|
fatal_error( "'equate' not supported for Win32\n" );
|
|
|
|
odp->u.abs.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* ParseStub
|
|
|
|
*
|
|
|
|
* Parse a 'stub' definition.
|
|
|
|
*/
|
|
|
|
static void ParseStub( ORDDEF *odp )
|
|
|
|
{
|
|
|
|
odp->u.func.arg_types[0] = '\0';
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name = xstrdup("");
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* ParseInterrupt
|
|
|
|
*
|
|
|
|
* Parse an 'interrupt' definition.
|
|
|
|
*/
|
|
|
|
static void ParseInterrupt( ORDDEF *odp )
|
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
if (SpecType == SPEC_WIN32)
|
|
|
|
fatal_error( "'interrupt' not supported for Win32\n" );
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
2000-06-23 22:15:35 +02:00
|
|
|
if (*token != '(') fatal_error( "Expected '(' got '%s'\n", token );
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
2000-06-23 22:15:35 +02:00
|
|
|
if (*token != ')') fatal_error( "Expected ')' got '%s'\n", token );
|
|
|
|
|
|
|
|
odp->u.func.arg_types[0] = '\0';
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name = xstrdup( GetToken(0) );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* ParseExtern
|
|
|
|
*
|
|
|
|
* Parse an 'extern' definition.
|
|
|
|
*/
|
|
|
|
static void ParseExtern( ORDDEF *odp )
|
|
|
|
{
|
|
|
|
if (SpecType == SPEC_WIN16) fatal_error( "'extern' not supported for Win16\n" );
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name = xstrdup( GetToken(0) );
|
2000-11-26 05:31:48 +01:00
|
|
|
/* 'extern' definitions are not available for implicit import */
|
|
|
|
odp->flags |= FLAG_NOIMPORT;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* ParseForward
|
|
|
|
*
|
|
|
|
* Parse a 'forward' definition.
|
|
|
|
*/
|
|
|
|
static void ParseForward( ORDDEF *odp )
|
|
|
|
{
|
|
|
|
if (SpecType == SPEC_WIN16) fatal_error( "'forward' not supported for Win16\n" );
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name = xstrdup( GetToken(0) );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* ParseFlags
|
|
|
|
*
|
|
|
|
* Parse the optional flags for an entry point
|
|
|
|
*/
|
2001-02-15 22:27:06 +01:00
|
|
|
static const char *ParseFlags( 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
|
|
|
|
{
|
|
|
|
token = GetToken(0);
|
|
|
|
for (i = 0; FlagNames[i]; i++)
|
|
|
|
if (!strcmp( FlagNames[i], token )) break;
|
|
|
|
if (!FlagNames[i]) fatal_error( "Unknown flag '%s'\n", token );
|
|
|
|
odp->flags |= 1 << i;
|
|
|
|
token = GetToken(0);
|
|
|
|
} while (*token == '-');
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* fix_export_name
|
|
|
|
*
|
|
|
|
* Fix an exported function name by removing a possible @xx suffix
|
|
|
|
*/
|
|
|
|
static void fix_export_name( char *name )
|
|
|
|
{
|
|
|
|
char *p, *end = strrchr( name, '@' );
|
|
|
|
if (!end || !end[1] || end == name) return;
|
|
|
|
/* make sure all the rest is digits */
|
|
|
|
for (p = end + 1; *p; p++) if (!isdigit(*p)) return;
|
|
|
|
*end = 0;
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* ParseOrdinal
|
|
|
|
*
|
|
|
|
* Parse an ordinal definition.
|
|
|
|
*/
|
|
|
|
static void ParseOrdinal(int ordinal)
|
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-12-16 00:04:40 +01:00
|
|
|
ORDDEF *odp = xmalloc( sizeof(*odp) );
|
|
|
|
memset( odp, 0, sizeof(*odp) );
|
|
|
|
EntryPoints[nb_entry_points++] = odp;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
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)
|
|
|
|
fatal_error( "Expected type after ordinal, found '%s' instead\n", token );
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
|
|
|
if (*token == '-') token = ParseFlags( odp );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->name = xstrdup( token );
|
2000-09-28 01:40:43 +02:00
|
|
|
fix_export_name( odp->name );
|
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:
|
2000-06-23 22:15:35 +02:00
|
|
|
ParseVariable( odp );
|
|
|
|
break;
|
|
|
|
case TYPE_REGISTER:
|
|
|
|
case TYPE_PASCAL_16:
|
|
|
|
case TYPE_PASCAL:
|
|
|
|
case TYPE_STDCALL:
|
|
|
|
case TYPE_VARARGS:
|
|
|
|
case TYPE_CDECL:
|
|
|
|
ParseExportFunction( odp );
|
|
|
|
break;
|
|
|
|
case TYPE_INTERRUPT:
|
|
|
|
ParseInterrupt( odp );
|
|
|
|
break;
|
|
|
|
case TYPE_ABS:
|
|
|
|
ParseEquate( odp );
|
|
|
|
break;
|
|
|
|
case TYPE_STUB:
|
|
|
|
ParseStub( odp );
|
|
|
|
break;
|
|
|
|
case TYPE_EXTERN:
|
|
|
|
ParseExtern( odp );
|
|
|
|
break;
|
|
|
|
case TYPE_FORWARD:
|
|
|
|
ParseForward( odp );
|
|
|
|
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 */
|
2000-12-16 00:04:40 +01:00
|
|
|
EntryPoints[--nb_entry_points] = NULL;
|
|
|
|
free( odp );
|
2000-11-26 05:31:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
if (ordinal != -1)
|
|
|
|
{
|
|
|
|
if (ordinal >= MAX_ORDINALS) fatal_error( "Ordinal number %d too large\n", ordinal );
|
|
|
|
if (ordinal > Limit) Limit = ordinal;
|
|
|
|
if (ordinal < Base) Base = ordinal;
|
|
|
|
odp->ordinal = ordinal;
|
|
|
|
Ordinals[ordinal] = odp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp( odp->name, "@" ))
|
|
|
|
{
|
|
|
|
if (ordinal == -1)
|
|
|
|
fatal_error( "Nameless function needs an explicit ordinal number\n" );
|
|
|
|
if (SpecType != SPEC_WIN32)
|
|
|
|
fatal_error( "Nameless functions not supported for Win16\n" );
|
|
|
|
odp->name[0] = 0;
|
|
|
|
}
|
|
|
|
else Names[nb_names++] = odp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-12 04:45:55 +01:00
|
|
|
static int name_compare( const void *name1, const void *name2 )
|
|
|
|
{
|
|
|
|
ORDDEF *odp1 = *(ORDDEF **)name1;
|
|
|
|
ORDDEF *odp2 = *(ORDDEF **)name2;
|
|
|
|
return strcmp( odp1->name, odp2->name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* sort_names
|
|
|
|
*
|
|
|
|
* Sort the name array and catch duplicates.
|
|
|
|
*/
|
|
|
|
static void sort_names(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!nb_names) return;
|
|
|
|
|
|
|
|
/* sort the list of names */
|
|
|
|
qsort( Names, nb_names, sizeof(Names[0]), name_compare );
|
|
|
|
|
|
|
|
/* check for duplicate names */
|
|
|
|
for (i = 0; i < nb_names - 1; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp( Names[i]->name, Names[i+1]->name ))
|
|
|
|
{
|
|
|
|
current_line = max( Names[i]->lineno, Names[i+1]->lineno );
|
|
|
|
fatal_error( "'%s' redefined (previous definition at line %d)\n",
|
|
|
|
Names[i]->name, min( Names[i]->lineno, Names[i+1]->lineno ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* ParseTopLevel
|
|
|
|
*
|
|
|
|
* Parse a spec file.
|
|
|
|
*/
|
|
|
|
SPEC_TYPE ParseTopLevel( FILE *file )
|
|
|
|
{
|
2001-02-15 22:27:06 +01:00
|
|
|
const char *token;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
input_file = file;
|
|
|
|
current_line = 1;
|
2000-11-26 05:31:48 +01:00
|
|
|
while ((token = GetToken(1)) != NULL)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
if (strcmp(token, "name") == 0)
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
strcpy(DLLName, GetToken(0));
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(token, "file") == 0)
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
strcpy(DLLFileName, GetToken(0));
|
2000-06-23 22:15:35 +02:00
|
|
|
strupper(DLLFileName);
|
|
|
|
}
|
|
|
|
else if (strcmp(token, "type") == 0)
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
2000-06-23 22:15:35 +02:00
|
|
|
if (!strcmp(token, "win16" )) SpecType = SPEC_WIN16;
|
|
|
|
else if (!strcmp(token, "win32" )) SpecType = SPEC_WIN32;
|
|
|
|
else fatal_error( "Type must be 'win16' or 'win32'\n" );
|
|
|
|
}
|
|
|
|
else if (strcmp(token, "mode") == 0)
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
2000-06-23 22:15:35 +02:00
|
|
|
if (!strcmp(token, "dll" )) SpecMode = SPEC_MODE_DLL;
|
|
|
|
else if (!strcmp(token, "guiexe" )) SpecMode = SPEC_MODE_GUIEXE;
|
|
|
|
else if (!strcmp(token, "cuiexe" )) SpecMode = SPEC_MODE_CUIEXE;
|
2000-12-15 04:38:11 +01:00
|
|
|
else if (!strcmp(token, "guiexe_unicode" )) SpecMode = SPEC_MODE_GUIEXE_UNICODE;
|
|
|
|
else if (!strcmp(token, "cuiexe_unicode" )) SpecMode = SPEC_MODE_CUIEXE_UNICODE;
|
|
|
|
else fatal_error( "Mode must be 'dll', 'guiexe', 'cuiexe', 'guiexe_unicode' or 'cuiexe_unicode'\n" );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(token, "heap") == 0)
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
token = GetToken(0);
|
2000-06-23 22:15:35 +02:00
|
|
|
if (!IsNumberString(token)) fatal_error( "Expected number after heap\n" );
|
|
|
|
DLLHeapSize = atoi(token);
|
|
|
|
}
|
2001-06-08 00:29:03 +02:00
|
|
|
else if (strcmp(token, "stack") == 0)
|
|
|
|
{
|
|
|
|
token = GetToken(0);
|
|
|
|
if (!IsNumberString(token)) fatal_error( "Expected number after stack\n" );
|
|
|
|
stack_size = atoi(token);
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
else if (strcmp(token, "init") == 0)
|
|
|
|
{
|
2000-12-16 00:04:40 +01:00
|
|
|
if (SpecType == SPEC_WIN16)
|
2000-06-23 22:15:35 +02:00
|
|
|
fatal_error( "init cannot be used for Win16 spec files\n" );
|
2000-12-16 00:04:40 +01:00
|
|
|
init_func = xstrdup( GetToken(0) );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(token, "import") == 0)
|
|
|
|
{
|
2000-12-26 02:22:34 +01:00
|
|
|
const char* name;
|
|
|
|
int delay = 0;
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
if (SpecType != SPEC_WIN32)
|
|
|
|
fatal_error( "Imports not supported for Win16\n" );
|
2000-12-26 02:22:34 +01:00
|
|
|
name = GetToken(0);
|
|
|
|
if (*name == '-')
|
|
|
|
{
|
|
|
|
name = GetToken(0);
|
|
|
|
if (!strcmp(name, "delay"))
|
|
|
|
{
|
2001-02-13 03:06:38 +01:00
|
|
|
|
2000-12-26 02:22:34 +01:00
|
|
|
name = GetToken(0);
|
2001-02-13 03:06:38 +01:00
|
|
|
#ifndef __PPC__
|
2000-12-26 02:22:34 +01:00
|
|
|
delay = 1;
|
2001-02-13 03:06:38 +01:00
|
|
|
#else
|
|
|
|
warning( "The 'delay' option is not yet supported on the PPC. 'delay' will be ignored.\n");
|
|
|
|
#endif /* __PPC__ */
|
2000-12-26 02:22:34 +01:00
|
|
|
}
|
|
|
|
else fatal_error( "Unknown option '%s' for import directive\n", name );
|
|
|
|
}
|
|
|
|
add_import_dll( name, delay );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(token, "rsrc") == 0)
|
|
|
|
{
|
2000-11-26 05:31:48 +01:00
|
|
|
if (SpecType != SPEC_WIN16) load_res32_file( GetToken(0) );
|
|
|
|
else load_res16_file( GetToken(0) );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2000-07-28 02:07:18 +02:00
|
|
|
else if (strcmp(token, "owner") == 0)
|
|
|
|
{
|
|
|
|
if (SpecType != SPEC_WIN16)
|
|
|
|
fatal_error( "Owner only supported for Win16 spec files\n" );
|
2000-11-26 05:31:48 +01:00
|
|
|
strcpy( owner_name, GetToken(0) );
|
2000-07-28 02:07:18 +02:00
|
|
|
}
|
2000-11-05 05:49:13 +01:00
|
|
|
else if (strcmp(token, "debug_channels") == 0)
|
|
|
|
{
|
|
|
|
if (SpecType != SPEC_WIN32)
|
|
|
|
fatal_error( "debug channels only supported for Win32 spec files\n" );
|
|
|
|
ParseDebug();
|
|
|
|
}
|
2000-12-14 23:18:22 +01:00
|
|
|
else if (strcmp(token, "ignore") == 0)
|
|
|
|
{
|
|
|
|
if (SpecType != SPEC_WIN32)
|
|
|
|
fatal_error( "'ignore' only supported for Win32 spec files\n" );
|
|
|
|
ParseIgnore();
|
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
else if (strcmp(token, "@") == 0)
|
|
|
|
{
|
|
|
|
if (SpecType != SPEC_WIN32)
|
|
|
|
fatal_error( "'@' ordinals not supported for Win16\n" );
|
|
|
|
ParseOrdinal( -1 );
|
|
|
|
}
|
|
|
|
else if (IsNumberString(token))
|
|
|
|
{
|
|
|
|
ParseOrdinal( atoi(token) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fatal_error( "Expected name, id, length or ordinal\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!DLLFileName[0])
|
|
|
|
{
|
|
|
|
if (SpecMode == SPEC_MODE_DLL)
|
|
|
|
sprintf( DLLFileName, "%s.dll", DLLName );
|
|
|
|
else
|
|
|
|
sprintf( DLLFileName, "%s.exe", DLLName );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SpecType == SPEC_INVALID) fatal_error( "Missing 'type' declaration\n" );
|
2000-07-28 02:07:18 +02:00
|
|
|
if (SpecType == SPEC_WIN16 && !owner_name[0])
|
|
|
|
fatal_error( "'owner' not specified for Win16 dll\n" );
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
current_line = 0; /* no longer parsing the input file */
|
2000-11-12 04:45:55 +01:00
|
|
|
sort_names();
|
2000-06-23 22:15:35 +02:00
|
|
|
return SpecType;
|
|
|
|
}
|