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

870
error.c
View file

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

330
error.h
View file

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

816
misc.c
View file

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

116
misc.h
View file

@ -1,58 +1,58 @@
//************************************************************************** //**************************************************************************
//** //**
//** misc.h //** misc.h
//** //**
//************************************************************************** //**************************************************************************
#ifndef __MISC_H__ #ifndef __MISC_H__
#define __MISC_H__ #define __MISC_H__
// HEADER FILES ------------------------------------------------------------ // HEADER FILES ------------------------------------------------------------
#include <stddef.h> #include <stddef.h>
#include "error.h" #include "error.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
#ifdef _WIN32 #ifdef _WIN32
#define strcasecmp stricmp #define strcasecmp stricmp
#endif #endif
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
typedef enum typedef enum
{ {
MSG_NORMAL, MSG_NORMAL,
MSG_VERBOSE, MSG_VERBOSE,
MSG_DEBUG MSG_DEBUG
} msg_t; } msg_t;
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void *MS_Alloc(size_t size, error_t error); void *MS_Alloc(size_t size, error_t error);
void *MS_Realloc(void *base, 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_WORD MS_LittleUWORD(U_WORD val);
// U_LONG MS_LittleULONG(U_LONG val); // U_LONG MS_LittleULONG(U_LONG val);
U_INT MS_LittleUINT(U_INT val); U_INT MS_LittleUINT(U_INT val);
int MS_LoadFile(char *name, char **buffer); int MS_LoadFile(char *name, char **buffer);
boolean MS_FileExists(char *name); boolean MS_FileExists(char *name);
boolean MS_SaveFile(char *name, void *buffer, int length); boolean MS_SaveFile(char *name, void *buffer, int length);
int MS_StrCmp(char *s1, char *s2); int MS_StrCmp(char *s1, char *s2);
char *MS_StrLwr(char *string); char *MS_StrLwr(char *string);
char *MS_StrUpr(char *string); char *MS_StrUpr(char *string);
void MS_SuggestFileExt(char *base, char *extension); void MS_SuggestFileExt(char *base, char *extension);
void MS_StripFileExt(char *name); void MS_StripFileExt(char *name);
boolean MS_StripFilename(char *path); boolean MS_StripFilename(char *path);
void MS_Message(msg_t type, char *text, ...); void MS_Message(msg_t type, char *text, ...);
boolean MS_IsPathAbsolute(char *name); boolean MS_IsPathAbsolute(char *name);
boolean MS_IsDirectoryDelimiter(char test); boolean MS_IsDirectoryDelimiter(char test);
// PUBLIC DATA DECLARATIONS ------------------------------------------------ // PUBLIC DATA DECLARATIONS ------------------------------------------------
#ifdef _MSC_VER #ifdef _MSC_VER
// Get rid of the annoying deprecation warnings with VC++2005 and newer. // Get rid of the annoying deprecation warnings with VC++2005 and newer.
#pragma warning(disable:4996) #pragma warning(disable:4996)
#endif #endif
#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 //** parse.h
//** //**
//************************************************************************** //**************************************************************************
#ifndef __PARSE_H__ #ifndef __PARSE_H__
#define __PARSE_H__ #define __PARSE_H__
// HEADER FILES ------------------------------------------------------------ // HEADER FILES ------------------------------------------------------------
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
struct ScriptTypes struct ScriptTypes
{ {
const char *TypeName; const char *TypeName;
int TypeBase; int TypeBase;
int TypeCount; int TypeCount;
}; };
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void PA_Parse(void); void PA_Parse(void);
// PUBLIC DATA DECLARATIONS ------------------------------------------------ // PUBLIC DATA DECLARATIONS ------------------------------------------------
extern int pa_ScriptCount; extern int pa_ScriptCount;
extern struct ScriptTypes *pa_TypedScriptCounts; extern struct ScriptTypes *pa_TypedScriptCounts;
extern int pa_MapVarCount; extern int pa_MapVarCount;
extern int pa_WorldVarCount; extern int pa_WorldVarCount;
extern int pa_GlobalVarCount; extern int pa_GlobalVarCount;
extern int pa_WorldArrayCount; extern int pa_WorldArrayCount;
extern int pa_GlobalArrayCount; extern int pa_GlobalArrayCount;
extern enum ImportModes ImportMode; extern enum ImportModes ImportMode;
extern boolean ExporterFlagged; extern boolean ExporterFlagged;
extern boolean pa_ConstExprIsString; extern boolean pa_ConstExprIsString;
#endif #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 //** strlist.c
//** //**
//************************************************************************** //**************************************************************************
// HEADER FILES ------------------------------------------------------------ // HEADER FILES ------------------------------------------------------------
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "common.h" #include "common.h"
#include "strlist.h" #include "strlist.h"
#include "error.h" #include "error.h"
#include "misc.h" #include "misc.h"
#include "pcode.h" #include "pcode.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
typedef struct typedef struct
{ {
char *name; char *name;
int address; int address;
} stringInfo_t; } stringInfo_t;
typedef struct typedef struct
{ {
int stringCount; int stringCount;
stringInfo_t strings[MAX_STRINGS]; stringInfo_t strings[MAX_STRINGS];
} stringList_t; } stringList_t;
// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static int STR_PutStringInSomeList(stringList_t *list, int index, char *name); static int STR_PutStringInSomeList(stringList_t *list, int index, char *name);
static int STR_FindInSomeList(stringList_t *list, char *name); static int STR_FindInSomeList(stringList_t *list, char *name);
static int STR_FindInSomeListInsensitive(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 DumpStrings(stringList_t *list, int lenadr, boolean quad, boolean crypt);
static void Encrypt(void *data, int key, int len); static void Encrypt(void *data, int key, int len);
// EXTERNAL DATA DECLARATIONS ---------------------------------------------- // EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS ------------------------------------------------- // PUBLIC DATA DEFINITIONS -------------------------------------------------
int NumLanguages, NumStringLists; int NumLanguages, NumStringLists;
// PRIVATE DATA DEFINITIONS ------------------------------------------------ // PRIVATE DATA DEFINITIONS ------------------------------------------------
static stringList_t MainStringList; static stringList_t MainStringList;
static stringList_t *StringLists[NUM_STRLISTS]; static stringList_t *StringLists[NUM_STRLISTS];
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
//========================================================================== //==========================================================================
// //
// STR_Init // STR_Init
// //
//========================================================================== //==========================================================================
void STR_Init(void) void STR_Init(void)
{ {
NumStringLists = 0; NumStringLists = 0;
MainStringList.stringCount = 0; MainStringList.stringCount = 0;
} }
//========================================================================== //==========================================================================
// //
// STR_Get // STR_Get
// //
//========================================================================== //==========================================================================
char *STR_Get(int num) char *STR_Get(int num)
{ {
return MainStringList.strings[num].name; return MainStringList.strings[num].name;
} }
//========================================================================== //==========================================================================
// //
// STR_Find // STR_Find
// //
//========================================================================== //==========================================================================
int STR_Find(char *name) int STR_Find(char *name)
{ {
return STR_FindInSomeList(&MainStringList, name); return STR_FindInSomeList(&MainStringList, name);
} }
//========================================================================== //==========================================================================
// //
// STR_FindInList // STR_FindInList
// //
//========================================================================== //==========================================================================
int STR_FindInList(int list, char *name) int STR_FindInList(int list, char *name)
{ {
if (StringLists[list] == NULL) if (StringLists[list] == NULL)
{ {
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY); StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0; StringLists[list]->stringCount = 0;
NumStringLists++; NumStringLists++;
if(pc_EnforceHexen) if(pc_EnforceHexen)
{ {
ERR_Error(ERR_HEXEN_COMPAT, YES); ERR_Error(ERR_HEXEN_COMPAT, YES);
} }
} }
return STR_FindInSomeList (StringLists[list], name); return STR_FindInSomeList (StringLists[list], name);
} }
//========================================================================== //==========================================================================
// //
// STR_FindInSomeList // STR_FindInSomeList
// //
//========================================================================== //==========================================================================
static int STR_FindInSomeList(stringList_t *list, char *name) static int STR_FindInSomeList(stringList_t *list, char *name)
{ {
int i; int i;
for(i = 0; i < list->stringCount; i++) for(i = 0; i < list->stringCount; i++)
{ {
if(strcmp(list->strings[i].name, name) == 0) if(strcmp(list->strings[i].name, name) == 0)
{ {
return i; return i;
} }
} }
// Add to list // Add to list
return STR_PutStringInSomeList(list, i, name); return STR_PutStringInSomeList(list, i, name);
} }
//========================================================================== //==========================================================================
// //
// STR_FindInListInsensitive // STR_FindInListInsensitive
// //
//========================================================================== //==========================================================================
int STR_FindInListInsensitive(int list, char *name) int STR_FindInListInsensitive(int list, char *name)
{ {
if (StringLists[list] == NULL) if (StringLists[list] == NULL)
{ {
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY); StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0; StringLists[list]->stringCount = 0;
NumStringLists++; NumStringLists++;
if(pc_EnforceHexen) if(pc_EnforceHexen)
{ {
ERR_Error(ERR_HEXEN_COMPAT, YES); ERR_Error(ERR_HEXEN_COMPAT, YES);
} }
} }
return STR_FindInSomeListInsensitive (StringLists[list], name); return STR_FindInSomeListInsensitive (StringLists[list], name);
} }
//========================================================================== //==========================================================================
// //
// STR_FindInSomeListInsensitive // STR_FindInSomeListInsensitive
// //
//========================================================================== //==========================================================================
static int STR_FindInSomeListInsensitive(stringList_t *list, char *name) static int STR_FindInSomeListInsensitive(stringList_t *list, char *name)
{ {
int i; int i;
for(i = 0; i < list->stringCount; i++) for(i = 0; i < list->stringCount; i++)
{ {
if(strcasecmp(list->strings[i].name, name) == 0) if(strcasecmp(list->strings[i].name, name) == 0)
{ {
return i; return i;
} }
} }
// Add to list // Add to list
return STR_PutStringInSomeList(list, i, name); return STR_PutStringInSomeList(list, i, name);
} }
//========================================================================== //==========================================================================
// //
// STR_GetString // STR_GetString
// //
//========================================================================== //==========================================================================
const char *STR_GetString(int list, int index) const char *STR_GetString(int list, int index)
{ {
if (StringLists[list] == NULL) if (StringLists[list] == NULL)
{ {
return NULL; return NULL;
} }
if (index < 0 || index >= StringLists[list]->stringCount) if (index < 0 || index >= StringLists[list]->stringCount)
{ {
return NULL; return NULL;
} }
return StringLists[list]->strings[index].name; return StringLists[list]->strings[index].name;
} }
//========================================================================== //==========================================================================
// //
// STR_AppendToList // STR_AppendToList
// //
//========================================================================== //==========================================================================
int STR_AppendToList(int list, char *name) int STR_AppendToList(int list, char *name)
{ {
if (StringLists[list] == NULL) if (StringLists[list] == NULL)
{ {
StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY); StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY);
StringLists[list]->stringCount = 0; StringLists[list]->stringCount = 0;
NumStringLists++; NumStringLists++;
} }
return STR_PutStringInSomeList(StringLists[list], StringLists[list]->stringCount, name); return STR_PutStringInSomeList(StringLists[list], StringLists[list]->stringCount, name);
} }
//========================================================================== //==========================================================================
// //
// STR_PutStringInSomeList // STR_PutStringInSomeList
// //
//========================================================================== //==========================================================================
static int STR_PutStringInSomeList(stringList_t *list, int index, char *name) static int STR_PutStringInSomeList(stringList_t *list, int index, char *name)
{ {
int i; int i;
if(index >= MAX_STRINGS) if(index >= MAX_STRINGS)
{ {
ERR_Error(ERR_TOO_MANY_STRINGS, YES, MAX_STRINGS); ERR_Error(ERR_TOO_MANY_STRINGS, YES, MAX_STRINGS);
return 0; return 0;
} }
MS_Message(MSG_DEBUG, "Adding string %d:\n \"%s\"\n", MS_Message(MSG_DEBUG, "Adding string %d:\n \"%s\"\n",
list->stringCount, name); list->stringCount, name);
if(index >= list->stringCount) if(index >= list->stringCount)
{ {
for(i = list->stringCount; i <= index; i++) for(i = list->stringCount; i <= index; i++)
{ {
list->strings[i].name = NULL; list->strings[i].name = NULL;
} }
list->stringCount = index + 1; list->stringCount = index + 1;
} }
if(list->strings[index].name != NULL) if(list->strings[index].name != NULL)
{ {
free(list->strings[index].name); free(list->strings[index].name);
} }
if(name != NULL) if(name != NULL)
{ {
list->strings[index].name = MS_Alloc(strlen(name)+1, ERR_OUT_OF_MEMORY); list->strings[index].name = MS_Alloc(strlen(name)+1, ERR_OUT_OF_MEMORY);
strcpy(list->strings[index].name, name); strcpy(list->strings[index].name, name);
} }
else else
{ {
list->strings[index].name = NULL; list->strings[index].name = NULL;
} }
return index; return index;
} }
//========================================================================== //==========================================================================
// //
// STR_ListSize // STR_ListSize
// //
//========================================================================== //==========================================================================
int STR_ListSize() int STR_ListSize()
{ {
return MainStringList.stringCount; return MainStringList.stringCount;
} }
//========================================================================== //==========================================================================
// //
// STR_WriteStrings // STR_WriteStrings
// //
// Writes all the strings to the p-code buffer. // Writes all the strings to the p-code buffer.
// //
//========================================================================== //==========================================================================
void STR_WriteStrings(void) void STR_WriteStrings(void)
{ {
int i; int i;
U_INT pad; U_INT pad;
MS_Message(MSG_DEBUG, "---- STR_WriteStrings ----\n"); MS_Message(MSG_DEBUG, "---- STR_WriteStrings ----\n");
for(i = 0; i < MainStringList.stringCount; i++) for(i = 0; i < MainStringList.stringCount; i++)
{ {
MainStringList.strings[i].address = pc_Address; MainStringList.strings[i].address = pc_Address;
PC_AppendString(MainStringList.strings[i].name); PC_AppendString(MainStringList.strings[i].name);
} }
if(pc_Address%4 != 0) if(pc_Address%4 != 0)
{ // Need to align { // Need to align
pad = 0; pad = 0;
PC_Append((void *)&pad, 4-(pc_Address%4)); PC_Append((void *)&pad, 4-(pc_Address%4));
} }
} }
//========================================================================== //==========================================================================
// //
// STR_WriteList // STR_WriteList
// //
//========================================================================== //==========================================================================
void STR_WriteList(void) void STR_WriteList(void)
{ {
int i; int i;
MS_Message(MSG_DEBUG, "---- STR_WriteList ----\n"); MS_Message(MSG_DEBUG, "---- STR_WriteList ----\n");
PC_AppendInt((U_INT)MainStringList.stringCount); PC_AppendInt((U_INT)MainStringList.stringCount);
for(i = 0; i < MainStringList.stringCount; i++) for(i = 0; i < MainStringList.stringCount; i++)
{ {
PC_AppendInt((U_INT)MainStringList.strings[i].address); PC_AppendInt((U_INT)MainStringList.strings[i].address);
} }
} }
//========================================================================== //==========================================================================
// //
// STR_WriteChunk // STR_WriteChunk
// //
//========================================================================== //==========================================================================
void STR_WriteChunk(boolean encrypt) void STR_WriteChunk(boolean encrypt)
{ {
int lenadr; int lenadr;
MS_Message(MSG_DEBUG, "---- STR_WriteChunk ----\n"); MS_Message(MSG_DEBUG, "---- STR_WriteChunk ----\n");
PC_Append(encrypt ? "STRE" : "STRL", 4); PC_Append(encrypt ? "STRE" : "STRL", 4);
lenadr = pc_Address; lenadr = pc_Address;
PC_SkipInt(); PC_SkipInt();
PC_AppendInt(0); PC_AppendInt(0);
PC_AppendInt(MainStringList.stringCount); PC_AppendInt(MainStringList.stringCount);
PC_AppendInt(0); // Used in-game for stringing lists together (NOT!) PC_AppendInt(0); // Used in-game for stringing lists together (NOT!)
DumpStrings (&MainStringList, lenadr, NO, encrypt); DumpStrings (&MainStringList, lenadr, NO, encrypt);
} }
//========================================================================== //==========================================================================
// //
// STR_WriteListChunk // STR_WriteListChunk
// //
//========================================================================== //==========================================================================
void STR_WriteListChunk(int list, int id, boolean quad) void STR_WriteListChunk(int list, int id, boolean quad)
{ {
int lenadr; int lenadr;
if (StringLists[list] != NULL && StringLists[list]->stringCount > 0) if (StringLists[list] != NULL && StringLists[list]->stringCount > 0)
{ {
MS_Message(MSG_DEBUG, "---- STR_WriteListChunk %d %c%c%c%c----\n", list, MS_Message(MSG_DEBUG, "---- STR_WriteListChunk %d %c%c%c%c----\n", list,
id&255, (id>>8)&255, (id>>16)&255, (id>>24)&255); id&255, (id>>8)&255, (id>>16)&255, (id>>24)&255);
PC_AppendInt((U_INT)id); PC_AppendInt((U_INT)id);
lenadr = pc_Address; lenadr = pc_Address;
PC_SkipInt(); PC_SkipInt();
PC_AppendInt(StringLists[list]->stringCount); PC_AppendInt(StringLists[list]->stringCount);
if (quad && pc_Address%8 != 0) if (quad && pc_Address%8 != 0)
{ // If writing quadword indices, align the indices to an { // If writing quadword indices, align the indices to an
// 8-byte boundary. // 8-byte boundary.
U_INT pad = 0; U_INT pad = 0;
PC_Append (&pad, 4); PC_Append (&pad, 4);
} }
DumpStrings(StringLists[list], lenadr, quad, NO); DumpStrings(StringLists[list], lenadr, quad, NO);
} }
} }
//========================================================================== //==========================================================================
// //
// DumpStrings // DumpStrings
// //
//========================================================================== //==========================================================================
static void DumpStrings(stringList_t *list, int lenadr, boolean quad, boolean crypt) static void DumpStrings(stringList_t *list, int lenadr, boolean quad, boolean crypt)
{ {
int i, ofs, startofs; int i, ofs, startofs;
startofs = ofs = pc_Address - lenadr - 4 + list->stringCount*(quad?8:4); startofs = ofs = pc_Address - lenadr - 4 + list->stringCount*(quad?8:4);
for(i = 0; i < list->stringCount; i++) for(i = 0; i < list->stringCount; i++)
{ {
if (list->strings[i].name != NULL) if (list->strings[i].name != NULL)
{ {
PC_AppendInt((U_INT)ofs); PC_AppendInt((U_INT)ofs);
ofs += strlen(list->strings[i].name) + 1; ofs += strlen(list->strings[i].name) + 1;
} }
else else
{ {
PC_AppendInt(0); PC_AppendInt(0);
} }
if (quad) if (quad)
{ {
PC_AppendInt(0); PC_AppendInt(0);
} }
} }
ofs = startofs; ofs = startofs;
for(i = 0; i < list->stringCount; i++) for(i = 0; i < list->stringCount; i++)
{ {
if(list->strings[i].name != NULL) if(list->strings[i].name != NULL)
{ {
int stringlen = strlen(list->strings[i].name) + 1; int stringlen = strlen(list->strings[i].name) + 1;
if(crypt) if(crypt)
{ {
int cryptkey = ofs*157135; int cryptkey = ofs*157135;
Encrypt(list->strings[i].name, cryptkey, stringlen); Encrypt(list->strings[i].name, cryptkey, stringlen);
PC_Append(list->strings[i].name, stringlen); PC_Append(list->strings[i].name, stringlen);
ofs += stringlen; ofs += stringlen;
Encrypt(list->strings[i].name, cryptkey, stringlen); Encrypt(list->strings[i].name, cryptkey, stringlen);
} }
else else
{ {
PC_AppendString(list->strings[i].name); PC_AppendString(list->strings[i].name);
} }
} }
} }
if(pc_Address%4 != 0) if(pc_Address%4 != 0)
{ // Need to align { // Need to align
U_INT pad = 0; U_INT pad = 0;
PC_Append((void *)&pad, 4-(pc_Address%4)); PC_Append((void *)&pad, 4-(pc_Address%4));
} }
PC_WriteInt(pc_Address - lenadr - 4, lenadr); PC_WriteInt(pc_Address - lenadr - 4, lenadr);
} }
static void Encrypt(void *data, int key, int len) static void Encrypt(void *data, int key, int len)
{ {
int p = (byte)key, i; int p = (byte)key, i;
for(i = 0; i < len; ++i) for(i = 0; i < len; ++i)
{ {
((byte *)data)[i] ^= (byte)(p+(i>>1)); ((byte *)data)[i] ^= (byte)(p+(i>>1));
} }
} }

View file

@ -1,38 +1,38 @@
//************************************************************************** //**************************************************************************
//** //**
//** strlist.h //** strlist.h
//** //**
//************************************************************************** //**************************************************************************
#ifndef __STRLIST_H__ #ifndef __STRLIST_H__
#define __STRLIST_H__ #define __STRLIST_H__
// HEADER FILES ------------------------------------------------------------ // HEADER FILES ------------------------------------------------------------
#include "common.h" #include "common.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void STR_Init(void); void STR_Init(void);
int STR_Find(char *name); int STR_Find(char *name);
char *STR_Get(int index); char *STR_Get(int index);
void STR_WriteStrings(void); void STR_WriteStrings(void);
void STR_WriteList(void); void STR_WriteList(void);
int STR_FindInList(int list, char *name); int STR_FindInList(int list, char *name);
int STR_FindInListInsensitive(int list, char *name); int STR_FindInListInsensitive(int list, char *name);
int STR_AppendToList(int list, char *name); int STR_AppendToList(int list, char *name);
const char *STR_GetString(int list, int index); const char *STR_GetString(int list, int index);
void STR_WriteChunk(boolean encrypt); void STR_WriteChunk(boolean encrypt);
void STR_WriteListChunk(int list, int id, boolean quad); void STR_WriteListChunk(int list, int id, boolean quad);
int STR_ListSize(); int STR_ListSize();
// PUBLIC DATA DECLARATIONS ------------------------------------------------ // PUBLIC DATA DECLARATIONS ------------------------------------------------
extern int NumStringLists; extern int NumStringLists;
#endif #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 //** symbol.h
//** //**
//************************************************************************** //**************************************************************************
#ifndef __SYMBOL_H__ #ifndef __SYMBOL_H__
#define __SYMBOL_H__ #define __SYMBOL_H__
// HEADER FILES ------------------------------------------------------------ // HEADER FILES ------------------------------------------------------------
#include "common.h" #include "common.h"
#include "pcode.h" #include "pcode.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
#define MAX_ARRAY_DIMS 8 #define MAX_ARRAY_DIMS 8
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
typedef enum typedef enum
{ {
SY_DUMMY, SY_DUMMY,
SY_LABEL, SY_LABEL,
SY_SCRIPTVAR, SY_SCRIPTVAR,
SY_SCRIPTALIAS, SY_SCRIPTALIAS,
SY_MAPVAR, SY_MAPVAR,
SY_WORLDVAR, SY_WORLDVAR,
SY_GLOBALVAR, SY_GLOBALVAR,
SY_SCRIPTARRAY, SY_SCRIPTARRAY,
SY_MAPARRAY, SY_MAPARRAY,
SY_WORLDARRAY, SY_WORLDARRAY,
SY_GLOBALARRAY, SY_GLOBALARRAY,
SY_SPECIAL, SY_SPECIAL,
SY_CONSTANT, SY_CONSTANT,
SY_INTERNFUNC, SY_INTERNFUNC,
SY_SCRIPTFUNC SY_SCRIPTFUNC
} symbolType_t; } symbolType_t;
typedef struct typedef struct
{ {
U_BYTE index; U_BYTE index;
} symVar_t; } symVar_t;
typedef struct typedef struct
{ {
U_BYTE index; U_BYTE index;
int dimensions[MAX_ARRAY_DIMS]; int dimensions[MAX_ARRAY_DIMS];
int ndim; int ndim;
int size; int size;
} symArray_t; } symArray_t;
typedef struct typedef struct
{ {
int address; int address;
} symLabel_t; } symLabel_t;
typedef struct typedef struct
{ {
int value; int value;
int argCount; int argCount;
} symSpecial_t; } symSpecial_t;
typedef struct typedef struct
{ {
int value; int value;
char *strValue; char *strValue;
int fileDepth; int fileDepth;
} symConstant_t; } symConstant_t;
typedef struct typedef struct
{ {
pcd_t directCommand; pcd_t directCommand;
pcd_t stackCommand; pcd_t stackCommand;
int argCount; int argCount;
int optMask; int optMask;
int outMask; int outMask;
boolean hasReturnValue; boolean hasReturnValue;
boolean latent; boolean latent;
} symInternFunc_t; } symInternFunc_t;
typedef struct typedef struct
{ {
int address; int address;
int argCount; int argCount;
int varCount; int varCount;
int funcNumber; int funcNumber;
boolean hasReturnValue; boolean hasReturnValue;
int sourceLine; int sourceLine;
char *sourceName; char *sourceName;
boolean predefined; boolean predefined;
} symScriptFunc_t; } symScriptFunc_t;
typedef struct symbolNode_s typedef struct symbolNode_s
{ {
struct symbolNode_s *left; struct symbolNode_s *left;
struct symbolNode_s *right; struct symbolNode_s *right;
char *name; char *name;
symbolType_t type; symbolType_t type;
boolean unused; boolean unused;
boolean imported; boolean imported;
union union
{ {
symVar_t var; symVar_t var;
symArray_t array; symArray_t array;
symLabel_t label; symLabel_t label;
symSpecial_t special; symSpecial_t special;
symConstant_t constant; symConstant_t constant;
symInternFunc_t internFunc; symInternFunc_t internFunc;
symScriptFunc_t scriptFunc; symScriptFunc_t scriptFunc;
} info; } info;
} symbolNode_t; } symbolNode_t;
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void SY_Init(void); void SY_Init(void);
symbolNode_t *SY_Find(char *name); symbolNode_t *SY_Find(char *name);
symbolNode_t *SY_FindLocal(char *name); symbolNode_t *SY_FindLocal(char *name);
symbolNode_t *SY_FindGlobal(char *name); symbolNode_t *SY_FindGlobal(char *name);
symbolNode_t *SY_InsertLocal(char *name, symbolType_t type); symbolNode_t *SY_InsertLocal(char *name, symbolType_t type);
symbolNode_t *SY_InsertGlobal(char *name, symbolType_t type); symbolNode_t *SY_InsertGlobal(char *name, symbolType_t type);
symbolNode_t *SY_InsertGlobalUnique(char *name, symbolType_t type); symbolNode_t *SY_InsertGlobalUnique(char *name, symbolType_t type);
void SY_FreeLocals(void); void SY_FreeLocals(void);
void SY_FreeGlobals(void); void SY_FreeGlobals(void);
void SY_FreeConstants(int depth); void SY_FreeConstants(int depth);
void SY_ClearShared(void); void SY_ClearShared(void);
// PUBLIC DATA DECLARATIONS ------------------------------------------------ // PUBLIC DATA DECLARATIONS ------------------------------------------------
#endif #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 //** token.h
//** //**
//************************************************************************** //**************************************************************************
#ifndef __TOKEN_H__ #ifndef __TOKEN_H__
#define __TOKEN_H__ #define __TOKEN_H__
// HEADER FILES ------------------------------------------------------------ // HEADER FILES ------------------------------------------------------------
#include "common.h" #include "common.h"
#include "error.h" #include "error.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
typedef enum typedef enum
{ {
TK_NONE, TK_NONE,
TK_EOF, TK_EOF,
TK_IDENTIFIER, // VALUE: (char *) tk_String TK_IDENTIFIER, // VALUE: (char *) tk_String
TK_STRING, // VALUE: (char *) tk_String TK_STRING, // VALUE: (char *) tk_String
TK_NUMBER, // VALUE: (int) tk_Number TK_NUMBER, // VALUE: (int) tk_Number
TK_LINESPECIAL, // VALUE: (int) tk_LineSpecial TK_LINESPECIAL, // VALUE: (int) tk_LineSpecial
TK_PLUS, // '+' TK_PLUS, // '+'
TK_MINUS, // '-' TK_MINUS, // '-'
TK_ASTERISK, // '*' TK_ASTERISK, // '*'
TK_SLASH, // '/' TK_SLASH, // '/'
TK_PERCENT, // '%' TK_PERCENT, // '%'
TK_ASSIGN, // '=' TK_ASSIGN, // '='
TK_ADDASSIGN, // '+=' TK_ADDASSIGN, // '+='
TK_SUBASSIGN, // '-=' TK_SUBASSIGN, // '-='
TK_MULASSIGN, // '*=' TK_MULASSIGN, // '*='
TK_DIVASSIGN, // '/=' TK_DIVASSIGN, // '/='
TK_MODASSIGN, // '%=' TK_MODASSIGN, // '%='
TK_INC, // '++' TK_INC, // '++'
TK_DEC, // '--' TK_DEC, // '--'
TK_EQ, // '==' TK_EQ, // '=='
TK_NE, // '!=' TK_NE, // '!='
TK_LT, // '<' TK_LT, // '<'
TK_GT, // '>' TK_GT, // '>'
TK_LE, // '<=' TK_LE, // '<='
TK_GE, // '>=' TK_GE, // '>='
TK_LSHIFT, // '<<' TK_LSHIFT, // '<<'
TK_RSHIFT, // '>>' TK_RSHIFT, // '>>'
TK_ANDLOGICAL, // '&&' TK_ANDLOGICAL, // '&&'
TK_ORLOGICAL, // '||' TK_ORLOGICAL, // '||'
TK_ANDBITWISE, // '&' TK_ANDBITWISE, // '&'
TK_ORBITWISE, // '|' TK_ORBITWISE, // '|'
TK_EORBITWISE, // '^' TK_EORBITWISE, // '^'
TK_TILDE, // '~' TK_TILDE, // '~'
TK_LPAREN, // '(' TK_LPAREN, // '('
TK_RPAREN, // ')' TK_RPAREN, // ')'
TK_LBRACE, // '{' TK_LBRACE, // '{'
TK_RBRACE, // '}' TK_RBRACE, // '}'
TK_LBRACKET, // '[' TK_LBRACKET, // '['
TK_RBRACKET, // ']' TK_RBRACKET, // ']'
TK_TERNARY, // '?' TK_TERNARY, // '?'
TK_COLON, // ':' TK_COLON, // ':'
TK_SEMICOLON, // ';' TK_SEMICOLON, // ';'
TK_COMMA, // ',' TK_COMMA, // ','
TK_PERIOD, // '.' TK_PERIOD, // '.'
TK_NOT, // '!' TK_NOT, // '!'
TK_NUMBERSIGN, // '#' TK_NUMBERSIGN, // '#'
TK_CPPCOMMENT, // '//' TK_CPPCOMMENT, // '//'
TK_STARTCOMMENT, // '/*' TK_STARTCOMMENT, // '/*'
TK_ENDCOMMENT, // '*/' TK_ENDCOMMENT, // '*/'
TK_BREAK, // 'break' TK_BREAK, // 'break'
TK_CASE, // 'case' TK_CASE, // 'case'
TK_CONST, // 'const' TK_CONST, // 'const'
TK_CONTINUE, // 'continue' TK_CONTINUE, // 'continue'
TK_DEFAULT, // 'default' TK_DEFAULT, // 'default'
TK_DEFINE, // 'define' TK_DEFINE, // 'define'
TK_DO, // 'do' TK_DO, // 'do'
TK_ELSE, // 'else' TK_ELSE, // 'else'
TK_FOR, // 'for' TK_FOR, // 'for'
TK_GOTO, // 'goto' TK_GOTO, // 'goto'
TK_IF, // 'if' TK_IF, // 'if'
TK_INCLUDE, // 'include' TK_INCLUDE, // 'include'
TK_INT, // 'int' TK_INT, // 'int'
TK_OPEN, // 'open' TK_OPEN, // 'open'
TK_PRINT, // 'print' TK_PRINT, // 'print'
TK_PRINTBOLD, // 'printbold' TK_PRINTBOLD, // 'printbold'
TK_LOG, // 'log' TK_LOG, // 'log'
TK_HUDMESSAGE, // 'hudmessage' TK_HUDMESSAGE, // 'hudmessage'
TK_HUDMESSAGEBOLD, // 'hudmessagebold' TK_HUDMESSAGEBOLD, // 'hudmessagebold'
TK_RESTART, // 'restart' TK_RESTART, // 'restart'
TK_SCRIPT, // 'script' TK_SCRIPT, // 'script'
TK_SPECIAL, // 'special' TK_SPECIAL, // 'special'
TK_STR, // 'str' TK_STR, // 'str'
TK_SUSPEND, // 'suspend' TK_SUSPEND, // 'suspend'
TK_SWITCH, // 'switch' TK_SWITCH, // 'switch'
TK_TERMINATE, // 'terminate' TK_TERMINATE, // 'terminate'
TK_UNTIL, // 'until' TK_UNTIL, // 'until'
TK_VOID, // 'void' TK_VOID, // 'void'
TK_WHILE, // 'while' TK_WHILE, // 'while'
TK_WORLD, // 'world' TK_WORLD, // 'world'
TK_GLOBAL, // 'global' TK_GLOBAL, // 'global'
TK_RESPAWN, // 'respawn' [BC] TK_RESPAWN, // 'respawn' [BC]
TK_DEATH, // 'death' [BC] TK_DEATH, // 'death' [BC]
TK_ENTER, // 'enter' [BC] TK_ENTER, // 'enter' [BC]
TK_PICKUP, // 'pickup' [BC] TK_PICKUP, // 'pickup' [BC]
TK_BLUERETURN, // 'bluereturn' [BC] TK_BLUERETURN, // 'bluereturn' [BC]
TK_REDRETURN, // 'redreturn' [BC] TK_REDRETURN, // 'redreturn' [BC]
TK_WHITERETURN, // 'whitereturn' [BC] TK_WHITERETURN, // 'whitereturn' [BC]
TK_NOCOMPACT, // 'nocompact' TK_NOCOMPACT, // 'nocompact'
TK_LIGHTNING, // 'ligtning' TK_LIGHTNING, // 'ligtning'
TK_CREATETRANSLATION,// 'createtranslation' TK_CREATETRANSLATION,// 'createtranslation'
TK_FUNCTION, // 'function' TK_FUNCTION, // 'function'
TK_RETURN, // 'return' TK_RETURN, // 'return'
TK_WADAUTHOR, // 'wadauthor' TK_WADAUTHOR, // 'wadauthor'
TK_NOWADAUTHOR, // 'nowadauthor' TK_NOWADAUTHOR, // 'nowadauthor'
TK_ACSEXECUTEWAIT, // 'acs_executewait' TK_ACSEXECUTEWAIT, // 'acs_executewait'
TK_ACSNAMEDEXECUTEWAIT,// 'acs_namedexecutewait' TK_ACSNAMEDEXECUTEWAIT,// 'acs_namedexecutewait'
TK_ENCRYPTSTRINGS, // 'encryptstrings' TK_ENCRYPTSTRINGS, // 'encryptstrings'
TK_IMPORT, // 'import' TK_IMPORT, // 'import'
TK_LIBRARY, // 'library' TK_LIBRARY, // 'library'
TK_LIBDEFINE, // 'libdefine' TK_LIBDEFINE, // 'libdefine'
TK_BOOL, // 'bool' TK_BOOL, // 'bool'
TK_NET, // 'net' TK_NET, // 'net'
TK_CLIENTSIDE, // 'clientside' TK_CLIENTSIDE, // 'clientside'
TK_DISCONNECT, // 'disconnect' TK_DISCONNECT, // 'disconnect'
TK_EVENT, // 'event' [BB] TK_EVENT, // 'event' [BB]
TK_UNLOADING, // 'unloading' TK_UNLOADING, // 'unloading'
TK_STATIC, // 'static' TK_STATIC, // 'static'
TK_ANDASSIGN, // '&=' TK_ANDASSIGN, // '&='
TK_ORASSIGN, // '|=' TK_ORASSIGN, // '|='
TK_EORASSIGN, // '^=' TK_EORASSIGN, // '^='
TK_LSASSIGN, // '<<=' TK_LSASSIGN, // '<<='
TK_RSASSIGN, // '>>=' TK_RSASSIGN, // '>>='
TK_STRPARAM_EVAL, // 'strparam' TK_STRPARAM_EVAL, // 'strparam'
TK_STRCPY, // 'strcpy' TK_STRCPY, // 'strcpy'
TK_REGION, // 'region' [mxd] TK_REGION, // 'region' [mxd]
TK_ENDREGION, // 'endregion' [mxd] TK_ENDREGION, // 'endregion' [mxd]
TK_KILL, // 'kill' [JM] TK_KILL, // 'kill' [JM]
TK_REOPEN, // 'reopen' [Nash] TK_REOPEN, // 'reopen' [Nash]
TK_ATSIGN, // '@' TK_ATSIGN, // '@'
TK_MORPHACTOR, // 'morphactor' [Dasperal] TK_MORPHACTOR, // 'morphactor' [Dasperal]
} tokenType_t; } tokenType_t;
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void TK_Init(void); void TK_Init(void);
void TK_OpenSource(char *fileName); void TK_OpenSource(char *fileName);
void TK_Include(char *fileName); void TK_Include(char *fileName);
void TK_Import(char *fileName, enum ImportModes prevMode); void TK_Import(char *fileName, enum ImportModes prevMode);
void TK_CloseSource(void); void TK_CloseSource(void);
int TK_GetDepth(void); int TK_GetDepth(void);
tokenType_t TK_NextToken(void); tokenType_t TK_NextToken(void);
int TK_NextCharacter(void); int TK_NextCharacter(void);
boolean TK_NextTokenMustBe(tokenType_t token, error_t error); boolean TK_NextTokenMustBe(tokenType_t token, error_t error);
boolean TK_TokenMustBe(tokenType_t token, error_t error); boolean TK_TokenMustBe(tokenType_t token, error_t error);
boolean TK_Member(tokenType_t *list); boolean TK_Member(tokenType_t *list);
void TK_Undo(void); void TK_Undo(void);
void TK_SkipLine(void); void TK_SkipLine(void);
void TK_SkipPast(tokenType_t token); void TK_SkipPast(tokenType_t token);
void TK_SkipTo(tokenType_t token); void TK_SkipTo(tokenType_t token);
void TK_AddIncludePath(char *sourceName); void TK_AddIncludePath(char *sourceName);
void TK_AddProgramIncludePath(char *argv0); void TK_AddProgramIncludePath(char *argv0);
// PUBLIC DATA DECLARATIONS ------------------------------------------------ // PUBLIC DATA DECLARATIONS ------------------------------------------------
extern tokenType_t tk_Token; extern tokenType_t tk_Token;
extern int tk_Line; extern int tk_Line;
extern int tk_Number; extern int tk_Number;
extern char *tk_String; extern char *tk_String;
extern int tk_SpecialValue; extern int tk_SpecialValue;
extern int tk_SpecialArgCount; extern int tk_SpecialArgCount;
extern char *tk_SourceName; extern char *tk_SourceName;
extern int tk_IncludedLines; extern int tk_IncludedLines;
extern boolean forSemicolonHack; extern boolean forSemicolonHack;
extern char MasterSourceLine[]; // master line - Ty 07jan2000 extern char MasterSourceLine[]; // master line - Ty 07jan2000
extern int MasterSourcePos; // master position - Ty 07jan2000 extern int MasterSourcePos; // master position - Ty 07jan2000
extern boolean ClearMasterSourceLine; // ready for new line - Ty 07jan2000 extern boolean ClearMasterSourceLine; // ready for new line - Ty 07jan2000
#endif #endif

View file

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

View file

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