- fix more line endings

This commit is contained in:
Rachael Alexanderson 2021-03-10 11:44:43 -05:00
parent da43a67e52
commit 497dd29e9e
17 changed files with 11173 additions and 11173 deletions

234
common.h
View file

@ -1,117 +1,117 @@
//**************************************************************************
//**
//** common.h
//**
//**************************************************************************
#ifndef __COMMON_H__
#define __COMMON_H__
// HEADER FILES ------------------------------------------------------------
// MACROS ------------------------------------------------------------------
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef YES
#define YES 1
#endif
#ifndef NO
#define NO 0
#endif
// Increased limits - Ty 03jan2000
// 32 is okay
#define MAX_IDENTIFIER_LENGTH 32
// 32k long quoted string should be okay
#define MAX_QUOTED_LENGTH 32768
// 512 max file name is okay in DOS/Win
#define MAX_FILE_NAME_LENGTH 512
// Was 64
#define MAX_SCRIPT_COUNT 1000
// Was 32
#define MAX_MAP_VARIABLES 128
// Left alone--there's something in the docs about this...
// [RH] Bumped up to 20 for fun.
#define MAX_SCRIPT_VARIABLES 20
// Was 64
#define MAX_WORLD_VARIABLES 256
// [RH] New
#define MAX_GLOBAL_VARIABLES 64
// Was 128
#define MAX_STRINGS 32768
// Don't know what this is
#define DEFAULT_OBJECT_SIZE 65536
// Added Ty 07Jan2000 for error details
#define MAX_STATEMENT_LENGTH 4096
#define MAX_FUNCTION_COUNT 8192
#define MAX_IMPORTS 256
#define MAX_SCRIPT_ARRAYS 255
// Max number of include paths the user can specify
// This includes the "working directory"!
#define MAX_INCLUDE_PATHS 16
// Maximum number of translations that can be used
#define MAX_TRANSLATIONS 32
enum
{
STRLIST_PICS,
STRLIST_FUNCTIONS,
STRLIST_MAPVARS,
STRLIST_NAMEDSCRIPTS,
NUM_STRLISTS
};
// These are just defs and have not been messed with
#define ASCII_SPACE 32
#define ASCII_QUOTE 34
#define ASCII_UNDERSCORE 95
#define EOF_CHARACTER 127
#ifdef __NeXT__
#define DIRECTORY_DELIMITER "/"
#define DIRECTORY_DELIMITER_CHAR ('/')
#else
#define DIRECTORY_DELIMITER "\\"
#define DIRECTORY_DELIMITER_CHAR ('\\')
#endif
#define MAKE4CC(a,b,c,d) ((a)|((b)<<8)|((c)<<16)|((d)<<24))
// TYPES -------------------------------------------------------------------
typedef unsigned int boolean;
typedef unsigned char byte;
typedef signed char S_BYTE;
typedef unsigned char U_BYTE;
typedef signed short S_WORD;
typedef unsigned short U_WORD;
typedef int S_INT;
typedef unsigned int U_INT;
// typedef signed long S_LONG;
// typedef unsigned long U_LONG;
enum ImportModes
{
IMPORT_None,
IMPORT_Importing,
IMPORT_Exporting
};
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PUBLIC DATA DECLARATIONS ------------------------------------------------
#endif
//**************************************************************************
//**
//** common.h
//**
//**************************************************************************
#ifndef __COMMON_H__
#define __COMMON_H__
// HEADER FILES ------------------------------------------------------------
// MACROS ------------------------------------------------------------------
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef YES
#define YES 1
#endif
#ifndef NO
#define NO 0
#endif
// Increased limits - Ty 03jan2000
// 32 is okay
#define MAX_IDENTIFIER_LENGTH 32
// 32k long quoted string should be okay
#define MAX_QUOTED_LENGTH 32768
// 512 max file name is okay in DOS/Win
#define MAX_FILE_NAME_LENGTH 512
// Was 64
#define MAX_SCRIPT_COUNT 1000
// Was 32
#define MAX_MAP_VARIABLES 128
// Left alone--there's something in the docs about this...
// [RH] Bumped up to 20 for fun.
#define MAX_SCRIPT_VARIABLES 20
// Was 64
#define MAX_WORLD_VARIABLES 256
// [RH] New
#define MAX_GLOBAL_VARIABLES 64
// Was 128
#define MAX_STRINGS 32768
// Don't know what this is
#define DEFAULT_OBJECT_SIZE 65536
// Added Ty 07Jan2000 for error details
#define MAX_STATEMENT_LENGTH 4096
#define MAX_FUNCTION_COUNT 8192
#define MAX_IMPORTS 256
#define MAX_SCRIPT_ARRAYS 255
// Max number of include paths the user can specify
// This includes the "working directory"!
#define MAX_INCLUDE_PATHS 16
// Maximum number of translations that can be used
#define MAX_TRANSLATIONS 32
enum
{
STRLIST_PICS,
STRLIST_FUNCTIONS,
STRLIST_MAPVARS,
STRLIST_NAMEDSCRIPTS,
NUM_STRLISTS
};
// These are just defs and have not been messed with
#define ASCII_SPACE 32
#define ASCII_QUOTE 34
#define ASCII_UNDERSCORE 95
#define EOF_CHARACTER 127
#ifdef __NeXT__
#define DIRECTORY_DELIMITER "/"
#define DIRECTORY_DELIMITER_CHAR ('/')
#else
#define DIRECTORY_DELIMITER "\\"
#define DIRECTORY_DELIMITER_CHAR ('\\')
#endif
#define MAKE4CC(a,b,c,d) ((a)|((b)<<8)|((c)<<16)|((d)<<24))
// TYPES -------------------------------------------------------------------
typedef unsigned int boolean;
typedef unsigned char byte;
typedef signed char S_BYTE;
typedef unsigned char U_BYTE;
typedef signed short S_WORD;
typedef unsigned short U_WORD;
typedef int S_INT;
typedef unsigned int U_INT;
// typedef signed long S_LONG;
// typedef unsigned long U_LONG;
enum ImportModes
{
IMPORT_None,
IMPORT_Importing,
IMPORT_Exporting
};
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PUBLIC DATA DECLARATIONS ------------------------------------------------
#endif

870
error.c
View file

@ -1,435 +1,435 @@
//**************************************************************************
//**
//** error.c
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "common.h"
#include "error.h"
#include "token.h"
#include "misc.h"
// MACROS ------------------------------------------------------------------
#define ERROR_FILE_NAME "acs.err"
// TYPES -------------------------------------------------------------------
typedef enum
{
ERRINFO_GCC,
ERRINFO_VCC
} errorInfo_e;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static char *ErrorText(error_t error);
static char *ErrorFileName(void);
static void eprintf(const char *fmt, ...);
static void veprintf(const char *fmt, va_list args);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern char acs_SourceFileName[MAX_FILE_NAME_LENGTH];
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static struct
{
error_t number;
char *name;
} ErrorNames[] =
{
{ ERR_MISSING_SEMICOLON, "Missing semicolon." },
{ ERR_MISSING_LPAREN, "Missing '('." },
{ ERR_MISSING_RPAREN, "Missing ')'." },
{ ERR_MISSING_LBRACE, "Missing '{'." },
{ ERR_MISSING_SCRIPT_NUMBER, "Missing script number." },
{ ERR_IDENTIFIER_TOO_LONG, "Identifier too long." },
{ ERR_STRING_TOO_LONG, "String too long." },
{ ERR_FILE_NAME_TOO_LONG, "File name too long.\nFile: \"%s\"" },
{ ERR_BAD_CHARACTER, "Bad character in script text." },
{ ERR_BAD_CHARACTER_CONSTANT, "Bad character constant in script text." },
{ ERR_ALLOC_PCODE_BUFFER, "Failed to allocate PCODE buffer." },
{ ERR_PCODE_BUFFER_OVERFLOW, "PCODE buffer overflow." },
{ ERR_TOO_MANY_SCRIPTS, "Too many scripts." },
{ ERR_TOO_MANY_FUNCTIONS, "Too many functions." },
{ ERR_SAVE_OBJECT_FAILED, "Couldn't save object file." },
{ ERR_MISSING_LPAREN_SCR, "Missing '(' in script definition." },
{ ERR_INVALID_IDENTIFIER, "Invalid identifier." },
{ ERR_REDEFINED_IDENTIFIER, "%s : Redefined identifier." },
{ ERR_MISSING_COMMA, "Missing comma." },
{ ERR_BAD_VAR_TYPE, "Invalid variable type." },
{ ERR_BAD_RETURN_TYPE, "Invalid return type." },
{ ERR_TOO_MANY_SCRIPT_ARGS, "Too many script arguments." },
{ ERR_MISSING_LBRACE_SCR, "Missing opening '{' in script definition." },
{ ERR_MISSING_RBRACE_SCR, "Missing closing '}' in script definition." },
{ ERR_TOO_MANY_MAP_VARS, "Too many map variables." },
{ ERR_TOO_MANY_SCRIPT_VARS, "Too many script variables." },
{ ERR_TOO_MANY_FUNCTION_VARS, "Too many function variables." },
{ ERR_TOO_MANY_SCRIPT_ARRAYS, "Too many script arrays." },
{ ERR_TOO_MANY_FUNCTION_ARRAYS, "Too many function arrays." },
{ ERR_MISSING_WVAR_INDEX, "Missing index in world variable declaration." },
{ ERR_MISSING_GVAR_INDEX, "Missing index in global variable declaration." },
{ ERR_BAD_WVAR_INDEX, "World variable index out of range." },
{ ERR_MISSING_WVAR_COLON, "Missing colon in world variable declaration." },
{ ERR_MISSING_GVAR_COLON, "Missing colon in global variable declaration." },
{ ERR_MISSING_SPEC_VAL, "Missing value in special declaration." },
{ ERR_MISSING_SPEC_COLON, "Missing colon in special declaration." },
{ ERR_MISSING_SPEC_ARGC, "Missing argument count in special declaration." },
{ ERR_CANT_READ_FILE, "Couldn't read file.\nFile: \"%s\"" },
{ ERR_CANT_OPEN_FILE, "Couldn't open file.\nFile: \"%s\"" },
{ ERR_CANT_OPEN_DBGFILE, "Couldn't open debug file." },
{ ERR_INVALID_DIRECTIVE, "Invalid directive." },
{ ERR_BAD_DEFINE, "Non-numeric constant found in #define." },
{ ERR_INCL_NESTING_TOO_DEEP, "Include nesting too deep.\nUnable to include file \"%s\"." },
{ ERR_STRING_LIT_NOT_FOUND, "String literal not found." },
{ ERR_INVALID_DECLARATOR, "Invalid declarator." },
{ ERR_BAD_LSPEC_ARG_COUNT, "Incorrect number of special arguments." },
{ ERR_BAD_ARG_COUNT, "Incorrect number of arguments." },
{ ERR_UNKNOWN_IDENTIFIER, "%s : Identifier has not been declared." },
{ ERR_MISSING_COLON, "Missing colon." },
{ ERR_BAD_EXPR, "Syntax error in expression." },
{ ERR_BAD_CONST_EXPR, "Syntax error in constant expression." },
{ ERR_DIV_BY_ZERO_IN_CONST_EXPR, "Division by zero in constant expression." },
{ ERR_NO_DIRECT_VER, "Internal function has no direct version." },
{ ERR_ILLEGAL_EXPR_IDENT, "%s : Illegal identifier in expression." },
{ ERR_EXPR_FUNC_NO_RET_VAL, "Function call in expression has no return value." },
{ ERR_MISSING_ASSIGN_OP, "Missing assignment operator." },
{ ERR_INCDEC_OP_ON_NON_VAR, "'++' or '--' used on a non-variable." },
{ ERR_MISSING_RBRACE, "Missing '}' at end of compound statement." },
{ ERR_INVALID_STATEMENT, "Invalid statement." },
{ ERR_BAD_DO_STATEMENT, "Do statement not followed by 'while' or 'until'." },
{ ERR_BAD_SCRIPT_DECL, "Bad script declaration." },
{ ERR_CASE_OVERFLOW, "Internal Error: Case stack overflow." },
{ ERR_BREAK_OVERFLOW, "Internal Error: Break stack overflow." },
{ ERR_CONTINUE_OVERFLOW, "Internal Error: Continue stack overflow." },
{ ERR_STATEMENT_OVERFLOW, "Internal Error: Statement overflow." },
{ ERR_MISPLACED_BREAK, "Misplaced BREAK statement." },
{ ERR_MISPLACED_CONTINUE, "Misplaced CONTINUE statement." },
{ ERR_CASE_NOT_IN_SWITCH, "CASE must appear in switch statement." },
{ ERR_DEFAULT_NOT_IN_SWITCH, "DEFAULT must appear in switch statement." },
{ ERR_MULTIPLE_DEFAULT, "Only 1 DEFAULT per switch allowed." },
{ ERR_EXPR_STACK_OVERFLOW, "Expression stack overflow." },
{ ERR_EXPR_STACK_EMPTY, "Tried to POP empty expression stack." },
{ ERR_UNKNOWN_CONST_EXPR_PCD, "Unknown PCD in constant expression." },
{ ERR_BAD_RADIX_CONSTANT, "Radix out of range in integer constant." },
{ ERR_BAD_ASSIGNMENT, "Syntax error in multiple assignment statement." },
{ ERR_OUT_OF_MEMORY, "Out of memory." },
{ ERR_TOO_MANY_STRINGS, "Too many strings. Current max is %d" },
{ ERR_UNKNOWN_PRTYPE, "Unknown cast type in print statement." },
{ ERR_SCRIPT_OUT_OF_RANGE, "Script number must be between 1 and 32767." },
{ ERR_MISSING_PARAM, "Missing required argument." },
{ ERR_SCRIPT_ALREADY_DEFINED, "Script already has a body." },
{ ERR_FUNCTION_ALREADY_DEFINED, "Function already has a body." },
{ ERR_PARM_MUST_BE_VAR, "Parameter must be a variable." },
{ ERR_MISSING_FONT_NAME, "Missing font name." },
{ ERR_MISSING_LBRACE_FONTS, "Missing opening '{' in font list." },
{ ERR_MISSING_RBRACE_FONTS, "Missing closing '}' in font list." },
{ ERR_NOCOMPACT_NOT_HERE, "#nocompact must appear before any scripts." },
{ ERR_MISSING_ASSIGN, "Missing '='." },
{ ERR_PREVIOUS_NOT_VOID, "Previous use of function expected a return value." },
{ ERR_MUST_RETURN_A_VALUE, "Function must return a value." },
{ ERR_MUST_NOT_RETURN_A_VALUE, "Void functions cannot return a value." },
{ ERR_SUSPEND_IN_FUNCTION, "Suspend cannot be used inside a function." },
{ ERR_TERMINATE_IN_FUNCTION, "Terminate cannot be used inside a function." },
{ ERR_RESTART_IN_FUNCTION, "Restart cannot be used inside a function." },
{ ERR_RETURN_OUTSIDE_FUNCTION, "Return can only be used inside a function." },
{ ERR_FUNC_ARGUMENT_COUNT, "Function %s should have %d argument%s." },
{ ERR_EOF, "Unexpected end of file." },
{ ERR_UNDEFINED_FUNC, "Function %s is used but not defined." },
{ ERR_TOO_MANY_ARRAY_DIMS, "Too many array dimensions." },
{ ERR_TOO_MANY_ARRAY_INIT, "Too many initializers for array." },
{ ERR_MISSING_LBRACKET, "Missing '['." },
{ ERR_MISSING_RBRACKET, "Missing ']'." },
{ ERR_ZERO_DIMENSION, "Arrays cannot have a dimension of zero." },
{ ERR_TOO_MANY_DIM_USED, "%s only has %d dimensions." },
{ ERR_TOO_FEW_DIM_USED, "%s access needs %d more dimensions." },
{ ERR_ARRAY_MAPVAR_ONLY, "Only map variables can be arrays." },
{ ERR_NOT_AN_ARRAY, "%s is not an array." },
{ ERR_MISSING_LBRACE_ARR, "Missing opening '{' in array initializer." },
{ ERR_MISSING_RBRACE_ARR, "Missing closing '}' in array initializer." },
{ ERR_LATENT_IN_FUNC, "Latent functions cannot be used inside functions." },
{ ERR_LOCAL_VAR_SHADOWED, "A global identifier already has this name." },
{ ERR_MULTIPLE_IMPORTS, "You can only #import one file." },
{ ERR_IMPORT_IN_EXPORT, "You cannot #import from inside an imported file." },
{ ERR_EXPORTER_NOT_FLAGGED, "A file that you #import must have a #library line." },
{ ERR_TOO_MANY_IMPORTS, "Too many files imported." },
{ ERR_NO_NEED_ARRAY_SIZE, "Only map arrays need a size." },
{ ERR_NO_MULTIDIMENSIONS, "Only map arrays can have more than one dimension." },
{ ERR_NEED_ARRAY_SIZE, "Missing array size." },
{ ERR_DISCONNECT_NEEDS_1_ARG, "Disconnect scripts must have 1 argument." },
{ ERR_UNCLOSED_WITH_ARGS, "Most special scripts must not have arguments." },
{ ERR_NOT_A_CHAR_ARRAY, "%s has %d dimensions. Use %d subscripts to get a char array." },
{ ERR_CANT_FIND_INCLUDE, "Couldn't find include file \"%s\"." },
{ ERR_SCRIPT_NAMED_NONE, "Scripts may not be named \"None\"." },
{ ERR_HEXEN_COMPAT, "Attempt to use feature not supported by Hexen." },
{ ERR_NOT_HEXEN, "Cannot save; new features are not compatible with Hexen." },
{ ERR_SPECIAL_RANGE, "Line specials with values higher than 255 require #nocompact." },
{ ERR_EVENT_NEEDS_3_ARG, "Event scripts must have 3 arguments." }, // [BB]
{ ERR_LIBRARY_NOT_FIRST, "#library must come before anything else." },
{ ERR_NONE, NULL }
};
static FILE *ErrorFile;
static int ErrorCount;
static errorInfo_e ErrorFormat;
static char *ErrorSourceName;
static int ErrorSourceLine;
// CODE --------------------------------------------------------------------
//==========================================================================
//
// ERR_ErrorAt
//
//==========================================================================
void ERR_ErrorAt(char *source, int line)
{
ErrorSourceName = source;
ErrorSourceLine = line;
}
//==========================================================================
//
// ERR_Error
//
//==========================================================================
void ERR_Error(error_t error, boolean info, ...)
{
va_list args;
va_start(args, info);
ERR_ErrorV(error, info, args);
va_end(args);
}
//==========================================================================
//
// ERR_Exit
//
//==========================================================================
void ERR_Exit(error_t error, boolean info, ...)
{
va_list args;
va_start(args, info);
ERR_ErrorV(error, info, args);
va_end(args);
ERR_Finish();
}
//==========================================================================
//
// ERR_Finish
//
//==========================================================================
void ERR_Finish(void)
{
if(ErrorFile)
{
fclose(ErrorFile);
ErrorFile = NULL;
}
if(ErrorCount)
{
exit(1);
}
}
//==========================================================================
//
// ShowError
//
//==========================================================================
void ERR_ErrorV(error_t error, boolean info, va_list args)
{
char *text;
boolean showLine = NO;
static boolean showedInfo = NO;
if(!ErrorFile)
{
ErrorFile = fopen(ErrorFileName(), "w");
}
if(ErrorCount == 0)
{
fprintf(stderr, "\n**** ERROR ****\n");
}
else if(ErrorCount == 100)
{
eprintf("More than 100 errors. Can't continue.\n");
ERR_Finish();
}
ErrorCount++;
if(info == YES)
{
char *source;
int line;
if(ErrorSourceName)
{
source = ErrorSourceName;
line = ErrorSourceLine;
ErrorSourceName = NULL;
}
else
{
source = tk_SourceName;
line = tk_Line;
showLine = YES;
}
if(showedInfo == NO)
{ // Output info compatible with older ACCs
// for editors that expect it.
showedInfo = YES;
eprintf("Line %d in file \"%s\" ...\n", line, source);
}
if(ErrorFormat == ERRINFO_GCC)
{
eprintf("%s:%d: ", source, line);
}
else
{
eprintf("%s(%d) : ", source, line);
if(error != ERR_NONE)
{
eprintf("error %04d: ", error);
}
}
}
if(error != ERR_NONE)
{
text = ErrorText(error);
if(text != NULL)
{
veprintf(text, args);
}
eprintf("\n");
if(showLine)
{
// deal with master source line and position indicator - Ty 07jan2000
MasterSourceLine[MasterSourcePos] = '\0'; // pre-incremented already
eprintf("> %s\n", MasterSourceLine); // the string
eprintf(">%*s\n", MasterSourcePos, "^"); // pointer to error
}
}
#if 0
else
{
va_list args2;
va_start(va_arg(args,char*), args2);
veprintf(va_arg(args,char*), args2);
va_end(args2);
}
#endif
}
//==========================================================================
//
// ERR_RemoveErrorFile
//
//==========================================================================
void ERR_RemoveErrorFile(void)
{
remove(ErrorFileName());
}
//==========================================================================
//
// ERR_ErrorFileName
//
//==========================================================================
static char *ErrorFileName(void)
{
static char errFileName[MAX_FILE_NAME_LENGTH];
strcpy(errFileName, acs_SourceFileName);
if(MS_StripFilename(errFileName) == NO)
{
strcpy(errFileName, ERROR_FILE_NAME);
}
else
{
strcat(errFileName, ERROR_FILE_NAME);
}
return errFileName;
}
//==========================================================================
//
// ErrorText
//
//==========================================================================
static char *ErrorText(error_t error)
{
int i;
for(i = 0; ErrorNames[i].number != ERR_NONE; i++)
{
if(error == ErrorNames[i].number)
{
return ErrorNames[i].name;
}
}
return NULL;
}
//==========================================================================
//
// eprintf
//
//==========================================================================
static void eprintf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
veprintf(fmt, args);
va_end(args);
}
//==========================================================================
//
// veprintf
//
//==========================================================================
static void veprintf(const char *fmt, va_list args)
{
#ifdef va_copy
va_list copy;
va_copy(copy, args);
#endif
vfprintf(stderr, fmt, args);
if(ErrorFile)
{
#ifdef va_copy
vfprintf(ErrorFile, fmt, copy);
#else
vfprintf(ErrorFile, fmt, args);
#endif
}
#ifdef va_copy
va_end(copy);
#endif
}
//**************************************************************************
//**
//** error.c
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "common.h"
#include "error.h"
#include "token.h"
#include "misc.h"
// MACROS ------------------------------------------------------------------
#define ERROR_FILE_NAME "acs.err"
// TYPES -------------------------------------------------------------------
typedef enum
{
ERRINFO_GCC,
ERRINFO_VCC
} errorInfo_e;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static char *ErrorText(error_t error);
static char *ErrorFileName(void);
static void eprintf(const char *fmt, ...);
static void veprintf(const char *fmt, va_list args);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern char acs_SourceFileName[MAX_FILE_NAME_LENGTH];
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static struct
{
error_t number;
char *name;
} ErrorNames[] =
{
{ ERR_MISSING_SEMICOLON, "Missing semicolon." },
{ ERR_MISSING_LPAREN, "Missing '('." },
{ ERR_MISSING_RPAREN, "Missing ')'." },
{ ERR_MISSING_LBRACE, "Missing '{'." },
{ ERR_MISSING_SCRIPT_NUMBER, "Missing script number." },
{ ERR_IDENTIFIER_TOO_LONG, "Identifier too long." },
{ ERR_STRING_TOO_LONG, "String too long." },
{ ERR_FILE_NAME_TOO_LONG, "File name too long.\nFile: \"%s\"" },
{ ERR_BAD_CHARACTER, "Bad character in script text." },
{ ERR_BAD_CHARACTER_CONSTANT, "Bad character constant in script text." },
{ ERR_ALLOC_PCODE_BUFFER, "Failed to allocate PCODE buffer." },
{ ERR_PCODE_BUFFER_OVERFLOW, "PCODE buffer overflow." },
{ ERR_TOO_MANY_SCRIPTS, "Too many scripts." },
{ ERR_TOO_MANY_FUNCTIONS, "Too many functions." },
{ ERR_SAVE_OBJECT_FAILED, "Couldn't save object file." },
{ ERR_MISSING_LPAREN_SCR, "Missing '(' in script definition." },
{ ERR_INVALID_IDENTIFIER, "Invalid identifier." },
{ ERR_REDEFINED_IDENTIFIER, "%s : Redefined identifier." },
{ ERR_MISSING_COMMA, "Missing comma." },
{ ERR_BAD_VAR_TYPE, "Invalid variable type." },
{ ERR_BAD_RETURN_TYPE, "Invalid return type." },
{ ERR_TOO_MANY_SCRIPT_ARGS, "Too many script arguments." },
{ ERR_MISSING_LBRACE_SCR, "Missing opening '{' in script definition." },
{ ERR_MISSING_RBRACE_SCR, "Missing closing '}' in script definition." },
{ ERR_TOO_MANY_MAP_VARS, "Too many map variables." },
{ ERR_TOO_MANY_SCRIPT_VARS, "Too many script variables." },
{ ERR_TOO_MANY_FUNCTION_VARS, "Too many function variables." },
{ ERR_TOO_MANY_SCRIPT_ARRAYS, "Too many script arrays." },
{ ERR_TOO_MANY_FUNCTION_ARRAYS, "Too many function arrays." },
{ ERR_MISSING_WVAR_INDEX, "Missing index in world variable declaration." },
{ ERR_MISSING_GVAR_INDEX, "Missing index in global variable declaration." },
{ ERR_BAD_WVAR_INDEX, "World variable index out of range." },
{ ERR_MISSING_WVAR_COLON, "Missing colon in world variable declaration." },
{ ERR_MISSING_GVAR_COLON, "Missing colon in global variable declaration." },
{ ERR_MISSING_SPEC_VAL, "Missing value in special declaration." },
{ ERR_MISSING_SPEC_COLON, "Missing colon in special declaration." },
{ ERR_MISSING_SPEC_ARGC, "Missing argument count in special declaration." },
{ ERR_CANT_READ_FILE, "Couldn't read file.\nFile: \"%s\"" },
{ ERR_CANT_OPEN_FILE, "Couldn't open file.\nFile: \"%s\"" },
{ ERR_CANT_OPEN_DBGFILE, "Couldn't open debug file." },
{ ERR_INVALID_DIRECTIVE, "Invalid directive." },
{ ERR_BAD_DEFINE, "Non-numeric constant found in #define." },
{ ERR_INCL_NESTING_TOO_DEEP, "Include nesting too deep.\nUnable to include file \"%s\"." },
{ ERR_STRING_LIT_NOT_FOUND, "String literal not found." },
{ ERR_INVALID_DECLARATOR, "Invalid declarator." },
{ ERR_BAD_LSPEC_ARG_COUNT, "Incorrect number of special arguments." },
{ ERR_BAD_ARG_COUNT, "Incorrect number of arguments." },
{ ERR_UNKNOWN_IDENTIFIER, "%s : Identifier has not been declared." },
{ ERR_MISSING_COLON, "Missing colon." },
{ ERR_BAD_EXPR, "Syntax error in expression." },
{ ERR_BAD_CONST_EXPR, "Syntax error in constant expression." },
{ ERR_DIV_BY_ZERO_IN_CONST_EXPR, "Division by zero in constant expression." },
{ ERR_NO_DIRECT_VER, "Internal function has no direct version." },
{ ERR_ILLEGAL_EXPR_IDENT, "%s : Illegal identifier in expression." },
{ ERR_EXPR_FUNC_NO_RET_VAL, "Function call in expression has no return value." },
{ ERR_MISSING_ASSIGN_OP, "Missing assignment operator." },
{ ERR_INCDEC_OP_ON_NON_VAR, "'++' or '--' used on a non-variable." },
{ ERR_MISSING_RBRACE, "Missing '}' at end of compound statement." },
{ ERR_INVALID_STATEMENT, "Invalid statement." },
{ ERR_BAD_DO_STATEMENT, "Do statement not followed by 'while' or 'until'." },
{ ERR_BAD_SCRIPT_DECL, "Bad script declaration." },
{ ERR_CASE_OVERFLOW, "Internal Error: Case stack overflow." },
{ ERR_BREAK_OVERFLOW, "Internal Error: Break stack overflow." },
{ ERR_CONTINUE_OVERFLOW, "Internal Error: Continue stack overflow." },
{ ERR_STATEMENT_OVERFLOW, "Internal Error: Statement overflow." },
{ ERR_MISPLACED_BREAK, "Misplaced BREAK statement." },
{ ERR_MISPLACED_CONTINUE, "Misplaced CONTINUE statement." },
{ ERR_CASE_NOT_IN_SWITCH, "CASE must appear in switch statement." },
{ ERR_DEFAULT_NOT_IN_SWITCH, "DEFAULT must appear in switch statement." },
{ ERR_MULTIPLE_DEFAULT, "Only 1 DEFAULT per switch allowed." },
{ ERR_EXPR_STACK_OVERFLOW, "Expression stack overflow." },
{ ERR_EXPR_STACK_EMPTY, "Tried to POP empty expression stack." },
{ ERR_UNKNOWN_CONST_EXPR_PCD, "Unknown PCD in constant expression." },
{ ERR_BAD_RADIX_CONSTANT, "Radix out of range in integer constant." },
{ ERR_BAD_ASSIGNMENT, "Syntax error in multiple assignment statement." },
{ ERR_OUT_OF_MEMORY, "Out of memory." },
{ ERR_TOO_MANY_STRINGS, "Too many strings. Current max is %d" },
{ ERR_UNKNOWN_PRTYPE, "Unknown cast type in print statement." },
{ ERR_SCRIPT_OUT_OF_RANGE, "Script number must be between 1 and 32767." },
{ ERR_MISSING_PARAM, "Missing required argument." },
{ ERR_SCRIPT_ALREADY_DEFINED, "Script already has a body." },
{ ERR_FUNCTION_ALREADY_DEFINED, "Function already has a body." },
{ ERR_PARM_MUST_BE_VAR, "Parameter must be a variable." },
{ ERR_MISSING_FONT_NAME, "Missing font name." },
{ ERR_MISSING_LBRACE_FONTS, "Missing opening '{' in font list." },
{ ERR_MISSING_RBRACE_FONTS, "Missing closing '}' in font list." },
{ ERR_NOCOMPACT_NOT_HERE, "#nocompact must appear before any scripts." },
{ ERR_MISSING_ASSIGN, "Missing '='." },
{ ERR_PREVIOUS_NOT_VOID, "Previous use of function expected a return value." },
{ ERR_MUST_RETURN_A_VALUE, "Function must return a value." },
{ ERR_MUST_NOT_RETURN_A_VALUE, "Void functions cannot return a value." },
{ ERR_SUSPEND_IN_FUNCTION, "Suspend cannot be used inside a function." },
{ ERR_TERMINATE_IN_FUNCTION, "Terminate cannot be used inside a function." },
{ ERR_RESTART_IN_FUNCTION, "Restart cannot be used inside a function." },
{ ERR_RETURN_OUTSIDE_FUNCTION, "Return can only be used inside a function." },
{ ERR_FUNC_ARGUMENT_COUNT, "Function %s should have %d argument%s." },
{ ERR_EOF, "Unexpected end of file." },
{ ERR_UNDEFINED_FUNC, "Function %s is used but not defined." },
{ ERR_TOO_MANY_ARRAY_DIMS, "Too many array dimensions." },
{ ERR_TOO_MANY_ARRAY_INIT, "Too many initializers for array." },
{ ERR_MISSING_LBRACKET, "Missing '['." },
{ ERR_MISSING_RBRACKET, "Missing ']'." },
{ ERR_ZERO_DIMENSION, "Arrays cannot have a dimension of zero." },
{ ERR_TOO_MANY_DIM_USED, "%s only has %d dimensions." },
{ ERR_TOO_FEW_DIM_USED, "%s access needs %d more dimensions." },
{ ERR_ARRAY_MAPVAR_ONLY, "Only map variables can be arrays." },
{ ERR_NOT_AN_ARRAY, "%s is not an array." },
{ ERR_MISSING_LBRACE_ARR, "Missing opening '{' in array initializer." },
{ ERR_MISSING_RBRACE_ARR, "Missing closing '}' in array initializer." },
{ ERR_LATENT_IN_FUNC, "Latent functions cannot be used inside functions." },
{ ERR_LOCAL_VAR_SHADOWED, "A global identifier already has this name." },
{ ERR_MULTIPLE_IMPORTS, "You can only #import one file." },
{ ERR_IMPORT_IN_EXPORT, "You cannot #import from inside an imported file." },
{ ERR_EXPORTER_NOT_FLAGGED, "A file that you #import must have a #library line." },
{ ERR_TOO_MANY_IMPORTS, "Too many files imported." },
{ ERR_NO_NEED_ARRAY_SIZE, "Only map arrays need a size." },
{ ERR_NO_MULTIDIMENSIONS, "Only map arrays can have more than one dimension." },
{ ERR_NEED_ARRAY_SIZE, "Missing array size." },
{ ERR_DISCONNECT_NEEDS_1_ARG, "Disconnect scripts must have 1 argument." },
{ ERR_UNCLOSED_WITH_ARGS, "Most special scripts must not have arguments." },
{ ERR_NOT_A_CHAR_ARRAY, "%s has %d dimensions. Use %d subscripts to get a char array." },
{ ERR_CANT_FIND_INCLUDE, "Couldn't find include file \"%s\"." },
{ ERR_SCRIPT_NAMED_NONE, "Scripts may not be named \"None\"." },
{ ERR_HEXEN_COMPAT, "Attempt to use feature not supported by Hexen." },
{ ERR_NOT_HEXEN, "Cannot save; new features are not compatible with Hexen." },
{ ERR_SPECIAL_RANGE, "Line specials with values higher than 255 require #nocompact." },
{ ERR_EVENT_NEEDS_3_ARG, "Event scripts must have 3 arguments." }, // [BB]
{ ERR_LIBRARY_NOT_FIRST, "#library must come before anything else." },
{ ERR_NONE, NULL }
};
static FILE *ErrorFile;
static int ErrorCount;
static errorInfo_e ErrorFormat;
static char *ErrorSourceName;
static int ErrorSourceLine;
// CODE --------------------------------------------------------------------
//==========================================================================
//
// ERR_ErrorAt
//
//==========================================================================
void ERR_ErrorAt(char *source, int line)
{
ErrorSourceName = source;
ErrorSourceLine = line;
}
//==========================================================================
//
// ERR_Error
//
//==========================================================================
void ERR_Error(error_t error, boolean info, ...)
{
va_list args;
va_start(args, info);
ERR_ErrorV(error, info, args);
va_end(args);
}
//==========================================================================
//
// ERR_Exit
//
//==========================================================================
void ERR_Exit(error_t error, boolean info, ...)
{
va_list args;
va_start(args, info);
ERR_ErrorV(error, info, args);
va_end(args);
ERR_Finish();
}
//==========================================================================
//
// ERR_Finish
//
//==========================================================================
void ERR_Finish(void)
{
if(ErrorFile)
{
fclose(ErrorFile);
ErrorFile = NULL;
}
if(ErrorCount)
{
exit(1);
}
}
//==========================================================================
//
// ShowError
//
//==========================================================================
void ERR_ErrorV(error_t error, boolean info, va_list args)
{
char *text;
boolean showLine = NO;
static boolean showedInfo = NO;
if(!ErrorFile)
{
ErrorFile = fopen(ErrorFileName(), "w");
}
if(ErrorCount == 0)
{
fprintf(stderr, "\n**** ERROR ****\n");
}
else if(ErrorCount == 100)
{
eprintf("More than 100 errors. Can't continue.\n");
ERR_Finish();
}
ErrorCount++;
if(info == YES)
{
char *source;
int line;
if(ErrorSourceName)
{
source = ErrorSourceName;
line = ErrorSourceLine;
ErrorSourceName = NULL;
}
else
{
source = tk_SourceName;
line = tk_Line;
showLine = YES;
}
if(showedInfo == NO)
{ // Output info compatible with older ACCs
// for editors that expect it.
showedInfo = YES;
eprintf("Line %d in file \"%s\" ...\n", line, source);
}
if(ErrorFormat == ERRINFO_GCC)
{
eprintf("%s:%d: ", source, line);
}
else
{
eprintf("%s(%d) : ", source, line);
if(error != ERR_NONE)
{
eprintf("error %04d: ", error);
}
}
}
if(error != ERR_NONE)
{
text = ErrorText(error);
if(text != NULL)
{
veprintf(text, args);
}
eprintf("\n");
if(showLine)
{
// deal with master source line and position indicator - Ty 07jan2000
MasterSourceLine[MasterSourcePos] = '\0'; // pre-incremented already
eprintf("> %s\n", MasterSourceLine); // the string
eprintf(">%*s\n", MasterSourcePos, "^"); // pointer to error
}
}
#if 0
else
{
va_list args2;
va_start(va_arg(args,char*), args2);
veprintf(va_arg(args,char*), args2);
va_end(args2);
}
#endif
}
//==========================================================================
//
// ERR_RemoveErrorFile
//
//==========================================================================
void ERR_RemoveErrorFile(void)
{
remove(ErrorFileName());
}
//==========================================================================
//
// ERR_ErrorFileName
//
//==========================================================================
static char *ErrorFileName(void)
{
static char errFileName[MAX_FILE_NAME_LENGTH];
strcpy(errFileName, acs_SourceFileName);
if(MS_StripFilename(errFileName) == NO)
{
strcpy(errFileName, ERROR_FILE_NAME);
}
else
{
strcat(errFileName, ERROR_FILE_NAME);
}
return errFileName;
}
//==========================================================================
//
// ErrorText
//
//==========================================================================
static char *ErrorText(error_t error)
{
int i;
for(i = 0; ErrorNames[i].number != ERR_NONE; i++)
{
if(error == ErrorNames[i].number)
{
return ErrorNames[i].name;
}
}
return NULL;
}
//==========================================================================
//
// eprintf
//
//==========================================================================
static void eprintf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
veprintf(fmt, args);
va_end(args);
}
//==========================================================================
//
// veprintf
//
//==========================================================================
static void veprintf(const char *fmt, va_list args)
{
#ifdef va_copy
va_list copy;
va_copy(copy, args);
#endif
vfprintf(stderr, fmt, args);
if(ErrorFile)
{
#ifdef va_copy
vfprintf(ErrorFile, fmt, copy);
#else
vfprintf(ErrorFile, fmt, args);
#endif
}
#ifdef va_copy
va_end(copy);
#endif
}

330
error.h
View file

@ -1,165 +1,165 @@
//**************************************************************************
//**
//** error.h
//**
//**************************************************************************
#ifndef __ERROR_H__
#define __ERROR_H__
// HEADER FILES ------------------------------------------------------------
#include <stdarg.h>
#include "common.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
typedef enum
{
ERR_NONE = 0,
ERR_NO_SYMBOL_MEM = 10,
ERR_IDENTIFIER_TOO_LONG,
ERR_STRING_TOO_LONG,
ERR_FILE_NAME_TOO_LONG,
ERR_MISSING_LPAREN,
ERR_MISSING_RPAREN,
ERR_MISSING_SEMICOLON,
ERR_MISSING_SCRIPT_NUMBER,
ERR_ALLOC_PCODE_BUFFER,
ERR_PCODE_BUFFER_OVERFLOW,
ERR_TOO_MANY_SCRIPTS,
ERR_TOO_MANY_FUNCTIONS,
ERR_SAVE_OBJECT_FAILED,
ERR_MISSING_LPAREN_SCR,
ERR_INVALID_IDENTIFIER,
ERR_REDEFINED_IDENTIFIER,
ERR_MISSING_COMMA,
ERR_BAD_VAR_TYPE,
ERR_BAD_RETURN_TYPE,
ERR_TOO_MANY_SCRIPT_ARGS,
ERR_MISSING_LBRACE_SCR,
ERR_MISSING_RBRACE_SCR,
ERR_TOO_MANY_MAP_VARS,
ERR_MISSING_WVAR_INDEX,
ERR_MISSING_GVAR_INDEX,
ERR_BAD_WVAR_INDEX,
ERR_MISSING_WVAR_COLON,
ERR_MISSING_GVAR_COLON,
ERR_MISSING_SPEC_VAL,
ERR_MISSING_SPEC_COLON,
ERR_MISSING_SPEC_ARGC,
ERR_CANT_READ_FILE,
ERR_CANT_OPEN_FILE,
ERR_CANT_OPEN_DBGFILE,
ERR_INVALID_DIRECTIVE,
ERR_BAD_DEFINE,
ERR_INCL_NESTING_TOO_DEEP,
ERR_STRING_LIT_NOT_FOUND,
ERR_TOO_MANY_SCRIPT_VARS,
ERR_TOO_MANY_FUNCTION_VARS,
ERR_TOO_MANY_SCRIPT_ARRAYS,
ERR_TOO_MANY_FUNCTION_ARRAYS,
ERR_INVALID_DECLARATOR,
ERR_BAD_LSPEC_ARG_COUNT,
ERR_BAD_ARG_COUNT,
ERR_UNKNOWN_IDENTIFIER,
ERR_MISSING_COLON,
ERR_BAD_EXPR,
ERR_BAD_CONST_EXPR,
ERR_DIV_BY_ZERO_IN_CONST_EXPR,
ERR_NO_DIRECT_VER,
ERR_ILLEGAL_EXPR_IDENT,
ERR_EXPR_FUNC_NO_RET_VAL,
ERR_MISSING_ASSIGN_OP,
ERR_INCDEC_OP_ON_NON_VAR,
ERR_MISSING_RBRACE,
ERR_INVALID_STATEMENT,
ERR_BAD_DO_STATEMENT,
ERR_BAD_SCRIPT_DECL,
ERR_CASE_OVERFLOW,
ERR_BREAK_OVERFLOW,
ERR_CONTINUE_OVERFLOW,
ERR_STATEMENT_OVERFLOW,
ERR_MISPLACED_BREAK,
ERR_MISPLACED_CONTINUE,
ERR_CASE_NOT_IN_SWITCH,
ERR_DEFAULT_NOT_IN_SWITCH,
ERR_MULTIPLE_DEFAULT,
ERR_EXPR_STACK_OVERFLOW,
ERR_EXPR_STACK_EMPTY,
ERR_UNKNOWN_CONST_EXPR_PCD,
ERR_BAD_RADIX_CONSTANT,
ERR_BAD_ASSIGNMENT,
ERR_OUT_OF_MEMORY,
ERR_TOO_MANY_STRINGS,
ERR_UNKNOWN_PRTYPE,
ERR_BAD_CHARACTER,
ERR_SCRIPT_OUT_OF_RANGE,
ERR_MISSING_PARAM,
ERR_SCRIPT_ALREADY_DEFINED,
ERR_FUNCTION_ALREADY_DEFINED,
ERR_PARM_MUST_BE_VAR,
ERR_MISSING_FONT_NAME,
ERR_MISSING_LBRACE_FONTS,
ERR_MISSING_RBRACE_FONTS,
ERR_NOCOMPACT_NOT_HERE,
ERR_MISSING_ASSIGN,
ERR_MUST_RETURN_A_VALUE,
ERR_MUST_NOT_RETURN_A_VALUE,
ERR_SUSPEND_IN_FUNCTION,
ERR_TERMINATE_IN_FUNCTION,
ERR_RESTART_IN_FUNCTION,
ERR_RETURN_OUTSIDE_FUNCTION,
ERR_PREVIOUS_NOT_VOID,
ERR_MISSING_LBRACE,
ERR_FUNC_ARGUMENT_COUNT,
ERR_UNDEFINED_FUNC,
ERR_TOO_MANY_ARRAY_DIMS,
ERR_MISSING_LBRACKET,
ERR_MISSING_RBRACKET,
ERR_ZERO_DIMENSION,
ERR_TOO_MANY_DIM_USED,
ERR_TOO_FEW_DIM_USED,
ERR_TOO_MANY_ARRAY_INIT,
ERR_EOF,
ERR_ARRAY_MAPVAR_ONLY,
ERR_NOT_AN_ARRAY,
ERR_MISSING_LBRACE_ARR,
ERR_MISSING_RBRACE_ARR,
ERR_LATENT_IN_FUNC,
ERR_LOCAL_VAR_SHADOWED,
ERR_BAD_CHARACTER_CONSTANT,
ERR_MULTIPLE_IMPORTS,
ERR_IMPORT_IN_EXPORT,
ERR_EXPORTER_NOT_FLAGGED,
ERR_TOO_MANY_IMPORTS,
ERR_NO_NEED_ARRAY_SIZE,
ERR_NO_MULTIDIMENSIONS,
ERR_NEED_ARRAY_SIZE,
ERR_DISCONNECT_NEEDS_1_ARG,
ERR_UNCLOSED_WITH_ARGS,
ERR_NOT_A_CHAR_ARRAY,
ERR_CANT_FIND_INCLUDE,
ERR_SCRIPT_NAMED_NONE,
ERR_HEXEN_COMPAT,
ERR_NOT_HEXEN,
ERR_SPECIAL_RANGE,
ERR_EVENT_NEEDS_3_ARG, // [BB]
ERR_LIBRARY_NOT_FIRST,
} error_t;
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void ERR_ErrorAt(char *sourceName, int sourceLine);
void ERR_Error(error_t error, boolean info, ...);
void ERR_ErrorV(error_t error, boolean info, va_list args);
void ERR_Finish(void);
void ERR_Exit(error_t error, boolean info, ...);
void ERR_RemoveErrorFile(void);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
#endif
//**************************************************************************
//**
//** error.h
//**
//**************************************************************************
#ifndef __ERROR_H__
#define __ERROR_H__
// HEADER FILES ------------------------------------------------------------
#include <stdarg.h>
#include "common.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
typedef enum
{
ERR_NONE = 0,
ERR_NO_SYMBOL_MEM = 10,
ERR_IDENTIFIER_TOO_LONG,
ERR_STRING_TOO_LONG,
ERR_FILE_NAME_TOO_LONG,
ERR_MISSING_LPAREN,
ERR_MISSING_RPAREN,
ERR_MISSING_SEMICOLON,
ERR_MISSING_SCRIPT_NUMBER,
ERR_ALLOC_PCODE_BUFFER,
ERR_PCODE_BUFFER_OVERFLOW,
ERR_TOO_MANY_SCRIPTS,
ERR_TOO_MANY_FUNCTIONS,
ERR_SAVE_OBJECT_FAILED,
ERR_MISSING_LPAREN_SCR,
ERR_INVALID_IDENTIFIER,
ERR_REDEFINED_IDENTIFIER,
ERR_MISSING_COMMA,
ERR_BAD_VAR_TYPE,
ERR_BAD_RETURN_TYPE,
ERR_TOO_MANY_SCRIPT_ARGS,
ERR_MISSING_LBRACE_SCR,
ERR_MISSING_RBRACE_SCR,
ERR_TOO_MANY_MAP_VARS,
ERR_MISSING_WVAR_INDEX,
ERR_MISSING_GVAR_INDEX,
ERR_BAD_WVAR_INDEX,
ERR_MISSING_WVAR_COLON,
ERR_MISSING_GVAR_COLON,
ERR_MISSING_SPEC_VAL,
ERR_MISSING_SPEC_COLON,
ERR_MISSING_SPEC_ARGC,
ERR_CANT_READ_FILE,
ERR_CANT_OPEN_FILE,
ERR_CANT_OPEN_DBGFILE,
ERR_INVALID_DIRECTIVE,
ERR_BAD_DEFINE,
ERR_INCL_NESTING_TOO_DEEP,
ERR_STRING_LIT_NOT_FOUND,
ERR_TOO_MANY_SCRIPT_VARS,
ERR_TOO_MANY_FUNCTION_VARS,
ERR_TOO_MANY_SCRIPT_ARRAYS,
ERR_TOO_MANY_FUNCTION_ARRAYS,
ERR_INVALID_DECLARATOR,
ERR_BAD_LSPEC_ARG_COUNT,
ERR_BAD_ARG_COUNT,
ERR_UNKNOWN_IDENTIFIER,
ERR_MISSING_COLON,
ERR_BAD_EXPR,
ERR_BAD_CONST_EXPR,
ERR_DIV_BY_ZERO_IN_CONST_EXPR,
ERR_NO_DIRECT_VER,
ERR_ILLEGAL_EXPR_IDENT,
ERR_EXPR_FUNC_NO_RET_VAL,
ERR_MISSING_ASSIGN_OP,
ERR_INCDEC_OP_ON_NON_VAR,
ERR_MISSING_RBRACE,
ERR_INVALID_STATEMENT,
ERR_BAD_DO_STATEMENT,
ERR_BAD_SCRIPT_DECL,
ERR_CASE_OVERFLOW,
ERR_BREAK_OVERFLOW,
ERR_CONTINUE_OVERFLOW,
ERR_STATEMENT_OVERFLOW,
ERR_MISPLACED_BREAK,
ERR_MISPLACED_CONTINUE,
ERR_CASE_NOT_IN_SWITCH,
ERR_DEFAULT_NOT_IN_SWITCH,
ERR_MULTIPLE_DEFAULT,
ERR_EXPR_STACK_OVERFLOW,
ERR_EXPR_STACK_EMPTY,
ERR_UNKNOWN_CONST_EXPR_PCD,
ERR_BAD_RADIX_CONSTANT,
ERR_BAD_ASSIGNMENT,
ERR_OUT_OF_MEMORY,
ERR_TOO_MANY_STRINGS,
ERR_UNKNOWN_PRTYPE,
ERR_BAD_CHARACTER,
ERR_SCRIPT_OUT_OF_RANGE,
ERR_MISSING_PARAM,
ERR_SCRIPT_ALREADY_DEFINED,
ERR_FUNCTION_ALREADY_DEFINED,
ERR_PARM_MUST_BE_VAR,
ERR_MISSING_FONT_NAME,
ERR_MISSING_LBRACE_FONTS,
ERR_MISSING_RBRACE_FONTS,
ERR_NOCOMPACT_NOT_HERE,
ERR_MISSING_ASSIGN,
ERR_MUST_RETURN_A_VALUE,
ERR_MUST_NOT_RETURN_A_VALUE,
ERR_SUSPEND_IN_FUNCTION,
ERR_TERMINATE_IN_FUNCTION,
ERR_RESTART_IN_FUNCTION,
ERR_RETURN_OUTSIDE_FUNCTION,
ERR_PREVIOUS_NOT_VOID,
ERR_MISSING_LBRACE,
ERR_FUNC_ARGUMENT_COUNT,
ERR_UNDEFINED_FUNC,
ERR_TOO_MANY_ARRAY_DIMS,
ERR_MISSING_LBRACKET,
ERR_MISSING_RBRACKET,
ERR_ZERO_DIMENSION,
ERR_TOO_MANY_DIM_USED,
ERR_TOO_FEW_DIM_USED,
ERR_TOO_MANY_ARRAY_INIT,
ERR_EOF,
ERR_ARRAY_MAPVAR_ONLY,
ERR_NOT_AN_ARRAY,
ERR_MISSING_LBRACE_ARR,
ERR_MISSING_RBRACE_ARR,
ERR_LATENT_IN_FUNC,
ERR_LOCAL_VAR_SHADOWED,
ERR_BAD_CHARACTER_CONSTANT,
ERR_MULTIPLE_IMPORTS,
ERR_IMPORT_IN_EXPORT,
ERR_EXPORTER_NOT_FLAGGED,
ERR_TOO_MANY_IMPORTS,
ERR_NO_NEED_ARRAY_SIZE,
ERR_NO_MULTIDIMENSIONS,
ERR_NEED_ARRAY_SIZE,
ERR_DISCONNECT_NEEDS_1_ARG,
ERR_UNCLOSED_WITH_ARGS,
ERR_NOT_A_CHAR_ARRAY,
ERR_CANT_FIND_INCLUDE,
ERR_SCRIPT_NAMED_NONE,
ERR_HEXEN_COMPAT,
ERR_NOT_HEXEN,
ERR_SPECIAL_RANGE,
ERR_EVENT_NEEDS_3_ARG, // [BB]
ERR_LIBRARY_NOT_FIRST,
} error_t;
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void ERR_ErrorAt(char *sourceName, int sourceLine);
void ERR_Error(error_t error, boolean info, ...);
void ERR_ErrorV(error_t error, boolean info, va_list args);
void ERR_Finish(void);
void ERR_Exit(error_t error, boolean info, ...);
void ERR_RemoveErrorFile(void);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
#endif

816
misc.c
View file

@ -1,408 +1,408 @@
//**************************************************************************
//**
//** misc.c
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#ifdef __NeXT__
#include <libc.h>
#else
#include <fcntl.h>
#include <stdlib.h>
#if !defined(unix) && !defined(__APPLE__)
#include <io.h>
#endif
#endif
#ifdef __GNUC__
#include <sys/stat.h>
#include <unistd.h>
#endif
#ifdef _WIN32
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include "common.h"
#include "misc.h"
#include "error.h"
// MACROS ------------------------------------------------------------------
#ifndef O_BINARY
#define O_BINARY 0
#endif
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern boolean acs_BigEndianHost;
extern boolean acs_VerboseMode;
extern boolean acs_DebugMode;
extern FILE *acs_DebugFile;
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
//==========================================================================
//
// MS_Alloc
//
//==========================================================================
void *MS_Alloc(size_t size, error_t error)
{
void *mem;
if((mem = malloc(size)) == NULL)
{
ERR_Exit(error, NO);
}
return mem;
}
//==========================================================================
//
// MS_Realloc
//
//==========================================================================
void *MS_Realloc(void *base, size_t size, error_t error)
{
void *mem;
if((mem = realloc(base, size)) == NULL)
{
ERR_Exit(error, NO);
}
return mem;
}
//==========================================================================
//
// MS_LittleUWORD
//
// Converts a host U_WORD (2 bytes) to little endian byte order.
//
//==========================================================================
U_WORD MS_LittleUWORD(U_WORD val)
{
if(acs_BigEndianHost == NO)
{
return val;
}
return ((val&255)<<8)+((val>>8)&255);
}
//==========================================================================
//
// MS_LittleUINT
//
// Converts a host U_INT (4 bytes) to little endian byte order.
//
//==========================================================================
U_INT MS_LittleUINT(U_INT val)
{
if(acs_BigEndianHost == NO)
{
return val;
}
return ((val&255)<<24)+(((val>>8)&255)<<16)+(((val>>16)&255)<<8)
+((val>>24)&255);
}
//==========================================================================
//
// MS_LoadFile
//
//==========================================================================
int MS_LoadFile(char *name, char **buffer)
{
int handle;
int size;
int count;
char *addr;
struct stat fileInfo;
if(strlen(name) >= MAX_FILE_NAME_LENGTH)
{
ERR_Exit(ERR_FILE_NAME_TOO_LONG, NO, name);
}
if((handle = open(name, O_RDONLY|O_BINARY, 0666)) == -1)
{
ERR_Exit(ERR_CANT_OPEN_FILE, NO, name);
}
if(fstat(handle, &fileInfo) == -1)
{
ERR_Exit(ERR_CANT_READ_FILE, NO, name);
}
size = fileInfo.st_size;
if((addr = malloc(size)) == NULL)
{
ERR_Exit(ERR_NONE, NO, "Couldn't malloc %d bytes for "
"file \"%s\".", size, name);
}
count = read(handle, addr, size);
close(handle);
if(count < size)
{
ERR_Exit(ERR_CANT_READ_FILE, NO, name);
}
*buffer = addr;
return size;
}
//==========================================================================
//
// MS_FileExists
//
// Pascal 21/11/08
//
//==========================================================================
boolean MS_FileExists(char *name)
{
struct stat info;
int ret = stat(name, &info);
return (ret == 0);
}
//==========================================================================
//
// MS_SaveFile
//
//==========================================================================
boolean MS_SaveFile(char *name, void *buffer, int length)
{
int handle;
int count;
handle = open(name, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
if(handle == -1)
{
return FALSE;
}
count = write(handle, buffer, length);
close(handle);
if(count < length)
{
return FALSE;
}
return TRUE;
}
//==========================================================================
//
// MS_StrCmp
//
//==========================================================================
int MS_StrCmp(char *s1, char *s2)
{
for(; tolower(*s1) == tolower(*s2); s1++, s2++)
{
if(*s1 == '\0')
{
return 0;
}
}
return tolower(*s1)-tolower(*s2);
}
//==========================================================================
//
// MS_StrLwr
//
//==========================================================================
char *MS_StrLwr(char *string)
{
char *c;
c = string;
while(*c)
{
*c = tolower(*c);
c++;
}
return string;
}
//==========================================================================
//
// MS_StrUpr
//
//==========================================================================
char *MS_StrUpr(char *string)
{
char *c;
c = string;
while(*c)
{
*c = toupper(*c);
c++;
}
return string;
}
//==========================================================================
//
// MS_SuggestFileExt
//
//==========================================================================
void MS_SuggestFileExt(char *base, char *extension)
{
char *search;
search = base+strlen(base)-1;
while(!MS_IsDirectoryDelimiter(*search) && search != base)
{
if(*search-- == '.')
{
return;
}
}
strcat(base, extension);
}
//==========================================================================
//
// MS_IsDirectoryDelimiter
//
//==========================================================================
boolean MS_IsDirectoryDelimiter(char foo)
{
#if defined(_WIN32) || defined(__MSDOS__)
return foo == '/' || foo == '\\' || foo == ':';
#else
return foo == '/';
#endif
}
//==========================================================================
//
// MS_StripFileExt
//
//==========================================================================
void MS_StripFileExt(char *name)
{
char *search;
search = name+strlen(name)-1;
while(!MS_IsDirectoryDelimiter(*search) && search != name)
{
if(*search == '.')
{
*search = '\0';
return;
}
search--;
}
}
//==========================================================================
//
// MS_StripFilename
//
// [RH] This now leaves the directory delimiter in place.
//
//==========================================================================
boolean MS_StripFilename(char *name)
{
char *c;
c = name+strlen(name);
do
{
if(--c == name)
{ // No directory delimiter
return NO;
}
} while(!MS_IsDirectoryDelimiter(*c));
*(c+1) = 0;
return YES;
}
//==========================================================================
//
// MS_Message
//
//==========================================================================
void MS_Message(msg_t type, char *text, ...)
{
FILE *fp;
va_list argPtr;
if(type == MSG_VERBOSE && acs_VerboseMode == NO)
{
return;
}
fp = stdout;
if(type == MSG_DEBUG)
{
if(acs_DebugMode == NO)
{
return;
}
if(acs_DebugFile != NULL)
{
fp = acs_DebugFile;
}
}
if(text)
{
va_start(argPtr, text);
vfprintf(fp, text, argPtr);
va_end(argPtr);
}
}
//==========================================================================
//
// MS_IsPathAbsolute
//
// Pascal 30/11/08
//
//==========================================================================
boolean MS_IsPathAbsolute(char *name)
{
#if defined(_WIN32) || defined(__MSDOS__)
// In Windows, the second character must be : if it is an
// absolute path (the first character indicates the drive)
// or the first character is either / or \ for absolute path
if((name[0] != '\0') && (name[1] == ':'))
return TRUE;
#endif
// In Unix-land, the first character must be / for a root path
return MS_IsDirectoryDelimiter(name[0]);
}
//**************************************************************************
//**
//** misc.c
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#ifdef __NeXT__
#include <libc.h>
#else
#include <fcntl.h>
#include <stdlib.h>
#if !defined(unix) && !defined(__APPLE__)
#include <io.h>
#endif
#endif
#ifdef __GNUC__
#include <sys/stat.h>
#include <unistd.h>
#endif
#ifdef _WIN32
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include "common.h"
#include "misc.h"
#include "error.h"
// MACROS ------------------------------------------------------------------
#ifndef O_BINARY
#define O_BINARY 0
#endif
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern boolean acs_BigEndianHost;
extern boolean acs_VerboseMode;
extern boolean acs_DebugMode;
extern FILE *acs_DebugFile;
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
//==========================================================================
//
// MS_Alloc
//
//==========================================================================
void *MS_Alloc(size_t size, error_t error)
{
void *mem;
if((mem = malloc(size)) == NULL)
{
ERR_Exit(error, NO);
}
return mem;
}
//==========================================================================
//
// MS_Realloc
//
//==========================================================================
void *MS_Realloc(void *base, size_t size, error_t error)
{
void *mem;
if((mem = realloc(base, size)) == NULL)
{
ERR_Exit(error, NO);
}
return mem;
}
//==========================================================================
//
// MS_LittleUWORD
//
// Converts a host U_WORD (2 bytes) to little endian byte order.
//
//==========================================================================
U_WORD MS_LittleUWORD(U_WORD val)
{
if(acs_BigEndianHost == NO)
{
return val;
}
return ((val&255)<<8)+((val>>8)&255);
}
//==========================================================================
//
// MS_LittleUINT
//
// Converts a host U_INT (4 bytes) to little endian byte order.
//
//==========================================================================
U_INT MS_LittleUINT(U_INT val)
{
if(acs_BigEndianHost == NO)
{
return val;
}
return ((val&255)<<24)+(((val>>8)&255)<<16)+(((val>>16)&255)<<8)
+((val>>24)&255);
}
//==========================================================================
//
// MS_LoadFile
//
//==========================================================================
int MS_LoadFile(char *name, char **buffer)
{
int handle;
int size;
int count;
char *addr;
struct stat fileInfo;
if(strlen(name) >= MAX_FILE_NAME_LENGTH)
{
ERR_Exit(ERR_FILE_NAME_TOO_LONG, NO, name);
}
if((handle = open(name, O_RDONLY|O_BINARY, 0666)) == -1)
{
ERR_Exit(ERR_CANT_OPEN_FILE, NO, name);
}
if(fstat(handle, &fileInfo) == -1)
{
ERR_Exit(ERR_CANT_READ_FILE, NO, name);
}
size = fileInfo.st_size;
if((addr = malloc(size)) == NULL)
{
ERR_Exit(ERR_NONE, NO, "Couldn't malloc %d bytes for "
"file \"%s\".", size, name);
}
count = read(handle, addr, size);
close(handle);
if(count < size)
{
ERR_Exit(ERR_CANT_READ_FILE, NO, name);
}
*buffer = addr;
return size;
}
//==========================================================================
//
// MS_FileExists
//
// Pascal 21/11/08
//
//==========================================================================
boolean MS_FileExists(char *name)
{
struct stat info;
int ret = stat(name, &info);
return (ret == 0);
}
//==========================================================================
//
// MS_SaveFile
//
//==========================================================================
boolean MS_SaveFile(char *name, void *buffer, int length)
{
int handle;
int count;
handle = open(name, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
if(handle == -1)
{
return FALSE;
}
count = write(handle, buffer, length);
close(handle);
if(count < length)
{
return FALSE;
}
return TRUE;
}
//==========================================================================
//
// MS_StrCmp
//
//==========================================================================
int MS_StrCmp(char *s1, char *s2)
{
for(; tolower(*s1) == tolower(*s2); s1++, s2++)
{
if(*s1 == '\0')
{
return 0;
}
}
return tolower(*s1)-tolower(*s2);
}
//==========================================================================
//
// MS_StrLwr
//
//==========================================================================
char *MS_StrLwr(char *string)
{
char *c;
c = string;
while(*c)
{
*c = tolower(*c);
c++;
}
return string;
}
//==========================================================================
//
// MS_StrUpr
//
//==========================================================================
char *MS_StrUpr(char *string)
{
char *c;
c = string;
while(*c)
{
*c = toupper(*c);
c++;
}
return string;
}
//==========================================================================
//
// MS_SuggestFileExt
//
//==========================================================================
void MS_SuggestFileExt(char *base, char *extension)
{
char *search;
search = base+strlen(base)-1;
while(!MS_IsDirectoryDelimiter(*search) && search != base)
{
if(*search-- == '.')
{
return;
}
}
strcat(base, extension);
}
//==========================================================================
//
// MS_IsDirectoryDelimiter
//
//==========================================================================
boolean MS_IsDirectoryDelimiter(char foo)
{
#if defined(_WIN32) || defined(__MSDOS__)
return foo == '/' || foo == '\\' || foo == ':';
#else
return foo == '/';
#endif
}
//==========================================================================
//
// MS_StripFileExt
//
//==========================================================================
void MS_StripFileExt(char *name)
{
char *search;
search = name+strlen(name)-1;
while(!MS_IsDirectoryDelimiter(*search) && search != name)
{
if(*search == '.')
{
*search = '\0';
return;
}
search--;
}
}
//==========================================================================
//
// MS_StripFilename
//
// [RH] This now leaves the directory delimiter in place.
//
//==========================================================================
boolean MS_StripFilename(char *name)
{
char *c;
c = name+strlen(name);
do
{
if(--c == name)
{ // No directory delimiter
return NO;
}
} while(!MS_IsDirectoryDelimiter(*c));
*(c+1) = 0;
return YES;
}
//==========================================================================
//
// MS_Message
//
//==========================================================================
void MS_Message(msg_t type, char *text, ...)
{
FILE *fp;
va_list argPtr;
if(type == MSG_VERBOSE && acs_VerboseMode == NO)
{
return;
}
fp = stdout;
if(type == MSG_DEBUG)
{
if(acs_DebugMode == NO)
{
return;
}
if(acs_DebugFile != NULL)
{
fp = acs_DebugFile;
}
}
if(text)
{
va_start(argPtr, text);
vfprintf(fp, text, argPtr);
va_end(argPtr);
}
}
//==========================================================================
//
// MS_IsPathAbsolute
//
// Pascal 30/11/08
//
//==========================================================================
boolean MS_IsPathAbsolute(char *name)
{
#if defined(_WIN32) || defined(__MSDOS__)
// In Windows, the second character must be : if it is an
// absolute path (the first character indicates the drive)
// or the first character is either / or \ for absolute path
if((name[0] != '\0') && (name[1] == ':'))
return TRUE;
#endif
// In Unix-land, the first character must be / for a root path
return MS_IsDirectoryDelimiter(name[0]);
}

116
misc.h
View file

@ -1,58 +1,58 @@
//**************************************************************************
//**
//** misc.h
//**
//**************************************************************************
#ifndef __MISC_H__
#define __MISC_H__
// HEADER FILES ------------------------------------------------------------
#include <stddef.h>
#include "error.h"
// MACROS ------------------------------------------------------------------
#ifdef _WIN32
#define strcasecmp stricmp
#endif
// TYPES -------------------------------------------------------------------
typedef enum
{
MSG_NORMAL,
MSG_VERBOSE,
MSG_DEBUG
} msg_t;
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void *MS_Alloc(size_t size, error_t error);
void *MS_Realloc(void *base, size_t size, error_t error);
U_WORD MS_LittleUWORD(U_WORD val);
// U_LONG MS_LittleULONG(U_LONG val);
U_INT MS_LittleUINT(U_INT val);
int MS_LoadFile(char *name, char **buffer);
boolean MS_FileExists(char *name);
boolean MS_SaveFile(char *name, void *buffer, int length);
int MS_StrCmp(char *s1, char *s2);
char *MS_StrLwr(char *string);
char *MS_StrUpr(char *string);
void MS_SuggestFileExt(char *base, char *extension);
void MS_StripFileExt(char *name);
boolean MS_StripFilename(char *path);
void MS_Message(msg_t type, char *text, ...);
boolean MS_IsPathAbsolute(char *name);
boolean MS_IsDirectoryDelimiter(char test);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
#ifdef _MSC_VER
// Get rid of the annoying deprecation warnings with VC++2005 and newer.
#pragma warning(disable:4996)
#endif
#endif
//**************************************************************************
//**
//** misc.h
//**
//**************************************************************************
#ifndef __MISC_H__
#define __MISC_H__
// HEADER FILES ------------------------------------------------------------
#include <stddef.h>
#include "error.h"
// MACROS ------------------------------------------------------------------
#ifdef _WIN32
#define strcasecmp stricmp
#endif
// TYPES -------------------------------------------------------------------
typedef enum
{
MSG_NORMAL,
MSG_VERBOSE,
MSG_DEBUG
} msg_t;
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void *MS_Alloc(size_t size, error_t error);
void *MS_Realloc(void *base, size_t size, error_t error);
U_WORD MS_LittleUWORD(U_WORD val);
// U_LONG MS_LittleULONG(U_LONG val);
U_INT MS_LittleUINT(U_INT val);
int MS_LoadFile(char *name, char **buffer);
boolean MS_FileExists(char *name);
boolean MS_SaveFile(char *name, void *buffer, int length);
int MS_StrCmp(char *s1, char *s2);
char *MS_StrLwr(char *string);
char *MS_StrUpr(char *string);
void MS_SuggestFileExt(char *base, char *extension);
void MS_StripFileExt(char *name);
boolean MS_StripFilename(char *path);
void MS_Message(msg_t type, char *text, ...);
boolean MS_IsPathAbsolute(char *name);
boolean MS_IsDirectoryDelimiter(char test);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
#ifdef _MSC_VER
// Get rid of the annoying deprecation warnings with VC++2005 and newer.
#pragma warning(disable:4996)
#endif
#endif

9690
parse.c

File diff suppressed because it is too large Load diff

82
parse.h
View file

@ -1,41 +1,41 @@
//**************************************************************************
//**
//** parse.h
//**
//**************************************************************************
#ifndef __PARSE_H__
#define __PARSE_H__
// HEADER FILES ------------------------------------------------------------
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
struct ScriptTypes
{
const char *TypeName;
int TypeBase;
int TypeCount;
};
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void PA_Parse(void);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
extern int pa_ScriptCount;
extern struct ScriptTypes *pa_TypedScriptCounts;
extern int pa_MapVarCount;
extern int pa_WorldVarCount;
extern int pa_GlobalVarCount;
extern int pa_WorldArrayCount;
extern int pa_GlobalArrayCount;
extern enum ImportModes ImportMode;
extern boolean ExporterFlagged;
extern boolean pa_ConstExprIsString;
#endif
//**************************************************************************
//**
//** parse.h
//**
//**************************************************************************
#ifndef __PARSE_H__
#define __PARSE_H__
// HEADER FILES ------------------------------------------------------------
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
struct ScriptTypes
{
const char *TypeName;
int TypeBase;
int TypeCount;
};
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void PA_Parse(void);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
extern int pa_ScriptCount;
extern struct ScriptTypes *pa_TypedScriptCounts;
extern int pa_MapVarCount;
extern int pa_WorldVarCount;
extern int pa_GlobalVarCount;
extern int pa_WorldArrayCount;
extern int pa_GlobalArrayCount;
extern enum ImportModes ImportMode;
extern boolean ExporterFlagged;
extern boolean pa_ConstExprIsString;
#endif

3222
pcode.c

File diff suppressed because it is too large Load diff

1006
pcode.h

File diff suppressed because it is too large Load diff

852
strlist.c
View file

@ -1,426 +1,426 @@
//**************************************************************************
//**
//** strlist.c
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include "common.h"
#include "strlist.h"
#include "error.h"
#include "misc.h"
#include "pcode.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
typedef struct
{
char *name;
int address;
} stringInfo_t;
typedef struct
{
int stringCount;
stringInfo_t strings[MAX_STRINGS];
} stringList_t;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static int STR_PutStringInSomeList(stringList_t *list, int index, char *name);
static int STR_FindInSomeList(stringList_t *list, char *name);
static int STR_FindInSomeListInsensitive(stringList_t *list, char *name);
static void DumpStrings(stringList_t *list, int lenadr, boolean quad, boolean crypt);
static void Encrypt(void *data, int key, int len);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
int NumLanguages, NumStringLists;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static stringList_t MainStringList;
static stringList_t *StringLists[NUM_STRLISTS];
// CODE --------------------------------------------------------------------
//==========================================================================
//
// STR_Init
//
//==========================================================================
void STR_Init(void)
{
NumStringLists = 0;
MainStringList.stringCount = 0;
}
//==========================================================================
//
// STR_Get
//
//==========================================================================
char *STR_Get(int num)
{
return MainStringList.strings[num].name;
}
//==========================================================================
//
// STR_Find
//
//==========================================================================
int STR_Find(char *name)
{
return STR_FindInSomeList(&MainStringList, name);
}
//==========================================================================
//
// STR_FindInList
//
//==========================================================================
int STR_FindInList(int list, char *name)
{
if (StringLists[list] == NULL)
{
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0;
NumStringLists++;
if(pc_EnforceHexen)
{
ERR_Error(ERR_HEXEN_COMPAT, YES);
}
}
return STR_FindInSomeList (StringLists[list], name);
}
//==========================================================================
//
// STR_FindInSomeList
//
//==========================================================================
static int STR_FindInSomeList(stringList_t *list, char *name)
{
int i;
for(i = 0; i < list->stringCount; i++)
{
if(strcmp(list->strings[i].name, name) == 0)
{
return i;
}
}
// Add to list
return STR_PutStringInSomeList(list, i, name);
}
//==========================================================================
//
// STR_FindInListInsensitive
//
//==========================================================================
int STR_FindInListInsensitive(int list, char *name)
{
if (StringLists[list] == NULL)
{
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0;
NumStringLists++;
if(pc_EnforceHexen)
{
ERR_Error(ERR_HEXEN_COMPAT, YES);
}
}
return STR_FindInSomeListInsensitive (StringLists[list], name);
}
//==========================================================================
//
// STR_FindInSomeListInsensitive
//
//==========================================================================
static int STR_FindInSomeListInsensitive(stringList_t *list, char *name)
{
int i;
for(i = 0; i < list->stringCount; i++)
{
if(strcasecmp(list->strings[i].name, name) == 0)
{
return i;
}
}
// Add to list
return STR_PutStringInSomeList(list, i, name);
}
//==========================================================================
//
// STR_GetString
//
//==========================================================================
const char *STR_GetString(int list, int index)
{
if (StringLists[list] == NULL)
{
return NULL;
}
if (index < 0 || index >= StringLists[list]->stringCount)
{
return NULL;
}
return StringLists[list]->strings[index].name;
}
//==========================================================================
//
// STR_AppendToList
//
//==========================================================================
int STR_AppendToList(int list, char *name)
{
if (StringLists[list] == NULL)
{
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0;
NumStringLists++;
}
return STR_PutStringInSomeList(StringLists[list], StringLists[list]->stringCount, name);
}
//==========================================================================
//
// STR_PutStringInSomeList
//
//==========================================================================
static int STR_PutStringInSomeList(stringList_t *list, int index, char *name)
{
int i;
if(index >= MAX_STRINGS)
{
ERR_Error(ERR_TOO_MANY_STRINGS, YES, MAX_STRINGS);
return 0;
}
MS_Message(MSG_DEBUG, "Adding string %d:\n \"%s\"\n",
list->stringCount, name);
if(index >= list->stringCount)
{
for(i = list->stringCount; i <= index; i++)
{
list->strings[i].name = NULL;
}
list->stringCount = index + 1;
}
if(list->strings[index].name != NULL)
{
free(list->strings[index].name);
}
if(name != NULL)
{
list->strings[index].name = MS_Alloc(strlen(name)+1, ERR_OUT_OF_MEMORY);
strcpy(list->strings[index].name, name);
}
else
{
list->strings[index].name = NULL;
}
return index;
}
//==========================================================================
//
// STR_ListSize
//
//==========================================================================
int STR_ListSize()
{
return MainStringList.stringCount;
}
//==========================================================================
//
// STR_WriteStrings
//
// Writes all the strings to the p-code buffer.
//
//==========================================================================
void STR_WriteStrings(void)
{
int i;
U_INT pad;
MS_Message(MSG_DEBUG, "---- STR_WriteStrings ----\n");
for(i = 0; i < MainStringList.stringCount; i++)
{
MainStringList.strings[i].address = pc_Address;
PC_AppendString(MainStringList.strings[i].name);
}
if(pc_Address%4 != 0)
{ // Need to align
pad = 0;
PC_Append((void *)&pad, 4-(pc_Address%4));
}
}
//==========================================================================
//
// STR_WriteList
//
//==========================================================================
void STR_WriteList(void)
{
int i;
MS_Message(MSG_DEBUG, "---- STR_WriteList ----\n");
PC_AppendInt((U_INT)MainStringList.stringCount);
for(i = 0; i < MainStringList.stringCount; i++)
{
PC_AppendInt((U_INT)MainStringList.strings[i].address);
}
}
//==========================================================================
//
// STR_WriteChunk
//
//==========================================================================
void STR_WriteChunk(boolean encrypt)
{
int lenadr;
MS_Message(MSG_DEBUG, "---- STR_WriteChunk ----\n");
PC_Append(encrypt ? "STRE" : "STRL", 4);
lenadr = pc_Address;
PC_SkipInt();
PC_AppendInt(0);
PC_AppendInt(MainStringList.stringCount);
PC_AppendInt(0); // Used in-game for stringing lists together (NOT!)
DumpStrings (&MainStringList, lenadr, NO, encrypt);
}
//==========================================================================
//
// STR_WriteListChunk
//
//==========================================================================
void STR_WriteListChunk(int list, int id, boolean quad)
{
int lenadr;
if (StringLists[list] != NULL && StringLists[list]->stringCount > 0)
{
MS_Message(MSG_DEBUG, "---- STR_WriteListChunk %d %c%c%c%c----\n", list,
id&255, (id>>8)&255, (id>>16)&255, (id>>24)&255);
PC_AppendInt((U_INT)id);
lenadr = pc_Address;
PC_SkipInt();
PC_AppendInt(StringLists[list]->stringCount);
if (quad && pc_Address%8 != 0)
{ // If writing quadword indices, align the indices to an
// 8-byte boundary.
U_INT pad = 0;
PC_Append (&pad, 4);
}
DumpStrings(StringLists[list], lenadr, quad, NO);
}
}
//==========================================================================
//
// DumpStrings
//
//==========================================================================
static void DumpStrings(stringList_t *list, int lenadr, boolean quad, boolean crypt)
{
int i, ofs, startofs;
startofs = ofs = pc_Address - lenadr - 4 + list->stringCount*(quad?8:4);
for(i = 0; i < list->stringCount; i++)
{
if (list->strings[i].name != NULL)
{
PC_AppendInt((U_INT)ofs);
ofs += strlen(list->strings[i].name) + 1;
}
else
{
PC_AppendInt(0);
}
if (quad)
{
PC_AppendInt(0);
}
}
ofs = startofs;
for(i = 0; i < list->stringCount; i++)
{
if(list->strings[i].name != NULL)
{
int stringlen = strlen(list->strings[i].name) + 1;
if(crypt)
{
int cryptkey = ofs*157135;
Encrypt(list->strings[i].name, cryptkey, stringlen);
PC_Append(list->strings[i].name, stringlen);
ofs += stringlen;
Encrypt(list->strings[i].name, cryptkey, stringlen);
}
else
{
PC_AppendString(list->strings[i].name);
}
}
}
if(pc_Address%4 != 0)
{ // Need to align
U_INT pad = 0;
PC_Append((void *)&pad, 4-(pc_Address%4));
}
PC_WriteInt(pc_Address - lenadr - 4, lenadr);
}
static void Encrypt(void *data, int key, int len)
{
int p = (byte)key, i;
for(i = 0; i < len; ++i)
{
((byte *)data)[i] ^= (byte)(p+(i>>1));
}
}
//**************************************************************************
//**
//** strlist.c
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include "common.h"
#include "strlist.h"
#include "error.h"
#include "misc.h"
#include "pcode.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
typedef struct
{
char *name;
int address;
} stringInfo_t;
typedef struct
{
int stringCount;
stringInfo_t strings[MAX_STRINGS];
} stringList_t;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static int STR_PutStringInSomeList(stringList_t *list, int index, char *name);
static int STR_FindInSomeList(stringList_t *list, char *name);
static int STR_FindInSomeListInsensitive(stringList_t *list, char *name);
static void DumpStrings(stringList_t *list, int lenadr, boolean quad, boolean crypt);
static void Encrypt(void *data, int key, int len);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
int NumLanguages, NumStringLists;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static stringList_t MainStringList;
static stringList_t *StringLists[NUM_STRLISTS];
// CODE --------------------------------------------------------------------
//==========================================================================
//
// STR_Init
//
//==========================================================================
void STR_Init(void)
{
NumStringLists = 0;
MainStringList.stringCount = 0;
}
//==========================================================================
//
// STR_Get
//
//==========================================================================
char *STR_Get(int num)
{
return MainStringList.strings[num].name;
}
//==========================================================================
//
// STR_Find
//
//==========================================================================
int STR_Find(char *name)
{
return STR_FindInSomeList(&MainStringList, name);
}
//==========================================================================
//
// STR_FindInList
//
//==========================================================================
int STR_FindInList(int list, char *name)
{
if (StringLists[list] == NULL)
{
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0;
NumStringLists++;
if(pc_EnforceHexen)
{
ERR_Error(ERR_HEXEN_COMPAT, YES);
}
}
return STR_FindInSomeList (StringLists[list], name);
}
//==========================================================================
//
// STR_FindInSomeList
//
//==========================================================================
static int STR_FindInSomeList(stringList_t *list, char *name)
{
int i;
for(i = 0; i < list->stringCount; i++)
{
if(strcmp(list->strings[i].name, name) == 0)
{
return i;
}
}
// Add to list
return STR_PutStringInSomeList(list, i, name);
}
//==========================================================================
//
// STR_FindInListInsensitive
//
//==========================================================================
int STR_FindInListInsensitive(int list, char *name)
{
if (StringLists[list] == NULL)
{
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0;
NumStringLists++;
if(pc_EnforceHexen)
{
ERR_Error(ERR_HEXEN_COMPAT, YES);
}
}
return STR_FindInSomeListInsensitive (StringLists[list], name);
}
//==========================================================================
//
// STR_FindInSomeListInsensitive
//
//==========================================================================
static int STR_FindInSomeListInsensitive(stringList_t *list, char *name)
{
int i;
for(i = 0; i < list->stringCount; i++)
{
if(strcasecmp(list->strings[i].name, name) == 0)
{
return i;
}
}
// Add to list
return STR_PutStringInSomeList(list, i, name);
}
//==========================================================================
//
// STR_GetString
//
//==========================================================================
const char *STR_GetString(int list, int index)
{
if (StringLists[list] == NULL)
{
return NULL;
}
if (index < 0 || index >= StringLists[list]->stringCount)
{
return NULL;
}
return StringLists[list]->strings[index].name;
}
//==========================================================================
//
// STR_AppendToList
//
//==========================================================================
int STR_AppendToList(int list, char *name)
{
if (StringLists[list] == NULL)
{
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0;
NumStringLists++;
}
return STR_PutStringInSomeList(StringLists[list], StringLists[list]->stringCount, name);
}
//==========================================================================
//
// STR_PutStringInSomeList
//
//==========================================================================
static int STR_PutStringInSomeList(stringList_t *list, int index, char *name)
{
int i;
if(index >= MAX_STRINGS)
{
ERR_Error(ERR_TOO_MANY_STRINGS, YES, MAX_STRINGS);
return 0;
}
MS_Message(MSG_DEBUG, "Adding string %d:\n \"%s\"\n",
list->stringCount, name);
if(index >= list->stringCount)
{
for(i = list->stringCount; i <= index; i++)
{
list->strings[i].name = NULL;
}
list->stringCount = index + 1;
}
if(list->strings[index].name != NULL)
{
free(list->strings[index].name);
}
if(name != NULL)
{
list->strings[index].name = MS_Alloc(strlen(name)+1, ERR_OUT_OF_MEMORY);
strcpy(list->strings[index].name, name);
}
else
{
list->strings[index].name = NULL;
}
return index;
}
//==========================================================================
//
// STR_ListSize
//
//==========================================================================
int STR_ListSize()
{
return MainStringList.stringCount;
}
//==========================================================================
//
// STR_WriteStrings
//
// Writes all the strings to the p-code buffer.
//
//==========================================================================
void STR_WriteStrings(void)
{
int i;
U_INT pad;
MS_Message(MSG_DEBUG, "---- STR_WriteStrings ----\n");
for(i = 0; i < MainStringList.stringCount; i++)
{
MainStringList.strings[i].address = pc_Address;
PC_AppendString(MainStringList.strings[i].name);
}
if(pc_Address%4 != 0)
{ // Need to align
pad = 0;
PC_Append((void *)&pad, 4-(pc_Address%4));
}
}
//==========================================================================
//
// STR_WriteList
//
//==========================================================================
void STR_WriteList(void)
{
int i;
MS_Message(MSG_DEBUG, "---- STR_WriteList ----\n");
PC_AppendInt((U_INT)MainStringList.stringCount);
for(i = 0; i < MainStringList.stringCount; i++)
{
PC_AppendInt((U_INT)MainStringList.strings[i].address);
}
}
//==========================================================================
//
// STR_WriteChunk
//
//==========================================================================
void STR_WriteChunk(boolean encrypt)
{
int lenadr;
MS_Message(MSG_DEBUG, "---- STR_WriteChunk ----\n");
PC_Append(encrypt ? "STRE" : "STRL", 4);
lenadr = pc_Address;
PC_SkipInt();
PC_AppendInt(0);
PC_AppendInt(MainStringList.stringCount);
PC_AppendInt(0); // Used in-game for stringing lists together (NOT!)
DumpStrings (&MainStringList, lenadr, NO, encrypt);
}
//==========================================================================
//
// STR_WriteListChunk
//
//==========================================================================
void STR_WriteListChunk(int list, int id, boolean quad)
{
int lenadr;
if (StringLists[list] != NULL && StringLists[list]->stringCount > 0)
{
MS_Message(MSG_DEBUG, "---- STR_WriteListChunk %d %c%c%c%c----\n", list,
id&255, (id>>8)&255, (id>>16)&255, (id>>24)&255);
PC_AppendInt((U_INT)id);
lenadr = pc_Address;
PC_SkipInt();
PC_AppendInt(StringLists[list]->stringCount);
if (quad && pc_Address%8 != 0)
{ // If writing quadword indices, align the indices to an
// 8-byte boundary.
U_INT pad = 0;
PC_Append (&pad, 4);
}
DumpStrings(StringLists[list], lenadr, quad, NO);
}
}
//==========================================================================
//
// DumpStrings
//
//==========================================================================
static void DumpStrings(stringList_t *list, int lenadr, boolean quad, boolean crypt)
{
int i, ofs, startofs;
startofs = ofs = pc_Address - lenadr - 4 + list->stringCount*(quad?8:4);
for(i = 0; i < list->stringCount; i++)
{
if (list->strings[i].name != NULL)
{
PC_AppendInt((U_INT)ofs);
ofs += strlen(list->strings[i].name) + 1;
}
else
{
PC_AppendInt(0);
}
if (quad)
{
PC_AppendInt(0);
}
}
ofs = startofs;
for(i = 0; i < list->stringCount; i++)
{
if(list->strings[i].name != NULL)
{
int stringlen = strlen(list->strings[i].name) + 1;
if(crypt)
{
int cryptkey = ofs*157135;
Encrypt(list->strings[i].name, cryptkey, stringlen);
PC_Append(list->strings[i].name, stringlen);
ofs += stringlen;
Encrypt(list->strings[i].name, cryptkey, stringlen);
}
else
{
PC_AppendString(list->strings[i].name);
}
}
}
if(pc_Address%4 != 0)
{ // Need to align
U_INT pad = 0;
PC_Append((void *)&pad, 4-(pc_Address%4));
}
PC_WriteInt(pc_Address - lenadr - 4, lenadr);
}
static void Encrypt(void *data, int key, int len)
{
int p = (byte)key, i;
for(i = 0; i < len; ++i)
{
((byte *)data)[i] ^= (byte)(p+(i>>1));
}
}

View file

@ -1,38 +1,38 @@
//**************************************************************************
//**
//** strlist.h
//**
//**************************************************************************
#ifndef __STRLIST_H__
#define __STRLIST_H__
// HEADER FILES ------------------------------------------------------------
#include "common.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void STR_Init(void);
int STR_Find(char *name);
char *STR_Get(int index);
void STR_WriteStrings(void);
void STR_WriteList(void);
int STR_FindInList(int list, char *name);
int STR_FindInListInsensitive(int list, char *name);
int STR_AppendToList(int list, char *name);
const char *STR_GetString(int list, int index);
void STR_WriteChunk(boolean encrypt);
void STR_WriteListChunk(int list, int id, boolean quad);
int STR_ListSize();
// PUBLIC DATA DECLARATIONS ------------------------------------------------
extern int NumStringLists;
#endif
//**************************************************************************
//**
//** strlist.h
//**
//**************************************************************************
#ifndef __STRLIST_H__
#define __STRLIST_H__
// HEADER FILES ------------------------------------------------------------
#include "common.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void STR_Init(void);
int STR_Find(char *name);
char *STR_Get(int index);
void STR_WriteStrings(void);
void STR_WriteList(void);
int STR_FindInList(int list, char *name);
int STR_FindInListInsensitive(int list, char *name);
int STR_AppendToList(int list, char *name);
const char *STR_GetString(int list, int index);
void STR_WriteChunk(boolean encrypt);
void STR_WriteListChunk(int list, int id, boolean quad);
int STR_ListSize();
// PUBLIC DATA DECLARATIONS ------------------------------------------------
extern int NumStringLists;
#endif

1214
symbol.c

File diff suppressed because it is too large Load diff

262
symbol.h
View file

@ -1,131 +1,131 @@
//**************************************************************************
//**
//** symbol.h
//**
//**************************************************************************
#ifndef __SYMBOL_H__
#define __SYMBOL_H__
// HEADER FILES ------------------------------------------------------------
#include "common.h"
#include "pcode.h"
// MACROS ------------------------------------------------------------------
#define MAX_ARRAY_DIMS 8
// TYPES -------------------------------------------------------------------
typedef enum
{
SY_DUMMY,
SY_LABEL,
SY_SCRIPTVAR,
SY_SCRIPTALIAS,
SY_MAPVAR,
SY_WORLDVAR,
SY_GLOBALVAR,
SY_SCRIPTARRAY,
SY_MAPARRAY,
SY_WORLDARRAY,
SY_GLOBALARRAY,
SY_SPECIAL,
SY_CONSTANT,
SY_INTERNFUNC,
SY_SCRIPTFUNC
} symbolType_t;
typedef struct
{
U_BYTE index;
} symVar_t;
typedef struct
{
U_BYTE index;
int dimensions[MAX_ARRAY_DIMS];
int ndim;
int size;
} symArray_t;
typedef struct
{
int address;
} symLabel_t;
typedef struct
{
int value;
int argCount;
} symSpecial_t;
typedef struct
{
int value;
char *strValue;
int fileDepth;
} symConstant_t;
typedef struct
{
pcd_t directCommand;
pcd_t stackCommand;
int argCount;
int optMask;
int outMask;
boolean hasReturnValue;
boolean latent;
} symInternFunc_t;
typedef struct
{
int address;
int argCount;
int varCount;
int funcNumber;
boolean hasReturnValue;
int sourceLine;
char *sourceName;
boolean predefined;
} symScriptFunc_t;
typedef struct symbolNode_s
{
struct symbolNode_s *left;
struct symbolNode_s *right;
char *name;
symbolType_t type;
boolean unused;
boolean imported;
union
{
symVar_t var;
symArray_t array;
symLabel_t label;
symSpecial_t special;
symConstant_t constant;
symInternFunc_t internFunc;
symScriptFunc_t scriptFunc;
} info;
} symbolNode_t;
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void SY_Init(void);
symbolNode_t *SY_Find(char *name);
symbolNode_t *SY_FindLocal(char *name);
symbolNode_t *SY_FindGlobal(char *name);
symbolNode_t *SY_InsertLocal(char *name, symbolType_t type);
symbolNode_t *SY_InsertGlobal(char *name, symbolType_t type);
symbolNode_t *SY_InsertGlobalUnique(char *name, symbolType_t type);
void SY_FreeLocals(void);
void SY_FreeGlobals(void);
void SY_FreeConstants(int depth);
void SY_ClearShared(void);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
#endif
//**************************************************************************
//**
//** symbol.h
//**
//**************************************************************************
#ifndef __SYMBOL_H__
#define __SYMBOL_H__
// HEADER FILES ------------------------------------------------------------
#include "common.h"
#include "pcode.h"
// MACROS ------------------------------------------------------------------
#define MAX_ARRAY_DIMS 8
// TYPES -------------------------------------------------------------------
typedef enum
{
SY_DUMMY,
SY_LABEL,
SY_SCRIPTVAR,
SY_SCRIPTALIAS,
SY_MAPVAR,
SY_WORLDVAR,
SY_GLOBALVAR,
SY_SCRIPTARRAY,
SY_MAPARRAY,
SY_WORLDARRAY,
SY_GLOBALARRAY,
SY_SPECIAL,
SY_CONSTANT,
SY_INTERNFUNC,
SY_SCRIPTFUNC
} symbolType_t;
typedef struct
{
U_BYTE index;
} symVar_t;
typedef struct
{
U_BYTE index;
int dimensions[MAX_ARRAY_DIMS];
int ndim;
int size;
} symArray_t;
typedef struct
{
int address;
} symLabel_t;
typedef struct
{
int value;
int argCount;
} symSpecial_t;
typedef struct
{
int value;
char *strValue;
int fileDepth;
} symConstant_t;
typedef struct
{
pcd_t directCommand;
pcd_t stackCommand;
int argCount;
int optMask;
int outMask;
boolean hasReturnValue;
boolean latent;
} symInternFunc_t;
typedef struct
{
int address;
int argCount;
int varCount;
int funcNumber;
boolean hasReturnValue;
int sourceLine;
char *sourceName;
boolean predefined;
} symScriptFunc_t;
typedef struct symbolNode_s
{
struct symbolNode_s *left;
struct symbolNode_s *right;
char *name;
symbolType_t type;
boolean unused;
boolean imported;
union
{
symVar_t var;
symArray_t array;
symLabel_t label;
symSpecial_t special;
symConstant_t constant;
symInternFunc_t internFunc;
symScriptFunc_t scriptFunc;
} info;
} symbolNode_t;
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void SY_Init(void);
symbolNode_t *SY_Find(char *name);
symbolNode_t *SY_FindLocal(char *name);
symbolNode_t *SY_FindGlobal(char *name);
symbolNode_t *SY_InsertLocal(char *name, symbolType_t type);
symbolNode_t *SY_InsertGlobal(char *name, symbolType_t type);
symbolNode_t *SY_InsertGlobalUnique(char *name, symbolType_t type);
void SY_FreeLocals(void);
void SY_FreeGlobals(void);
void SY_FreeConstants(int depth);
void SY_ClearShared(void);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
#endif

3172
token.c

File diff suppressed because it is too large Load diff

358
token.h
View file

@ -1,179 +1,179 @@
//**************************************************************************
//**
//** token.h
//**
//**************************************************************************
#ifndef __TOKEN_H__
#define __TOKEN_H__
// HEADER FILES ------------------------------------------------------------
#include "common.h"
#include "error.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
typedef enum
{
TK_NONE,
TK_EOF,
TK_IDENTIFIER, // VALUE: (char *) tk_String
TK_STRING, // VALUE: (char *) tk_String
TK_NUMBER, // VALUE: (int) tk_Number
TK_LINESPECIAL, // VALUE: (int) tk_LineSpecial
TK_PLUS, // '+'
TK_MINUS, // '-'
TK_ASTERISK, // '*'
TK_SLASH, // '/'
TK_PERCENT, // '%'
TK_ASSIGN, // '='
TK_ADDASSIGN, // '+='
TK_SUBASSIGN, // '-='
TK_MULASSIGN, // '*='
TK_DIVASSIGN, // '/='
TK_MODASSIGN, // '%='
TK_INC, // '++'
TK_DEC, // '--'
TK_EQ, // '=='
TK_NE, // '!='
TK_LT, // '<'
TK_GT, // '>'
TK_LE, // '<='
TK_GE, // '>='
TK_LSHIFT, // '<<'
TK_RSHIFT, // '>>'
TK_ANDLOGICAL, // '&&'
TK_ORLOGICAL, // '||'
TK_ANDBITWISE, // '&'
TK_ORBITWISE, // '|'
TK_EORBITWISE, // '^'
TK_TILDE, // '~'
TK_LPAREN, // '('
TK_RPAREN, // ')'
TK_LBRACE, // '{'
TK_RBRACE, // '}'
TK_LBRACKET, // '['
TK_RBRACKET, // ']'
TK_TERNARY, // '?'
TK_COLON, // ':'
TK_SEMICOLON, // ';'
TK_COMMA, // ','
TK_PERIOD, // '.'
TK_NOT, // '!'
TK_NUMBERSIGN, // '#'
TK_CPPCOMMENT, // '//'
TK_STARTCOMMENT, // '/*'
TK_ENDCOMMENT, // '*/'
TK_BREAK, // 'break'
TK_CASE, // 'case'
TK_CONST, // 'const'
TK_CONTINUE, // 'continue'
TK_DEFAULT, // 'default'
TK_DEFINE, // 'define'
TK_DO, // 'do'
TK_ELSE, // 'else'
TK_FOR, // 'for'
TK_GOTO, // 'goto'
TK_IF, // 'if'
TK_INCLUDE, // 'include'
TK_INT, // 'int'
TK_OPEN, // 'open'
TK_PRINT, // 'print'
TK_PRINTBOLD, // 'printbold'
TK_LOG, // 'log'
TK_HUDMESSAGE, // 'hudmessage'
TK_HUDMESSAGEBOLD, // 'hudmessagebold'
TK_RESTART, // 'restart'
TK_SCRIPT, // 'script'
TK_SPECIAL, // 'special'
TK_STR, // 'str'
TK_SUSPEND, // 'suspend'
TK_SWITCH, // 'switch'
TK_TERMINATE, // 'terminate'
TK_UNTIL, // 'until'
TK_VOID, // 'void'
TK_WHILE, // 'while'
TK_WORLD, // 'world'
TK_GLOBAL, // 'global'
TK_RESPAWN, // 'respawn' [BC]
TK_DEATH, // 'death' [BC]
TK_ENTER, // 'enter' [BC]
TK_PICKUP, // 'pickup' [BC]
TK_BLUERETURN, // 'bluereturn' [BC]
TK_REDRETURN, // 'redreturn' [BC]
TK_WHITERETURN, // 'whitereturn' [BC]
TK_NOCOMPACT, // 'nocompact'
TK_LIGHTNING, // 'ligtning'
TK_CREATETRANSLATION,// 'createtranslation'
TK_FUNCTION, // 'function'
TK_RETURN, // 'return'
TK_WADAUTHOR, // 'wadauthor'
TK_NOWADAUTHOR, // 'nowadauthor'
TK_ACSEXECUTEWAIT, // 'acs_executewait'
TK_ACSNAMEDEXECUTEWAIT,// 'acs_namedexecutewait'
TK_ENCRYPTSTRINGS, // 'encryptstrings'
TK_IMPORT, // 'import'
TK_LIBRARY, // 'library'
TK_LIBDEFINE, // 'libdefine'
TK_BOOL, // 'bool'
TK_NET, // 'net'
TK_CLIENTSIDE, // 'clientside'
TK_DISCONNECT, // 'disconnect'
TK_EVENT, // 'event' [BB]
TK_UNLOADING, // 'unloading'
TK_STATIC, // 'static'
TK_ANDASSIGN, // '&='
TK_ORASSIGN, // '|='
TK_EORASSIGN, // '^='
TK_LSASSIGN, // '<<='
TK_RSASSIGN, // '>>='
TK_STRPARAM_EVAL, // 'strparam'
TK_STRCPY, // 'strcpy'
TK_REGION, // 'region' [mxd]
TK_ENDREGION, // 'endregion' [mxd]
TK_KILL, // 'kill' [JM]
TK_REOPEN, // 'reopen' [Nash]
TK_ATSIGN, // '@'
TK_MORPHACTOR, // 'morphactor' [Dasperal]
} tokenType_t;
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void TK_Init(void);
void TK_OpenSource(char *fileName);
void TK_Include(char *fileName);
void TK_Import(char *fileName, enum ImportModes prevMode);
void TK_CloseSource(void);
int TK_GetDepth(void);
tokenType_t TK_NextToken(void);
int TK_NextCharacter(void);
boolean TK_NextTokenMustBe(tokenType_t token, error_t error);
boolean TK_TokenMustBe(tokenType_t token, error_t error);
boolean TK_Member(tokenType_t *list);
void TK_Undo(void);
void TK_SkipLine(void);
void TK_SkipPast(tokenType_t token);
void TK_SkipTo(tokenType_t token);
void TK_AddIncludePath(char *sourceName);
void TK_AddProgramIncludePath(char *argv0);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
extern tokenType_t tk_Token;
extern int tk_Line;
extern int tk_Number;
extern char *tk_String;
extern int tk_SpecialValue;
extern int tk_SpecialArgCount;
extern char *tk_SourceName;
extern int tk_IncludedLines;
extern boolean forSemicolonHack;
extern char MasterSourceLine[]; // master line - Ty 07jan2000
extern int MasterSourcePos; // master position - Ty 07jan2000
extern boolean ClearMasterSourceLine; // ready for new line - Ty 07jan2000
#endif
//**************************************************************************
//**
//** token.h
//**
//**************************************************************************
#ifndef __TOKEN_H__
#define __TOKEN_H__
// HEADER FILES ------------------------------------------------------------
#include "common.h"
#include "error.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
typedef enum
{
TK_NONE,
TK_EOF,
TK_IDENTIFIER, // VALUE: (char *) tk_String
TK_STRING, // VALUE: (char *) tk_String
TK_NUMBER, // VALUE: (int) tk_Number
TK_LINESPECIAL, // VALUE: (int) tk_LineSpecial
TK_PLUS, // '+'
TK_MINUS, // '-'
TK_ASTERISK, // '*'
TK_SLASH, // '/'
TK_PERCENT, // '%'
TK_ASSIGN, // '='
TK_ADDASSIGN, // '+='
TK_SUBASSIGN, // '-='
TK_MULASSIGN, // '*='
TK_DIVASSIGN, // '/='
TK_MODASSIGN, // '%='
TK_INC, // '++'
TK_DEC, // '--'
TK_EQ, // '=='
TK_NE, // '!='
TK_LT, // '<'
TK_GT, // '>'
TK_LE, // '<='
TK_GE, // '>='
TK_LSHIFT, // '<<'
TK_RSHIFT, // '>>'
TK_ANDLOGICAL, // '&&'
TK_ORLOGICAL, // '||'
TK_ANDBITWISE, // '&'
TK_ORBITWISE, // '|'
TK_EORBITWISE, // '^'
TK_TILDE, // '~'
TK_LPAREN, // '('
TK_RPAREN, // ')'
TK_LBRACE, // '{'
TK_RBRACE, // '}'
TK_LBRACKET, // '['
TK_RBRACKET, // ']'
TK_TERNARY, // '?'
TK_COLON, // ':'
TK_SEMICOLON, // ';'
TK_COMMA, // ','
TK_PERIOD, // '.'
TK_NOT, // '!'
TK_NUMBERSIGN, // '#'
TK_CPPCOMMENT, // '//'
TK_STARTCOMMENT, // '/*'
TK_ENDCOMMENT, // '*/'
TK_BREAK, // 'break'
TK_CASE, // 'case'
TK_CONST, // 'const'
TK_CONTINUE, // 'continue'
TK_DEFAULT, // 'default'
TK_DEFINE, // 'define'
TK_DO, // 'do'
TK_ELSE, // 'else'
TK_FOR, // 'for'
TK_GOTO, // 'goto'
TK_IF, // 'if'
TK_INCLUDE, // 'include'
TK_INT, // 'int'
TK_OPEN, // 'open'
TK_PRINT, // 'print'
TK_PRINTBOLD, // 'printbold'
TK_LOG, // 'log'
TK_HUDMESSAGE, // 'hudmessage'
TK_HUDMESSAGEBOLD, // 'hudmessagebold'
TK_RESTART, // 'restart'
TK_SCRIPT, // 'script'
TK_SPECIAL, // 'special'
TK_STR, // 'str'
TK_SUSPEND, // 'suspend'
TK_SWITCH, // 'switch'
TK_TERMINATE, // 'terminate'
TK_UNTIL, // 'until'
TK_VOID, // 'void'
TK_WHILE, // 'while'
TK_WORLD, // 'world'
TK_GLOBAL, // 'global'
TK_RESPAWN, // 'respawn' [BC]
TK_DEATH, // 'death' [BC]
TK_ENTER, // 'enter' [BC]
TK_PICKUP, // 'pickup' [BC]
TK_BLUERETURN, // 'bluereturn' [BC]
TK_REDRETURN, // 'redreturn' [BC]
TK_WHITERETURN, // 'whitereturn' [BC]
TK_NOCOMPACT, // 'nocompact'
TK_LIGHTNING, // 'ligtning'
TK_CREATETRANSLATION,// 'createtranslation'
TK_FUNCTION, // 'function'
TK_RETURN, // 'return'
TK_WADAUTHOR, // 'wadauthor'
TK_NOWADAUTHOR, // 'nowadauthor'
TK_ACSEXECUTEWAIT, // 'acs_executewait'
TK_ACSNAMEDEXECUTEWAIT,// 'acs_namedexecutewait'
TK_ENCRYPTSTRINGS, // 'encryptstrings'
TK_IMPORT, // 'import'
TK_LIBRARY, // 'library'
TK_LIBDEFINE, // 'libdefine'
TK_BOOL, // 'bool'
TK_NET, // 'net'
TK_CLIENTSIDE, // 'clientside'
TK_DISCONNECT, // 'disconnect'
TK_EVENT, // 'event' [BB]
TK_UNLOADING, // 'unloading'
TK_STATIC, // 'static'
TK_ANDASSIGN, // '&='
TK_ORASSIGN, // '|='
TK_EORASSIGN, // '^='
TK_LSASSIGN, // '<<='
TK_RSASSIGN, // '>>='
TK_STRPARAM_EVAL, // 'strparam'
TK_STRCPY, // 'strcpy'
TK_REGION, // 'region' [mxd]
TK_ENDREGION, // 'endregion' [mxd]
TK_KILL, // 'kill' [JM]
TK_REOPEN, // 'reopen' [Nash]
TK_ATSIGN, // '@'
TK_MORPHACTOR, // 'morphactor' [Dasperal]
} tokenType_t;
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void TK_Init(void);
void TK_OpenSource(char *fileName);
void TK_Include(char *fileName);
void TK_Import(char *fileName, enum ImportModes prevMode);
void TK_CloseSource(void);
int TK_GetDepth(void);
tokenType_t TK_NextToken(void);
int TK_NextCharacter(void);
boolean TK_NextTokenMustBe(tokenType_t token, error_t error);
boolean TK_TokenMustBe(tokenType_t token, error_t error);
boolean TK_Member(tokenType_t *list);
void TK_Undo(void);
void TK_SkipLine(void);
void TK_SkipPast(tokenType_t token);
void TK_SkipTo(tokenType_t token);
void TK_AddIncludePath(char *sourceName);
void TK_AddProgramIncludePath(char *argv0);
// PUBLIC DATA DECLARATIONS ------------------------------------------------
extern tokenType_t tk_Token;
extern int tk_Line;
extern int tk_Number;
extern char *tk_String;
extern int tk_SpecialValue;
extern int tk_SpecialArgCount;
extern char *tk_SourceName;
extern int tk_IncludedLines;
extern boolean forSemicolonHack;
extern char MasterSourceLine[]; // master line - Ty 07jan2000
extern int MasterSourcePos; // master position - Ty 07jan2000
extern boolean ClearMasterSourceLine; // ready for new line - Ty 07jan2000
#endif

View file

@ -1,15 +1,15 @@
//**************************************************************************
//**
//** zcommon.acs
//**
//**************************************************************************
// If you are not using the -h command line switch and do not want to use
// WadAuthor's error checker, you can uncomment the following line to shave
// a few bytes off the size of compiled scripts.
//#nowadauthor
#include "zspecial.acs"
#include "zdefs.acs"
#include "zwvars.acs"
//**************************************************************************
//**
//** zcommon.acs
//**
//**************************************************************************
// If you are not using the -h command line switch and do not want to use
// WadAuthor's error checker, you can uncomment the following line to shave
// a few bytes off the size of compiled scripts.
//#nowadauthor
#include "zspecial.acs"
#include "zdefs.acs"
#include "zwvars.acs"

View file

@ -1,8 +1,8 @@
//**************************************************************************
//**
//** zwvars.acs
//**
//**************************************************************************
// include your world-variable declarations here.
//**************************************************************************
//**
//** zwvars.acs
//**
//**************************************************************************
// include your world-variable declarations here.