formatting and all sorts of cleanup stuff... not anywhere near done or

perfect... :(


SVN revision: 9805
This commit is contained in:
Carsten Haitzler 2004-04-20 03:50:11 +00:00
parent c742fbdd6a
commit 0d755cb255
16 changed files with 12921 additions and 11771 deletions

View File

@ -21,53 +21,25 @@
* Version: $Id$
*/
#if defined LINUX
#include "embryo_cc_osdefs.h"
#include "embryo_cc_sclinux.h"
#endif
#include "embryo_cc_osdefs.h"
#include "embryo_cc_sclinux.h"
#ifndef __AMX_H
#define __AMX_H
#ifndef EMBRYO_CC_AMX_H
#define EMBRYO_CC_AMX_H
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
/* The ISO C99 defines the int16_t and int_32t types. If the compiler got
* here, these types are probably undefined.
*/
# ifndef HAVE_STDINT_H
typedef short int int16_t;
typedef unsigned short int uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef short int int16_t;
typedef unsigned short int uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
# endif
#endif
#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined __MSDOS__
#if !defined alloca
#define alloca(n) _alloca(n)
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* calling convention for native functions */
#if !defined AMX_NATIVE_CALL
#define AMX_NATIVE_CALL
#endif
/* calling convention for all interface functions and callback functions */
#if !defined AMXAPI
#if defined STDECL
#define AMXAPI __stdcall
#elif defined CDECL
#define AMXAPI __cdecl
#else
#define AMXAPI
#endif
#endif
#if !defined AMXEXPORT
#define AMXEXPORT
#endif
/* File format version Required AMX version
* 0 (original version) 0
@ -79,192 +51,155 @@ extern "C" {
* 6 (reformatted header) 6
* 7 (name table, opcodes SYMTAG & SYSREQ.D) 7
*/
#define CUR_FILE_VERSION 7 /* current file version; also the current AMX version */
#define MIN_FILE_VERSION 6 /* lowest supported file format version for the current AMX version */
#define MIN_AMX_VERSION 7 /* minimum AMX version needed to support the current file format */
#define CUR_FILE_VERSION 7 /* current file version; also the current AMX version */
#define MIN_FILE_VERSION 6 /* lowest supported file format version for the current AMX version */
#define MIN_AMX_VERSION 7 /* minimum AMX version needed to support the current file format */
#if !defined CELL_TYPE
#define CELL_TYPE
#if defined(BIT16)
typedef uint16_t ucell; /* only for type casting */
typedef int16_t cell;
#else
typedef uint32_t ucell;
typedef int32_t cell;
#endif
#define CELL_TYPE
typedef uint32_t ucell;
typedef int32_t cell;
#endif
struct tagAMX;
typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct tagAMX *amx, cell *params);
typedef int (AMXAPI *AMX_CALLBACK)(struct tagAMX *amx, cell index,
cell *result, cell *params);
typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#if !defined _FAR
#define _FAR
#endif
struct tagAMX;
typedef cell(*AMX_NATIVE) (struct tagAMX * amx,
cell * params);
typedef int (* AMX_CALLBACK) (struct tagAMX * amx, cell index,
cell * result, cell * params);
typedef int (* AMX_DEBUG) (struct tagAMX * amx);
#if defined _MSC_VER
#pragma warning(disable:4103) /* disable warning message 4103 that complains
* about pragma pack in a header file */
#pragma warning(disable:4100) /* "'%$S' : unreferenced formal parameter" */
#endif
/* Some compilers do not support the #pragma align, which should be fine. Some
* compilers give a warning on unknown #pragmas, which is not so fine...
*/
#if defined SN_TARGET_PS2 || defined __GNUC__
#define AMX_NO_ALIGN
#endif
#if defined __GNUC__
#define PACKED __attribute__((packed))
#else
#define PACKED
#endif
#if !defined AMX_NO_ALIGN
#if defined LINUX
#pragma pack(1) /* structures must be packed (byte-aligned) */
#else
#pragma pack(push)
#pragma pack(1) /* structures must be packed (byte-aligned) */
#if defined __TURBOC__
#pragma option -a- /* "pack" pragma for older Borland compilers */
#endif
#endif
#endif
typedef struct {
char _FAR *name PACKED;
AMX_NATIVE func PACKED;
} AMX_NATIVE_INFO PACKED;
typedef struct
{
char *name;
AMX_NATIVE func ;
} AMX_NATIVE_INFO ;
#define AMX_USERNUM 4
#define sEXPMAX 19 /* maximum name length for file version <= 6 */
#define sNAMEMAX 31 /* maximum name length of symbol name */
#define sEXPMAX 19 /* maximum name length for file version <= 6 */
#define sNAMEMAX 31 /* maximum name length of symbol name */
typedef struct tagAMX_FUNCSTUB {
uint32_t address PACKED;
char name[sEXPMAX+1] PACKED;
} AMX_FUNCSTUB PACKED;
typedef struct tagAMX_FUNCSTUB
{
uint32_t address ;
char name[sEXPMAX + 1];
} AMX_FUNCSTUB __attribute__((packed));
/* The AMX structure is the internal structure for many functions. Not all
* fields are valid at all times; many fields are cached in local variables.
*/
typedef struct tagAMX {
unsigned char _FAR *base PACKED; /* points to the AMX header ("amxhdr") plus the code, optionally also the data */
unsigned char _FAR *data PACKED; /* points to separate data+stack+heap, may be NULL */
AMX_CALLBACK callback PACKED;
AMX_DEBUG debug PACKED; /* debug callback */
/* for external functions a few registers must be accessible from the outside */
cell cip PACKED; /* instruction pointer: relative to base + amxhdr->cod */
cell frm PACKED; /* stack frame base: relative to base + amxhdr->dat */
cell hea PACKED; /* top of the heap: relative to base + amxhdr->dat */
cell hlw PACKED; /* bottom of the heap: relative to base + amxhdr->dat */
cell stk PACKED; /* stack pointer: relative to base + amxhdr->dat */
cell stp PACKED; /* top of the stack: relative to base + amxhdr->dat */
int flags PACKED; /* current status, see amx_Flags() */
/* for assertions and debug hook */
cell curline PACKED;
cell curfile PACKED;
int dbgcode PACKED;
cell dbgaddr PACKED;
cell dbgparam PACKED;
char _FAR *dbgname PACKED;
/* user data */
long usertags[AMX_USERNUM] PACKED;
void _FAR *userdata[AMX_USERNUM] PACKED;
/* native functions can raise an error */
int error PACKED;
/* the sleep opcode needs to store the full AMX status */
cell pri PACKED;
cell alt PACKED;
cell reset_stk PACKED;
cell reset_hea PACKED;
cell _FAR *syscall_d PACKED; /* relocated value/address for the SYSCALL.D opcode */
#if defined JIT
/* support variables for the JIT */
int reloc_size PACKED; /* required temporary buffer for relocations */
long code_size PACKED; /* estimated memory footprint of the native code */
#endif
} AMX PACKED;
typedef struct tagAMX
{
unsigned char *base; /* points to the AMX header ("amxhdr") plus the code, optionally also the data */
unsigned char *data; /* points to separate data+stack+heap, may be NULL */
AMX_CALLBACK callback;
AMX_DEBUG debug ; /* debug callback */
/* for external functions a few registers must be accessible from the outside */
cell cip ; /* instruction pointer: relative to base + amxhdr->cod */
cell frm ; /* stack frame base: relative to base + amxhdr->dat */
cell hea ; /* top of the heap: relative to base + amxhdr->dat */
cell hlw ; /* bottom of the heap: relative to base + amxhdr->dat */
cell stk ; /* stack pointer: relative to base + amxhdr->dat */
cell stp ; /* top of the stack: relative to base + amxhdr->dat */
int flags ; /* current status, see amx_Flags() */
/* for assertions and debug hook */
cell curline ;
cell curfile ;
int dbgcode ;
cell dbgaddr ;
cell dbgparam ;
char *dbgname;
/* user data */
long usertags[AMX_USERNUM];
void *userdata[AMX_USERNUM];
/* native functions can raise an error */
int error ;
/* the sleep opcode needs to store the full AMX status */
cell pri ;
cell alt ;
cell reset_stk ;
cell reset_hea ;
cell *syscall_d; /* relocated value/address for the SYSCALL.D opcode */
} AMX __attribute__((packed));
/* The AMX_HEADER structure is both the memory format as the file format. The
* structure is used internaly.
*/
typedef struct tagAMX_HEADER {
int32_t size PACKED; /* size of the "file" */
uint16_t magic PACKED; /* signature */
char file_version PACKED; /* file format version */
char amx_version PACKED; /* required version of the AMX */
int16_t flags PACKED;
int16_t defsize PACKED; /* size of a definition record */
int32_t cod PACKED; /* initial value of COD - code block */
int32_t dat PACKED; /* initial value of DAT - data block */
int32_t hea PACKED; /* initial value of HEA - start of the heap */
int32_t stp PACKED; /* initial value of STP - stack top */
int32_t cip PACKED; /* initial value of CIP - the instruction pointer */
int32_t publics PACKED; /* offset to the "public functions" table */
int32_t natives PACKED; /* offset to the "native functions" table */
int32_t libraries PACKED; /* offset to the table of libraries */
int32_t pubvars PACKED; /* the "public variables" table */
int32_t tags PACKED; /* the "public tagnames" table */
int32_t nametable PACKED; /* name table, file version 7 only */
} AMX_HEADER PACKED;
typedef struct tagAMX_HEADER
{
int32_t size ; /* size of the "file" */
uint16_t magic ; /* signature */
char file_version ; /* file format version */
char amx_version ; /* required version of the AMX */
int16_t flags ;
int16_t defsize ; /* size of a definition record */
int32_t cod ; /* initial value of COD - code block */
int32_t dat ; /* initial value of DAT - data block */
int32_t hea ; /* initial value of HEA - start of the heap */
int32_t stp ; /* initial value of STP - stack top */
int32_t cip ; /* initial value of CIP - the instruction pointer */
int32_t publics ; /* offset to the "public functions" table */
int32_t natives ; /* offset to the "native functions" table */
int32_t libraries ; /* offset to the table of libraries */
int32_t pubvars ; /* the "public variables" table */
int32_t tags ; /* the "public tagnames" table */
int32_t nametable ; /* name table, file version 7 only */
} AMX_HEADER __attribute__((packed));
#define AMX_MAGIC 0xf1e0
enum {
AMX_ERR_NONE,
/* reserve the first 15 error codes for exit codes of the abstract machine */
AMX_ERR_EXIT, /* forced exit */
AMX_ERR_ASSERT, /* assertion failed */
AMX_ERR_STACKERR, /* stack/heap collision */
AMX_ERR_BOUNDS, /* index out of bounds */
AMX_ERR_MEMACCESS, /* invalid memory access */
AMX_ERR_INVINSTR, /* invalid instruction */
AMX_ERR_STACKLOW, /* stack underflow */
AMX_ERR_HEAPLOW, /* heap underflow */
AMX_ERR_CALLBACK, /* no callback, or invalid callback */
AMX_ERR_NATIVE, /* native function failed */
AMX_ERR_DIVIDE, /* divide by zero */
AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */
enum
{
AMX_ERR_NONE,
/* reserve the first 15 error codes for exit codes of the abstract machine */
AMX_ERR_EXIT, /* forced exit */
AMX_ERR_ASSERT, /* assertion failed */
AMX_ERR_STACKERR, /* stack/heap collision */
AMX_ERR_BOUNDS, /* index out of bounds */
AMX_ERR_MEMACCESS, /* invalid memory access */
AMX_ERR_INVINSTR, /* invalid instruction */
AMX_ERR_STACKLOW, /* stack underflow */
AMX_ERR_HEAPLOW, /* heap underflow */
AMX_ERR_CALLBACK, /* no callback, or invalid callback */
AMX_ERR_NATIVE, /* native function failed */
AMX_ERR_DIVIDE, /* divide by zero */
AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */
AMX_ERR_MEMORY = 16, /* out of memory */
AMX_ERR_FORMAT, /* invalid file format */
AMX_ERR_VERSION, /* file is for a newer version of the AMX */
AMX_ERR_NOTFOUND, /* function not found */
AMX_ERR_INDEX, /* invalid index parameter (bad entry point) */
AMX_ERR_DEBUG, /* debugger cannot run */
AMX_ERR_INIT, /* AMX not initialized (or doubly initialized) */
AMX_ERR_USERDATA, /* unable to set user data field (table full) */
AMX_ERR_INIT_JIT, /* cannot initialize the JIT */
AMX_ERR_PARAMS, /* parameter error */
AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */
};
AMX_ERR_MEMORY = 16, /* out of memory */
AMX_ERR_FORMAT, /* invalid file format */
AMX_ERR_VERSION, /* file is for a newer version of the AMX */
AMX_ERR_NOTFOUND, /* function not found */
AMX_ERR_INDEX, /* invalid index parameter (bad entry point) */
AMX_ERR_DEBUG, /* debugger cannot run */
AMX_ERR_INIT, /* AMX not initialized (or doubly initialized) */
AMX_ERR_USERDATA, /* unable to set user data field (table full) */
AMX_ERR_INIT_JIT, /* cannot initialize the JIT */
AMX_ERR_PARAMS, /* parameter error */
AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */
};
enum {
DBG_INIT, /* query/initialize */
DBG_FILE, /* file number in curfile, filename in name */
DBG_LINE, /* line number in curline, file number in curfile */
DBG_SYMBOL, /* address in dbgaddr, class/type in dbgparam */
DBG_CLRSYM, /* stack address below which locals should be removed. stack address in stk */
DBG_CALL, /* function call, address jumped to in dbgaddr */
DBG_RETURN, /* function returns */
DBG_TERMINATE, /* program ends, code address in dbgaddr, reason in dbgparam */
DBG_SRANGE, /* symbol size and dimensions (arrays); level in dbgaddr (!); length in dbgparam */
DBG_SYMTAG, /* tag of the most recent symbol (if non-zero), tag in dbgparam */
};
enum
{
DBG_INIT, /* query/initialize */
DBG_FILE, /* file number in curfile, filename in name */
DBG_LINE, /* line number in curline, file number in curfile */
DBG_SYMBOL, /* address in dbgaddr, class/type in dbgparam */
DBG_CLRSYM, /* stack address below which locals should be removed. stack address in stk */
DBG_CALL, /* function call, address jumped to in dbgaddr */
DBG_RETURN, /* function returns */
DBG_TERMINATE, /* program ends, code address in dbgaddr, reason in dbgparam */
DBG_SRANGE, /* symbol size and dimensions (arrays); level in dbgaddr (!); length in dbgparam */
DBG_SYMTAG, /* tag of the most recent symbol (if non-zero), tag in dbgparam */
};
#define AMX_FLAG_CHAR16 0x01 /* characters are 16-bit */
#define AMX_FLAG_DEBUG 0x02 /* symbolic info. available */
#define AMX_FLAG_COMPACT 0x04 /* compact encoding */
#define AMX_FLAG_BIGENDIAN 0x08 /* big endian encoding */
#define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking */
#define AMX_FLAG_BROWSE 0x4000 /* browsing/relocating or executing */
#define AMX_FLAG_RELOC 0x8000 /* jump/call addresses relocated */
#define AMX_FLAG_CHAR16 0x01 /* characters are 16-bit */
#define AMX_FLAG_DEBUG 0x02 /* symbolic info. available */
#define AMX_FLAG_COMPACT 0x04 /* compact encoding */
#define AMX_FLAG_BIGENDIAN 0x08 /* big endian encoding */
#define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking */
#define AMX_FLAG_BROWSE 0x4000 /* browsing/relocating or executing */
#define AMX_FLAG_RELOC 0x8000 /* jump/call addresses relocated */
#define AMX_EXEC_MAIN -1 /* start at program entry point */
#define AMX_EXEC_CONT -2 /* continue from last address */
#define AMX_EXEC_MAIN -1 /* start at program entry point */
#define AMX_EXEC_CONT -2 /* continue from last address */
#define AMX_USERTAG(a,b,c,d) ((a) | ((b)<<8) | ((long)(c)<<16) | ((long)(d)<<24))
@ -274,8 +209,8 @@ enum {
* two macros are convenient for casting a "cell" into a "float" type _without_
* changing the bit pattern
*/
#define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */
#define amx_ctof(c) ( * ((float*)&c) ) /* cell to float */
#define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */
#define amx_ctof(c) ( * ((float*)&c) ) /* cell to float */
#define amx_StrParam(amx,param,result) { \
cell *amx_cstr_; int amx_length_; \
@ -287,57 +222,54 @@ enum {
else (result) = NULL; \
}
uint16_t * AMXAPI amx_Align16(uint16_t *v);
uint32_t * AMXAPI amx_Align32(uint32_t *v);
int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr);
int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params);
int AMXAPI amx_Cleanup(AMX *amx);
int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data);
int AMXAPI amx_Debug(AMX *amx); /* default debug procedure, does nothing */
int AMXAPI amx_Exec(AMX *amx, cell *retval, int index, int numparams, ...);
int AMXAPI amx_Execv(AMX *amx, cell *retval, int index, int numparams, cell params[]);
int AMXAPI amx_FindNative(AMX *amx, char *name, int *index);
int AMXAPI amx_FindPublic(AMX *amx, char *funcname, int *index);
int AMXAPI amx_FindPubVar(AMX *amx, char *varname, cell *amx_addr);
int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname);
int AMXAPI amx_Flags(AMX *amx,uint16_t *flags);
int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr);
int AMXAPI amx_GetNative(AMX *amx, int index, char *funcname);
int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname);
int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr);
int AMXAPI amx_GetString(char *dest,cell *source);
int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id);
int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr);
int AMXAPI amx_Init(AMX *amx, void *program);
int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code);
int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap);
int AMXAPI amx_NameLength(AMX *amx, int *length);
AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(char *name,AMX_NATIVE func);
int AMXAPI amx_NumNatives(AMX *amx, int *number);
int AMXAPI amx_NumPublics(AMX *amx, int *number);
int AMXAPI amx_NumPubVars(AMX *amx, int *number);
int AMXAPI amx_NumTags(AMX *amx, int *number);
int AMXAPI amx_RaiseError(AMX *amx, int error);
int AMXAPI amx_Register(AMX *amx, AMX_NATIVE_INFO *nativelist, int number);
int AMXAPI amx_Release(AMX *amx, cell amx_addr);
int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback);
int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug);
int AMXAPI amx_SetString(cell *dest, char *source, int pack);
int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr);
char * AMXAPI amx_StrError(int errnum);
int AMXAPI amx_StrLen(cell *cstring, int *length);
uint16_t *amx_Align16(uint16_t * v);
uint32_t *amx_Align32(uint32_t * v);
int amx_Allot(AMX * amx, int cells, cell * amx_addr,
cell ** phys_addr);
int amx_Callback(AMX * amx, cell index, cell * result,
cell * params);
int amx_Cleanup(AMX * amx);
int amx_Clone(AMX * amxClone, AMX * amxSource, void *data);
int amx_Debug(AMX * amx); /* default debug procedure, does nothing */
int amx_Exec(AMX * amx, cell * retval, int index,
int numparams, ...);
int amx_Execv(AMX * amx, cell * retval, int index,
int numparams, cell params[]);
int amx_FindNative(AMX * amx, char *name, int *index);
int amx_FindPublic(AMX * amx, char *funcname, int *index);
int amx_FindPubVar(AMX * amx, char *varname,
cell * amx_addr);
int amx_FindTagId(AMX * amx, cell tag_id, char *tagname);
int amx_Flags(AMX * amx, uint16_t * flags);
int amx_GetAddr(AMX * amx, cell amx_addr, cell ** phys_addr);
int amx_GetNative(AMX * amx, int index, char *funcname);
int amx_GetPublic(AMX * amx, int index, char *funcname);
int amx_GetPubVar(AMX * amx, int index, char *varname,
cell * amx_addr);
int amx_GetString(char *dest, cell * source);
int amx_GetTag(AMX * amx, int index, char *tagname,
cell * tag_id);
int amx_GetUserData(AMX * amx, long tag, void **ptr);
int amx_Init(AMX * amx, void *program);
int amx_InitJIT(AMX * amx, void *reloc_table,
void *native_code);
int amx_MemInfo(AMX * amx, long *codesize, long *datasize,
long *stackheap);
int amx_NameLength(AMX * amx, int *length);
AMX_NATIVE_INFO *amx_NativeInfo(char *name, AMX_NATIVE func);
int amx_NumNatives(AMX * amx, int *number);
int amx_NumPublics(AMX * amx, int *number);
int amx_NumPubVars(AMX * amx, int *number);
int amx_NumTags(AMX * amx, int *number);
int amx_RaiseError(AMX * amx, int error);
int amx_Register(AMX * amx, AMX_NATIVE_INFO * nativelist,
int number);
int amx_Release(AMX * amx, cell amx_addr);
int amx_SetCallback(AMX * amx, AMX_CALLBACK callback);
int amx_SetDebugHook(AMX * amx, AMX_DEBUG debug);
int amx_SetString(cell * dest, char *source, int pack);
int amx_SetUserData(AMX * amx, long tag, void *ptr);
char *amx_StrError(int errnum);
int amx_StrLen(cell * cstring, int *length);
#if !defined AMX_NO_ALIGN
#if defined LINUX
#pragma pack() /* reset default packing */
#else
#pragma pack(pop) /* reset previous packing */
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif /* __AMX_H */
#endif /* __AMX_H */

View File

@ -1,88 +1,40 @@
/* __MSDOS__ set when compiling for DOS (not Windows)
* _Windows set when compiling for any version of Microsoft Windows
* __WIN32__ set when compiling for Windows95 or WindowsNT (32 bit mode)
* __32BIT__ set when compiling in 32-bit "flat" mode (DOS or Windows)
*
/*
* Copyright 1998-2003, ITB CompuPhase, The Netherlands.
* info@compuphase.com.
*/
#ifndef _OSDEFS_H
#define _OSDEFS_H
#ifndef EMBRYO_CC_OSDEFS_H
# define EMBRYO_CC_OSDEFS_H
/* Every compiler uses different "default" macros to indicate the mode
* it is in. Throughout the source, we use the Borland C++ macros, so
* the macros of Watcom C/C++ and Microsoft Visual C/C++ are mapped to
* those of Borland C++.
*/
#if defined(__WATCOMC__)
# if defined(__WINDOWS__) || defined(__NT__)
# define _Windows 1
# endif
# ifdef __386__
# define __32BIT__ 1
# endif
# if defined(_Windows) && defined(__32BIT__)
# define __WIN32__ 1
# endif
#elif defined(_MSC_VER)
# if defined(_WINDOWS) || defined(_WIN32)
# define _Windows 1
# endif
# ifdef _WIN32
# define __WIN32__ 1
# define __32BIT__ 1
# endif
#endif
#include "embryo_cc_sclinux.h"
#if defined LINUX
#include "config.h"
#endif
/* Linux NOW has these */
#if !defined BIG_ENDIAN
#define BIG_ENDIAN 4321
#endif
#if !defined LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
#endif
/* educated guess, BYTE_ORDER is undefined, i386 is common => little endian */
#ifdef WORDS_BIGENDIAN
# undef BYTE_ORDER
# define BYTE_ORDER BIG_ENDIAN
#else
# undef BYTE_ORDER
# define BYTE_ORDER LITTLE_ENDIAN
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
# ifdef HAVE_STDINT_H
# include <stdint.h>
# endif
/* _MAX_PATH is sometimes called differently and it may be in limits.h instead
* stdio.h.
*/
#if !defined _MAX_PATH
/* not defined, perhaps stdio.h was not included */
#include <stdio.h>
#if !defined _MAX_PATH
/* still undefined, try a common alternative name */
#if defined MAX_PATH
#define _MAX_PATH MAX_PATH
#else
/* no _MAX_PATH and no MAX_PATH, perhaps it is in limits.h */
#include <limits.h>
#if defined PATH_MAX
#define _MAX_PATH PATH_MAX
#elif defined _POSIX_PATH_MAX
#define _MAX_PATH _POSIX_PATH_MAX
#else
/* everything failed, actually we have a problem here... */
#define _MAX_PATH 1024
#endif
#endif
#endif
#endif
# if !defined _MAX_PATH
/* not defined, perhaps stdio.h was not included */
# include <stdio.h>
# if !defined _MAX_PATH
/* still undefined, try a common alternative name */
# if defined MAX_PATH
# define _MAX_PATH MAX_PATH
# else
/* no _MAX_PATH and no MAX_PATH, perhaps it is in limits.h */
# include <limits.h>
# if defined PATH_MAX
# define _MAX_PATH PATH_MAX
# elif defined _POSIX_PATH_MAX
# define _MAX_PATH _POSIX_PATH_MAX
# else
/* everything failed, actually we have a problem here... */
# define _MAX_PATH 4096
# endif
# endif
# endif
# endif
#endif /* _OSDEFS_H */
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -21,35 +21,16 @@
*
* Version: $Id$
*/
#include <assert.h>
#if defined __WIN32__ || defined _WIN32 || defined __MSDOS__
#include <io.h>
#endif
#if defined LINUX || defined __GNUC__
#include <unistd.h>
#endif
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h> /* ANSI standardized variable argument list functions */
#include <stdarg.h>
#include <string.h>
#if defined FORTIFY
#include "fortify.h"
#endif
#include "embryo_cc_sc.h"
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable:4125) /* decimal digit terminates octal escape sequence */
#endif
#include "embryo_cc_sc5.scp"
#if defined _MSC_VER
#pragma warning(pop)
#endif
static int errflag;
static int errstart; /* line number at which the instruction started */
static int errstart; /* line number at which the instruction started */
/* error
*
@ -63,103 +44,122 @@ static int errstart; /* line number at which the instruction started */
* fcurrent (reffered to only)
* errflag (altered)
*/
SC_FUNC int error(int number,...)
int
error(int number, ...)
{
static char *prefix[3]={ "error", "fatal error", "warning" };
static int lastline,lastfile,errorcount;
char *msg,*pre;
va_list argptr;
char string[128];
static char *prefix[3] = { "error", "fatal error", "warning" };
static int lastline, lastfile, errorcount;
char *msg, *pre;
va_list argptr;
char string[1024];
/* errflag is reset on each semicolon.
* In a two-pass compiler, an error should not be reported twice. Therefore
* the error reporting is enabled only in the second pass (and only when
* actually producing output). Fatal errors may never be ignored.
*/
if ((errflag || sc_status!=statWRITE) && (number<100 || number>=200))
return 0;
/* errflag is reset on each semicolon.
* In a two-pass compiler, an error should not be reported twice. Therefore
* the error reporting is enabled only in the second pass (and only when
* actually producing output). Fatal errors may never be ignored.
*/
if (((errflag) || (sc_status != statWRITE)) &&
((number < 100) || (number >= 200)))
return 0;
if (number < 100)
{
msg = errmsg[number - 1];
pre = prefix[0];
errflag = TRUE; /* set errflag (skip rest of erroneous expression) */
errnum++;
}
else if (number < 200)
{
msg = fatalmsg[number - 100];
pre = prefix[1];
errnum++; /* a fatal error also counts as an error */
}
else
{
msg = warnmsg[number - 200];
pre = prefix[2];
warnnum++;
}
if (number<100){
msg=errmsg[number-1];
pre=prefix[0];
errflag=TRUE; /* set errflag (skip rest of erroneous expression) */
errnum++;
} else if (number<200){
msg=fatalmsg[number-100];
pre=prefix[1];
errnum++; /* a fatal error also counts as an error */
} else {
msg=warnmsg[number-200];
pre=prefix[2];
warnnum++;
} /* if */
strexpand(string, (unsigned char *)msg, sizeof string, SCPACK_TABLE);
strexpand(string,(unsigned char *)msg,sizeof string,SCPACK_TABLE);
va_start(argptr, number);
if (strlen(errfname) == 0)
{
int start = (errstart == fline) ? -1 : errstart;
assert(errstart<=fline);
va_start(argptr,number);
if (strlen(errfname)==0) {
int start= (errstart==fline) ? -1 : errstart;
if (sc_error(number,string,inpfname,start,fline,argptr)) {
sc_closeasm(outf,TRUE);
outf=NULL;
longjmp(errbuf,3); /* user abort */
} /* if */
} else {
FILE *fp=fopen(errfname,"at");
if (fp!=NULL) {
if (errstart>=0 && errstart!=fline)
fprintf(fp,"%s(%d -- %d) : %s %03d: ",inpfname,errstart,fline,pre,number);
else
fprintf(fp,"%s(%d) : %s %03d: ",inpfname,fline,pre,number);
vfprintf(fp,string,argptr);
fclose(fp);
} /* if */
} /* if */
va_end(argptr);
if (sc_error(number, string, inpfname, start, fline, argptr))
{
sc_closeasm(outf, TRUE);
outf = NULL;
longjmp(errbuf, 3);
}
}
else
{
FILE *fp;
fp = fopen(errfname, "at");
if (fp != NULL)
{
if (errstart >= 0 && errstart != fline)
fprintf(fp, "%s(%d -- %d) : %s %03d: ", inpfname, errstart, fline, pre, number);
else
fprintf(fp, "%s(%d) : %s %03d: ", inpfname, fline, pre, number);
vfprintf(fp, string, argptr);
fclose(fp);
}
}
va_end(argptr);
if (number>=100 && number<200 || errnum>25){
if (strlen(errfname)==0) {
va_start(argptr,number);
sc_error(0,"\nCompilation aborted.",NULL,0,0,argptr);
va_end(argptr);
} /* if */
if (outf!=NULL) {
sc_closeasm(outf,TRUE);
outf=NULL;
} /* if */
longjmp(errbuf,2); /* fatal error, quit */
} /* if */
if (((number >= 100) && (number < 200)) || (errnum > 250))
{
if (strlen(errfname) == 0)
{
va_start(argptr, number);
sc_error(0, "\nCompilation aborted.", NULL, 0, 0, argptr);
va_end(argptr);
} /* if */
if (outf != NULL)
{
sc_closeasm(outf, TRUE);
outf = NULL;
} /* if */
longjmp(errbuf, 2); /* fatal error, quit */
} /* if */
/* check whether we are seeing many errors on the same line */
if ((errstart<0 && lastline!=fline) || lastline<errstart || lastline>fline || fcurrent!=lastfile)
errorcount=0;
lastline=fline;
lastfile=fcurrent;
if (number<200)
errorcount++;
if (errorcount>=3)
error(107); /* too many error/warning messages on one line */
return 0;
/* check whether we are seeing many errors on the same line */
if (((errstart < 0) && (lastline != fline)) ||
(lastline < errstart) || (lastline > fline) || (fcurrent != lastfile))
errorcount = 0;
lastline = fline;
lastfile = fcurrent;
if (number < 200)
errorcount++;
if (errorcount >= 3)
error(107); /* too many error/warning messages on one line */
return 0;
}
SC_FUNC void errorset(int code)
void
errorset(int code)
{
switch (code) {
case sRESET:
errflag=FALSE; /* start reporting errors */
break;
case sFORCESET:
errflag=TRUE; /* stop reporting errors */
break;
case sEXPRMARK:
errstart=fline; /* save start line number */
break;
case sEXPRRELEASE:
errstart=-1; /* forget start line number */
break;
} /* switch */
switch (code)
{
case sRESET:
errflag = FALSE; /* start reporting errors */
break;
case sFORCESET:
errflag = TRUE; /* stop reporting errors */
break;
case sEXPRMARK:
errstart = fline; /* save start line number */
break;
case sEXPRRELEASE:
errstart = -1; /* forget start line number */
break;
default:
break;
}
}
#undef SCPACK_TABLE

View File

@ -21,263 +21,297 @@
* Version: $Id$
*/
SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]);
SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen,
unsigned char pairtable[128][2]);
#define SCPACK_TABLE errstr_table
/*-*SCPACK start of pair table, do not change or remove this line */
unsigned char errstr_table[][2] = {
{101,32}, {116,32}, {111,110}, {105,110}, {97,114}, {100,32}, {105,130}, {101,114}, {101,110}, {115,32}, {97,108}, {97,116}, {117,110}, {115,34}, {37,141}, {34,142},
{109,136}, {121,32}, {97,110}, {114,101}, {99,116}, {134,32}, {110,111}, {101,133}, {118,138}, {115,105}, {98,108}, {111,114}, {115,116}, {41,10}, {109,98}, {100,101},
{117,115}, {150,129}, {102,140}, {117,144}, {162,148}, {103,163}, {132,165}, {114,97}, {105,133}, {152,168}, {99,104}, {32,143}, {97,32}, {131,169}, {97,115}, {164,149},
{111,108}, {101,120}, {97,154}, {135,32}, {132,167}, {111,102}, {105,116}, {166,129}, {101,100}, {98,128}, {178,128}, {160,129}, {105,137}, {180,145}, {121,158}, {190,176},
{109,187}, {115,191}, {118,132}, {101,10}, {115,10}, {112,147}, {155,32}, {181,32}, {159,102}, {194,105}, {99,130}, {103,32}, {201,186}, {116,111}, {34,32}, {109,97},
{153,122}, {171,10}, {104,97}, {100,105}, {108,111}, {111,112}, {200,131}, {139,134}, {213,135}, {101,137}, {202,156}, {143,157}, {138,32}, {192,185}, {58,209}, {105,99},
{112,111}, {115,115}, {110,117}, {115,117}, {146,129}, {226,158}, {229,179}, {177,197}, {231,225}, {132,97}, {98,101}, {99,111}, {216,139}, {109,139}, {116,10}, {99,146},
{44,32}, {237,170}, {131,203}, {116,104}, {117,108}, {152,117}, {108,128}, {118,128}, {101,144}, {233,148}, {174,153}, {110,32}, {131,32}, {146,32}, {239,161}
unsigned char errstr_table[][2] = {
{101, 32}, {116, 32}, {111, 110}, {105, 110}, {97, 114}, {100, 32}, {105,
130},
{101, 114}, {101, 110}, {115, 32}, {97, 108}, {97, 116}, {117, 110}, {115,
34},
{37, 141}, {34, 142},
{109, 136}, {121, 32}, {97, 110}, {114, 101}, {99, 116}, {134, 32}, {110,
111},
{101, 133}, {118, 138}, {115, 105}, {98, 108}, {111, 114}, {115, 116},
{41, 10}, {109, 98}, {100, 101},
{117, 115}, {150, 129}, {102, 140}, {117, 144}, {162, 148}, {103, 163}, {132,
165},
{114, 97}, {105, 133}, {152, 168}, {99, 104}, {32, 143}, {97, 32}, {131,
169},
{97, 115}, {164, 149},
{111, 108}, {101, 120}, {97, 154}, {135, 32}, {132, 167}, {111, 102}, {105,
116},
{166, 129}, {101, 100}, {98, 128}, {178, 128}, {160, 129}, {105, 137},
{180, 145}, {121, 158}, {190, 176},
{109, 187}, {115, 191}, {118, 132}, {101, 10}, {115, 10}, {112, 147}, {155,
32},
{181, 32}, {159, 102}, {194, 105}, {99, 130}, {103, 32}, {201, 186}, {116,
111},
{34, 32}, {109, 97},
{153, 122}, {171, 10}, {104, 97}, {100, 105}, {108, 111}, {111, 112}, {200,
131},
{139, 134}, {213, 135}, {101, 137}, {202, 156}, {143, 157}, {138, 32},
{192, 185}, {58, 209}, {105, 99},
{112, 111}, {115, 115}, {110, 117}, {115, 117}, {146, 129}, {226, 158}, {229,
179},
{177, 197}, {231, 225}, {132, 97}, {98, 101}, {99, 111}, {216, 139}, {109,
139},
{116, 10}, {99, 146},
{44, 32}, {237, 170}, {131, 203}, {116, 104}, {117, 108}, {152, 117}, {108,
128},
{118, 128}, {101, 144}, {233, 148}, {174, 153}, {110, 32}, {131, 32},
{146, 32}, {239, 161}
};
/*-*SCPACK end of pair table, do not change or remove this line */
static char *errmsg[] = {
static char *errmsg[] = {
#ifdef SCPACK
/*001*/ "expected token: \"%s\", but found \"%s\"\n",
/*002*/ "only a single statement (or expression) can follow each \"case\"\n",
/*003*/ "declaration of a local variable must appear in a compound block\n",
/*004*/ "function \"%s\" is not implemented\n",
/*005*/ "function may not have arguments\n",
/*006*/ "must be assigned to an array\n",
/*007*/ "assertion failed\n",
/*008*/ "must be a constant expression; assumed zero\n",
/*009*/ "invalid array size (negative or zero)\n",
/*010*/ "invalid function or declaration\n",
/*011*/ "invalid outside functions\n",
/*012*/ "invalid function call, not a valid address\n",
/*013*/ "no entry point (no public functions)\n",
/*014*/ "invalid statement; not in switch\n",
/*015*/ "\"default\" case must be the last case in switch statement\n",
/*016*/ "multiple defaults in \"switch\"\n",
/*017*/ "undefined symbol \"%s\"\n",
/*018*/ "initialization data exceeds declared size\n",
/*019*/ "not a label: \"%s\"\n",
/*020*/ "invalid symbol name \"%s\"\n",
/*021*/ "symbol already defined: \"%s\"\n",
/*022*/ "must be lvalue (non-constant)\n",
/*023*/ "array assignment must be simple assignment\n",
/*024*/ "\"break\" or \"continue\" is out of context\n",
/*025*/ "function heading differs from prototype\n",
/*026*/ "no matching \"#if...\"\n",
/*027*/ "invalid character constant\n",
/*028*/ "invalid subscript (not an array or too many subscripts)\n",
/*029*/ "invalid expression, assumed zero\n",
/*030*/ "compound statement not closed at the end of file\n",
/*031*/ "unknown directive\n",
/*032*/ "array index out of bounds (variable \"%s\")\n",
/*033*/ "array must be indexed (variable \"%s\")\n",
/*034*/ "argument does not have a default value (argument %d)\n",
/*035*/ "argument type mismatch (argument %d)\n",
/*036*/ "empty statement\n",
/*037*/ "invalid string (possibly non-terminated string)\n",
/*038*/ "extra characters on line\n",
/*039*/ "constant symbol has no size\n",
/*040*/ "duplicate \"case\" label (value %d)\n",
/*041*/ "invalid ellipsis, array size is not known\n",
/*042*/ "invalid combination of class specifiers\n",
/*043*/ "character constant exceeds range for packed string\n",
/*044*/ "positional parameters must precede all named parameters\n",
/*045*/ "too many function arguments\n",
/*046*/ "unknown array size (variable \"%s\")\n",
/*047*/ "array sizes must match\n",
/*048*/ "array dimensions must match\n",
/*049*/ "invalid line continuation\n",
/*050*/ "invalid range\n",
/*051*/ "invalid subscript, use \"[ ]\" operators on major dimensions\n",
/*052*/ "only the last dimension may be variable length\n",
/*053*/ "exceeding maximum number of dimensions\n",
/*054*/ "unmatched closing brace\n",
/*055*/ "start of function body without function header\n",
/*056*/ "arrays, local variables and function arguments cannot be public (variable \"%s\")\n",
/*057*/ "unfinished expression before compiler directive\n",
/*058*/ "duplicate argument; same argument is passed twice\n",
/*059*/ "function argument may not have a default value (variable \"%s\")\n",
/*060*/ "multiple \"#else\" directives between \"#if ... #endif\"\n",
/*061*/ "operator cannot be redefined\n",
/*062*/ "number of operands does not fit the operator\n",
/*063*/ "function result tag of operator \"%s\" must be \"%s\"\n",
/*064*/ "cannot change predefined operators\n",
/*065*/ "function argument may only have a single tag (argument %d)\n",
/*066*/ "function argument may not be a reference argument or an array (argument \"%s\")\n",
/*067*/ "variable cannot be both a reference and an array (variable \"%s\")\n",
/*068*/ "invalid rational number precision in #pragma\n",
/*069*/ "rational number format already defined\n",
/*070*/ "rational number support was not enabled\n",
/*071*/ "user-defined operator must be declared before use (function \"%s\")\n",
/*072*/ "\"sizeof\" operator is invalid on \"function\" symbols\n",
/*073*/ "function argument must be an array (argument \"%s\")\n",
/*074*/ "#define pattern must start with an alphabetic character\n",
/*075*/ "input line too long (after substitutions)\n"
/*001*/ "expected token: \"%s\", but found \"%s\"\n",
/*002*/ "only a single statement (or expression) can follow each \"case\"\n",
/*003*/ "declaration of a local variable must appear in a compound block\n",
/*004*/ "function \"%s\" is not implemented\n",
/*005*/ "function may not have arguments\n",
/*006*/ "must be assigned to an array\n",
/*007*/ "assertion failed\n",
/*008*/ "must be a constant expression; assumed zero\n",
/*009*/ "invalid array size (negative or zero)\n",
/*010*/ "invalid function or declaration\n",
/*011*/ "invalid outside functions\n",
/*012*/ "invalid function call, not a valid address\n",
/*013*/ "no entry point (no public functions)\n",
/*014*/ "invalid statement; not in switch\n",
/*015*/ "\"default\" case must be the last case in switch statement\n",
/*016*/ "multiple defaults in \"switch\"\n",
/*017*/ "undefined symbol \"%s\"\n",
/*018*/ "initialization data exceeds declared size\n",
/*019*/ "not a label: \"%s\"\n",
/*020*/ "invalid symbol name \"%s\"\n",
/*021*/ "symbol already defined: \"%s\"\n",
/*022*/ "must be lvalue (non-constant)\n",
/*023*/ "array assignment must be simple assignment\n",
/*024*/ "\"break\" or \"continue\" is out of context\n",
/*025*/ "function heading differs from prototype\n",
/*026*/ "no matching \"#if...\"\n",
/*027*/ "invalid character constant\n",
/*028*/ "invalid subscript (not an array or too many subscripts)\n",
/*029*/ "invalid expression, assumed zero\n",
/*030*/ "compound statement not closed at the end of file\n",
/*031*/ "unknown directive\n",
/*032*/ "array index out of bounds (variable \"%s\")\n",
/*033*/ "array must be indexed (variable \"%s\")\n",
/*034*/ "argument does not have a default value (argument %d)\n",
/*035*/ "argument type mismatch (argument %d)\n",
/*036*/ "empty statement\n",
/*037*/ "invalid string (possibly non-terminated string)\n",
/*038*/ "extra characters on line\n",
/*039*/ "constant symbol has no size\n",
/*040*/ "duplicate \"case\" label (value %d)\n",
/*041*/ "invalid ellipsis, array size is not known\n",
/*042*/ "invalid combination of class specifiers\n",
/*043*/ "character constant exceeds range for packed string\n",
/*044*/ "positional parameters must precede all named parameters\n",
/*045*/ "too many function arguments\n",
/*046*/ "unknown array size (variable \"%s\")\n",
/*047*/ "array sizes must match\n",
/*048*/ "array dimensions must match\n",
/*049*/ "invalid line continuation\n",
/*050*/ "invalid range\n",
/*051*/ "invalid subscript, use \"[ ]\" operators on major dimensions\n",
/*052*/ "only the last dimension may be variable length\n",
/*053*/ "exceeding maximum number of dimensions\n",
/*054*/ "unmatched closing brace\n",
/*055*/ "start of function body without function header\n",
/*056*/
"arrays, local variables and function arguments cannot be public (variable \"%s\")\n",
/*057*/ "unfinished expression before compiler directive\n",
/*058*/ "duplicate argument; same argument is passed twice\n",
/*059*/ "function argument may not have a default value (variable \"%s\")\n",
/*060*/ "multiple \"#else\" directives between \"#if ... #endif\"\n",
/*061*/ "operator cannot be redefined\n",
/*062*/ "number of operands does not fit the operator\n",
/*063*/ "function result tag of operator \"%s\" must be \"%s\"\n",
/*064*/ "cannot change predefined operators\n",
/*065*/ "function argument may only have a single tag (argument %d)\n",
/*066*/
"function argument may not be a reference argument or an array (argument \"%s\")\n",
/*067*/
"variable cannot be both a reference and an array (variable \"%s\")\n",
/*068*/ "invalid rational number precision in #pragma\n",
/*069*/ "rational number format already defined\n",
/*070*/ "rational number support was not enabled\n",
/*071*/
"user-defined operator must be declared before use (function \"%s\")\n",
/*072*/ "\"sizeof\" operator is invalid on \"function\" symbols\n",
/*073*/ "function argument must be an array (argument \"%s\")\n",
/*074*/ "#define pattern must start with an alphabetic character\n",
/*075*/ "input line too long (after substitutions)\n"
#else
"\261pe\224\227\315k\210:\253\360bu\201fo\214\205\217\012",
"\202l\221\254s\203g\366\234\213\370\201(\306\350\206) \357 f\260\324w ea\252 \042c\256e\042\012",
"\237cl\204\213\225\307\254\324c\334\314\300appe\204 \374\254\353m\340\214\205\232ock\012",
"\257\217 \274\241impl\370t\270\012",
"\257\317\221\241\322\367\246t\304",
"\335\372gn\227\315 \375\264y\012",
"\256s\207t\225fail\270\012",
"\335\254\332\344\350\206; \256\343m\227z\207o\012",
"\255\275\320\200(neg\213i\367\306z\207o\235",
"\255\257\306\237cl\204\327\012",
"\255out\231d\200\244\206\304",
"\255\257c\212l\360\241\254\251add\223s\304",
"\226 \210tr\221\340\203\201(\226 pu\232\337 \244\206s\235",
"\255\234\213\370t; \241\374sw\266\252\012",
"\042\310a\364t\316c\256\200\335\363\200l\256\201c\256\200\374sw\266\252 \234\213\370\356",
"m\364tip\366\310a\364t\211\374\042sw\266\252\042\012",
"\214\326\227\301\321",
"\203\266i\212iz\213\225d\213\254\261ce\270\211\237cl\204\227\320\303",
"\241\254la\352l\336",
"\255\301 nam\200\217\012",
"\301 \212\223ad\221\326\270\336",
"\335l\365\200(n\202-\332\222t\235",
"\275\372gn\220\201\335\231mp\366\372gn\220\356",
"\042b\223ak\316\306\042\312t\203ue\316\274ou\201\307\312t\261\356",
"\257head\362\323ff\207\211from pro\315typ\303",
"\226 \361\362\042#if...\042\012",
"\255\252\371\263\332\222\356",
"\255\343bscrip\201(\241\375\275\306\315o m\222\221\343bscripts\235",
"\255\350\206\360\256\343m\227z\207o\012",
"\353m\340\214\205\234\213\370\201\241c\324s\227a\201\363\200\210\205\307fil\303",
"\214k\226w\373\323\223\224iv\303",
"\275\203\237x ou\201\307bo\214d\211(\314\333",
"\275\335\203\237x\227(\314\333",
"\267do\331\241\322\367\254\310a\364\201\365\200(\267%d\235",
"\267typ\200mis\361 (\267%d\235",
"empt\221\234\213\370\356",
"\255\234r\362(\340s\231\232\221n\202-t\207m\203\213\227\234r\203g\235",
"\261t\247 \252\371\207\211\202 l\203\303",
"\332\344\301 \322\211\226 \320\303",
"dupl\337\213\200\042c\256e\316la\352l (\365\200%d\235",
"\255ellip\231s\360\275\320\200\274\241k\226wn\012",
"\255\353\236\203\213\225\307cl\256\211specifi\207\304",
"\252\371\263\332\344\261ce\270\211r\222g\200f\306pack\227\234r\203g\012",
"\340\231t\206\334p\351met\207\211\300\305c\270\200\212l nam\227p\351met\207\304",
"\315o m\222\221\257\246t\304",
"\214k\226w\373\275\320\200(\314\333",
"\275\320\331\300\361\012",
"\275\323\220s\206\211\300\361\012",
"\255l\203\200\312t\203u\327\012",
"\255r\222g\303",
"\255\343bscript\360\240\200\042[ ]\316\354\233\211\202 \317j\306\323\220s\206\304",
"\202l\221\363\200l\256\201\323\220s\225\317\221\271\314l\210g\363\012",
"\261ce\270\362\317ximum \346\307\323\220s\206\304",
"\214\361\227c\324s\362b\247c\303",
"\234\204\201\307\257bod\221w\266hou\201\257head\207\012",
"\264ys\360\324c\334\311\262\331\222\205\257\246t\211\376\271pu\232\337 (\314\333",
"\214f\203ish\227\350\225\352f\233\200\353mpil\263\323\223\224iv\303",
"dupl\337\213\200\246t; sam\200\267\274p\256s\227tw\337\303",
"\257\267\317\221\241\322\367\254\310a\364\201\365\200(\314\333",
"m\364tip\366\042#else\316\323\223\224iv\331\352twe\210 \042#if ... #\210\323f\042\012",
"\354\306\376\271\223\326\270\012",
"\346\307\330\222d\211do\331\241fi\201\363\200\354\233\012",
"\257\223\343l\201ta\313\307\354\233\253 \335\217\012",
"\376\252\222g\200\305\326\227\354\233\304",
"\257\267\317\221\202l\221\322\367\254s\203g\366ta\313(\267%d\235",
"\257\267\317\221\241\271\254\223f\207\210c\200\267\306\375\275(\267\333",
"\314\376\271bo\363 \254\223f\207\210c\200\222\205\375\275(\314\333",
"\255r\327\334\346\305cis\225\374#p\247g\317\012",
"r\327\334\346f\233\317\201\212\223ad\221\326\270\012",
"r\327\334\346\343pp\233\201wa\211\241\210\262\270\012",
"\240\207-\326\227\354\306\335\237cl\204\227\352f\233\200\240\200(\257\333",
"\042\320e\265\316\354\306\274\255\202 \042\244\206\316\301\304",
"\257\267\335\375\275(\267\333",
"#\326\200p\213t\207\373\300\234\204\201w\266h \375\212p\322\352t\337 \252\371\207\012",
"\203pu\201l\203\200\315o l\202\313(aft\263\343b\234\266ut\206s\235"
"\261pe\224\227\315k\210:\253\360bu\201fo\214\205\217\012",
"\202l\221\254s\203g\366\234\213\370\201(\306\350\206) \357 f\260\324w ea\252 \042c\256e\042\012",
"\237cl\204\213\225\307\254\324c\334\314\300appe\204 \374\254\353m\340\214\205\232ock\012",
"\257\217 \274\241impl\370t\270\012",
"\257\317\221\241\322\367\246t\304",
"\335\372gn\227\315 \375\264y\012",
"\256s\207t\225fail\270\012",
"\335\254\332\344\350\206; \256\343m\227z\207o\012",
"\255\275\320\200(neg\213i\367\306z\207o\235",
"\255\257\306\237cl\204\327\012",
"\255out\231d\200\244\206\304",
"\255\257c\212l\360\241\254\251add\223s\304",
"\226 \210tr\221\340\203\201(\226 pu\232\337 \244\206s\235",
"\255\234\213\370t; \241\374sw\266\252\012",
"\042\310a\364t\316c\256\200\335\363\200l\256\201c\256\200\374sw\266\252 \234\213\370\356",
"m\364tip\366\310a\364t\211\374\042sw\266\252\042\012",
"\214\326\227\301\321",
"\203\266i\212iz\213\225d\213\254\261ce\270\211\237cl\204\227\320\303",
"\241\254la\352l\336",
"\255\301 nam\200\217\012",
"\301 \212\223ad\221\326\270\336",
"\335l\365\200(n\202-\332\222t\235",
"\275\372gn\220\201\335\231mp\366\372gn\220\356",
"\042b\223ak\316\306\042\312t\203ue\316\274ou\201\307\312t\261\356",
"\257head\362\323ff\207\211from pro\315typ\303",
"\226 \361\362\042#if...\042\012",
"\255\252\371\263\332\222\356",
"\255\343bscrip\201(\241\375\275\306\315o m\222\221\343bscripts\235",
"\255\350\206\360\256\343m\227z\207o\012",
"\353m\340\214\205\234\213\370\201\241c\324s\227a\201\363\200\210\205\307fil\303",
"\214k\226w\373\323\223\224iv\303",
"\275\203\237x ou\201\307bo\214d\211(\314\333",
"\275\335\203\237x\227(\314\333",
"\267do\331\241\322\367\254\310a\364\201\365\200(\267%d\235",
"\267typ\200mis\361 (\267%d\235",
"empt\221\234\213\370\356",
"\255\234r\362(\340s\231\232\221n\202-t\207m\203\213\227\234r\203g\235",
"\261t\247 \252\371\207\211\202 l\203\303",
"\332\344\301 \322\211\226 \320\303",
"dupl\337\213\200\042c\256e\316la\352l (\365\200%d\235",
"\255ellip\231s\360\275\320\200\274\241k\226wn\012",
"\255\353\236\203\213\225\307cl\256\211specifi\207\304",
"\252\371\263\332\344\261ce\270\211r\222g\200f\306pack\227\234r\203g\012",
"\340\231t\206\334p\351met\207\211\300\305c\270\200\212l nam\227p\351met\207\304",
"\315o m\222\221\257\246t\304",
"\214k\226w\373\275\320\200(\314\333",
"\275\320\331\300\361\012",
"\275\323\220s\206\211\300\361\012",
"\255l\203\200\312t\203u\327\012",
"\255r\222g\303",
"\255\343bscript\360\240\200\042[ ]\316\354\233\211\202 \317j\306\323\220s\206\304",
"\202l\221\363\200l\256\201\323\220s\225\317\221\271\314l\210g\363\012",
"\261ce\270\362\317ximum \346\307\323\220s\206\304",
"\214\361\227c\324s\362b\247c\303",
"\234\204\201\307\257bod\221w\266hou\201\257head\207\012",
"\264ys\360\324c\334\311\262\331\222\205\257\246t\211\376\271pu\232\337 (\314\333",
"\214f\203ish\227\350\225\352f\233\200\353mpil\263\323\223\224iv\303",
"dupl\337\213\200\246t; sam\200\267\274p\256s\227tw\337\303",
"\257\267\317\221\241\322\367\254\310a\364\201\365\200(\314\333",
"m\364tip\366\042#else\316\323\223\224iv\331\352twe\210 \042#if ... #\210\323f\042\012",
"\354\306\376\271\223\326\270\012",
"\346\307\330\222d\211do\331\241fi\201\363\200\354\233\012",
"\257\223\343l\201ta\313\307\354\233\253 \335\217\012",
"\376\252\222g\200\305\326\227\354\233\304",
"\257\267\317\221\202l\221\322\367\254s\203g\366ta\313(\267%d\235",
"\257\267\317\221\241\271\254\223f\207\210c\200\267\306\375\275(\267\333",
"\314\376\271bo\363 \254\223f\207\210c\200\222\205\375\275(\314\333",
"\255r\327\334\346\305cis\225\374#p\247g\317\012",
"r\327\334\346f\233\317\201\212\223ad\221\326\270\012",
"r\327\334\346\343pp\233\201wa\211\241\210\262\270\012",
"\240\207-\326\227\354\306\335\237cl\204\227\352f\233\200\240\200(\257\333",
"\042\320e\265\316\354\306\274\255\202 \042\244\206\316\301\304",
"\257\267\335\375\275(\267\333",
"#\326\200p\213t\207\373\300\234\204\201w\266h \375\212p\322\352t\337 \252\371\207\012",
"\203pu\201l\203\200\315o l\202\313(aft\263\343b\234\266ut\206s\235"
#endif
};
};
static char *fatalmsg[] = {
static char *fatalmsg[] = {
#ifdef SCPACK
/*100*/ "cannot read from file: \"%s\"\n",
/*101*/ "cannot write to file: \"%s\"\n",
/*102*/ "table overflow: \"%s\"\n",
/* table can be: loop table
* literal table
* staging buffer
* parser stack (recursive include?)
* option table (response file)
* peephole optimizer table
*/
/*103*/ "insufficient memory\n",
/*104*/ "invalid assembler instruction \"%s\"\n",
/*105*/ "numeric overflow, exceeding capacity\n",
/*106*/ "compaction buffer overflow\n",
/*107*/ "too many error messages on one line\n"
/*100*/ "cannot read from file: \"%s\"\n",
/*101*/ "cannot write to file: \"%s\"\n",
/*102*/ "table overflow: \"%s\"\n",
/* table can be: loop table
* literal table
* staging buffer
* parser stack (recursive include?)
* option table (response file)
* peephole optimizer table
*/
/*103*/ "insufficient memory\n",
/*104*/ "invalid assembler instruction \"%s\"\n",
/*105*/ "numeric overflow, exceeding capacity\n",
/*106*/ "compaction buffer overflow\n",
/*107*/ "too many error messages on one line\n"
#else
"\376\223a\205from file\336",
"\376wr\266\200\315 file\336",
"t\272ov\207f\324w\336",
"\203\343ff\337i\210\201mem\233y\012",
"\255\256sem\232\263\203\234ru\224\225\217\012",
"\342m\207\337 ov\207f\324w\360\261ce\270\362capac\266y\012",
"\353mpa\224\225buff\263ov\207f\324w\012",
"\315o m\222\221\207r\306me\341ag\331\202 \202\200l\203\303"
"\376\223a\205from file\336",
"\376wr\266\200\315 file\336",
"t\272ov\207f\324w\336",
"\203\343ff\337i\210\201mem\233y\012",
"\255\256sem\232\263\203\234ru\224\225\217\012",
"\342m\207\337 ov\207f\324w\360\261ce\270\362capac\266y\012",
"\353mpa\224\225buff\263ov\207f\324w\012",
"\315o m\222\221\207r\306me\341ag\331\202 \202\200l\203\303"
#endif
};
};
static char *warnmsg[] = {
static char *warnmsg[] = {
#ifdef SCPACK
/*200*/ "symbol \"%s\" is truncated to %d characters\n",
/*201*/ "redefinition of constant/macro (symbol \"%s\")\n",
/*202*/ "number of arguments does not match definition\n",
/*203*/ "symbol is never used: \"%s\"\n",
/*204*/ "symbol is assigned a value that is never used: \"%s\"\n",
/*205*/ "redundant code: constant expression is zero\n",
/*206*/ "redundant test: constant expression is non-zero\n",
/*207*/ "unknown #pragma\n",
/*208*/ "function uses both \"return;\" and \"return <value>;\"\n",
/*209*/ "function \"%s\" should return a value\n",
/*210*/ "possible use of symbol before initialization: \"%s\"\n",
/*211*/ "possibly unintended assignment\n",
/*212*/ "possibly unintended bitwise operation\n",
/*213*/ "tag mismatch\n",
/*214*/ "possibly a \"const\" array argument was intended: \"%s\"\n",
/*215*/ "expression has no effect\n",
/*216*/ "nested comment\n",
/*217*/ "loose indentation\n",
/*218*/ "old style prototypes used with optional semicolumns\n",
/*219*/ "local variable \"%s\" shadows a variable at a preceding level\n",
/*220*/ "exported or native symbol \"%s\" is truncated to %d characters\n",
/*221*/ "label name \"%s\" shadows tag name\n",
/*222*/ "number of digits exceeds rational number precision\n",
/*223*/ "redundant \"sizeof\": argument size is always 1 (symbol \"%s\")\n",
/*224*/ "indeterminate array size in \"sizeof\" expression (symbol \"%s\")\n",
/*225*/ "unreachable code\n",
/*226*/ "a variable is assigned to itself (symbol \"%s\")\n"
/*200*/ "symbol \"%s\" is truncated to %d characters\n",
/*201*/ "redefinition of constant/macro (symbol \"%s\")\n",
/*202*/ "number of arguments does not match definition\n",
/*203*/ "symbol is never used: \"%s\"\n",
/*204*/ "symbol is assigned a value that is never used: \"%s\"\n",
/*205*/ "redundant code: constant expression is zero\n",
/*206*/ "redundant test: constant expression is non-zero\n",
/*207*/ "unknown #pragma\n",
/*208*/ "function uses both \"return;\" and \"return <value>;\"\n",
/*209*/ "function \"%s\" should return a value\n",
/*210*/ "possible use of symbol before initialization: \"%s\"\n",
/*211*/ "possibly unintended assignment\n",
/*212*/ "possibly unintended bitwise operation\n",
/*213*/ "tag mismatch\n",
/*214*/ "possibly a \"const\" array argument was intended: \"%s\"\n",
/*215*/ "expression has no effect\n",
/*216*/ "nested comment\n",
/*217*/ "loose indentation\n",
/*218*/ "old style prototypes used with optional semicolumns\n",
/*219*/ "local variable \"%s\" shadows a variable at a preceding level\n",
/*220*/ "exported or native symbol \"%s\" is truncated to %d characters\n",
/*221*/ "label name \"%s\" shadows tag name\n",
/*222*/ "number of digits exceeds rational number precision\n",
/*223*/ "redundant \"sizeof\": argument size is always 1 (symbol \"%s\")\n",
/*224*/
"indeterminate array size in \"sizeof\" expression (symbol \"%s\")\n",
/*225*/ "unreachable code\n",
/*226*/ "a variable is assigned to itself (symbol \"%s\")\n"
#else
"\301\253 \274tr\214c\213\227\315 %\205\252\371\207\304",
"\223\326\266\225\307\332\222t/\317cro (\301\253\235",
"\346\307\246t\211do\331\241\361 \326\266\206\012",
"\301 \274nev\263\240\270\336",
"\301 \274\372gn\227\254\365\200t\322\201\274nev\263\240\270\336",
"\223d\214d\344\353\237: \332\344\350\225\274z\207o\012",
"\223d\214d\344te\234: \332\344\350\225\274n\202-z\207o\012",
"\214k\226w\373#p\247g\317\012",
"\257\240\331bo\363 \042\223turn;\316\222\205\042\223tur\373<\365e>;\042\012",
"\257\217 sho\364\205\223tur\373\254\365\303",
"\340s\231\232\200\240\200\307\301 \352f\233\200\203\266i\212iz\327\336",
"\340s\231\232\221\214\203t\210d\227\372gn\220\356",
"\340s\231\232\221\214\203t\210d\227b\266wis\200\330\327\012",
"ta\313mis\361\012",
"\340s\231\232\221\254\042\332\316\275\267wa\211\203t\210\237d\336",
"\350\225\322\211\226 effe\224\012",
"ne\234\227\353m\220\356",
"\324os\200\203d\210t\327\012",
"\260\205\234y\366pro\315typ\331\240\227w\266h \325t\206\334sem\337\260umn\304",
"\324c\334\314\217 s\322dow\211\254\314a\201\254\305c\270\362level\012",
"\261p\233t\227\306n\213i\367\301\253 \274tr\214c\213\227\315 %\205\252\371\207\304",
"la\352l nam\200\217 s\322dow\211ta\313nam\303",
"\346\307\323g\266\211\261ce\270\211r\327\334\346\305cis\206\012",
"\223d\214d\344\042\320e\265\042: \267\320\200\274\212way\2111 (\301\253\235",
"\203\237t\207m\203\213\200\275\320\200\374\042\320e\265\316\350\225(\301\253\235",
"\214\223a\252\272\353\237\012",
"\254\314\274\372gn\227\315 \266self (\301\253\235"
"\301\253 \274tr\214c\213\227\315 %\205\252\371\207\304",
"\223\326\266\225\307\332\222t/\317cro (\301\253\235",
"\346\307\246t\211do\331\241\361 \326\266\206\012",
"\301 \274nev\263\240\270\336",
"\301 \274\372gn\227\254\365\200t\322\201\274nev\263\240\270\336",
"\223d\214d\344\353\237: \332\344\350\225\274z\207o\012",
"\223d\214d\344te\234: \332\344\350\225\274n\202-z\207o\012",
"\214k\226w\373#p\247g\317\012",
"\257\240\331bo\363 \042\223turn;\316\222\205\042\223tur\373<\365e>;\042\012",
"\257\217 sho\364\205\223tur\373\254\365\303",
"\340s\231\232\200\240\200\307\301 \352f\233\200\203\266i\212iz\327\336",
"\340s\231\232\221\214\203t\210d\227\372gn\220\356",
"\340s\231\232\221\214\203t\210d\227b\266wis\200\330\327\012",
"ta\313mis\361\012",
"\340s\231\232\221\254\042\332\316\275\267wa\211\203t\210\237d\336",
"\350\225\322\211\226 effe\224\012",
"ne\234\227\353m\220\356",
"\324os\200\203d\210t\327\012",
"\260\205\234y\366pro\315typ\331\240\227w\266h \325t\206\334sem\337\260umn\304",
"\324c\334\314\217 s\322dow\211\254\314a\201\254\305c\270\362level\012",
"\261p\233t\227\306n\213i\367\301\253 \274tr\214c\213\227\315 %\205\252\371\207\304",
"la\352l nam\200\217 s\322dow\211ta\313nam\303",
"\346\307\323g\266\211\261ce\270\211r\327\334\346\305cis\206\012",
"\223d\214d\344\042\320e\265\042: \267\320\200\274\212way\2111 (\301\253\235",
"\203\237t\207m\203\213\200\275\320\200\374\042\320e\265\316\350\225(\301\253\235",
"\214\223a\252\272\353\237\012",
"\254\314\274\372gn\227\315 \266self (\301\253\235"
#endif
};
};

File diff suppressed because it is too large Load Diff

View File

@ -39,67 +39,69 @@
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h> /* for atoi() */
#include <stdlib.h> /* for atoi() */
#include <string.h>
#include <ctype.h>
#if defined FORTIFY
#include "fortify.h"
#include "fortify.h"
#endif
#include "embryo_cc_sc.h"
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable:4125) /* decimal digit terminates octal escape sequence */
#pragma warning(push)
#pragma warning(disable:4125) /* decimal digit terminates octal escape sequence */
#endif
#include "embryo_cc_sc7.scp"
#if defined _MSC_VER
#pragma warning(pop)
#pragma warning(pop)
#endif
static void stgstring(char *start,char *end);
static void stgopt(char *start,char *end);
static void stgstring(char *start, char *end);
static void stgopt(char *start, char *end);
#define sSTG_GROW 512
#define sSTG_MAX 20480
static char *stgbuf = NULL;
static int stgmax = 0; /* current size of the staging buffer */
static char *stgbuf = NULL;
static int stgmax = 0; /* current size of the staging buffer */
#define CHECK_STGBUFFER(index) if ((int)(index)>=stgmax) grow_stgbuffer((index)+1)
static void grow_stgbuffer(int requiredsize)
static void
grow_stgbuffer(int requiredsize)
{
char *p;
int clear = stgbuf==NULL; /* if previously none, empty buffer explicitly */
char *p;
int clear = stgbuf == NULL; /* if previously none, empty buffer explicitly */
assert(stgmax<requiredsize);
/* if the staging buffer (holding intermediate code for one line) grows
* over a few kBytes, there is probably a run-away expression
*/
if (requiredsize>sSTG_MAX)
error(102,"staging buffer"); /* staging buffer overflow (fatal error) */
stgmax=requiredsize+sSTG_GROW;
if (stgbuf!=NULL)
p=(char *)realloc(stgbuf,stgmax*sizeof(char));
else
p=(char *)malloc(stgmax*sizeof(char));
if (p==NULL)
error(102,"staging buffer"); /* staging buffer overflow (fatal error) */
stgbuf=p;
if (clear)
*stgbuf='\0';
assert(stgmax < requiredsize);
/* if the staging buffer (holding intermediate code for one line) grows
* over a few kBytes, there is probably a run-away expression
*/
if (requiredsize > sSTG_MAX)
error(102, "staging buffer"); /* staging buffer overflow (fatal error) */
stgmax = requiredsize + sSTG_GROW;
if (stgbuf != NULL)
p = (char *)realloc(stgbuf, stgmax * sizeof(char));
else
p = (char *)malloc(stgmax * sizeof(char));
if (p == NULL)
error(102, "staging buffer"); /* staging buffer overflow (fatal error) */
stgbuf = p;
if (clear)
*stgbuf = '\0';
}
SC_FUNC void stgbuffer_cleanup(void)
SC_FUNC void
stgbuffer_cleanup(void)
{
if (stgbuf!=NULL) {
free(stgbuf);
stgbuf=NULL;
stgmax=0;
} /* if */
if (stgbuf != NULL)
{
free(stgbuf);
stgbuf = NULL;
stgmax = 0;
} /* if */
}
/* the variables "stgidx" and "staging" are declared in "scvars.c" */
@ -120,19 +122,22 @@ SC_FUNC void stgbuffer_cleanup(void)
* stgbuf (altered)
* staging (referred to only)
*/
SC_FUNC void stgmark(char mark)
SC_FUNC void
stgmark(char mark)
{
if (staging) {
CHECK_STGBUFFER(stgidx);
stgbuf[stgidx++]=mark;
} /* if */
if (staging)
{
CHECK_STGBUFFER(stgidx);
stgbuf[stgidx++] = mark;
} /* if */
}
static int filewrite(char *str)
static int
filewrite(char *str)
{
if (sc_status==statWRITE)
return sc_writeasm(outf,str);
return TRUE;
if (sc_status == statWRITE)
return sc_writeasm(outf, str);
return TRUE;
}
/* stgwrite
@ -152,29 +157,36 @@ static int filewrite(char *str)
* stgbuf (altered)
* staging (referred to only)
*/
SC_FUNC void stgwrite(char *st)
SC_FUNC void
stgwrite(char *st)
{
int len;
int len;
CHECK_STGBUFFER(0);
if (staging) {
if (stgidx>=2 && stgbuf[stgidx-1]=='\0' && stgbuf[stgidx-2]!='\n')
stgidx-=1; /* overwrite last '\0' */
while (*st!='\0') { /* copy to staging buffer */
CHECK_STGBUFFER(stgidx);
stgbuf[stgidx++]=*st++;
} /* while */
CHECK_STGBUFFER(stgidx);
stgbuf[stgidx++]='\0';
} else {
CHECK_STGBUFFER(strlen(stgbuf)+strlen(st)+1);
strcat(stgbuf,st);
len=strlen(stgbuf);
if (len>0 && stgbuf[len-1]=='\n') {
filewrite(stgbuf);
stgbuf[0]='\0';
} /* if */
} /* if */
CHECK_STGBUFFER(0);
if (staging)
{
if (stgidx >= 2 && stgbuf[stgidx - 1] == '\0'
&& stgbuf[stgidx - 2] != '\n')
stgidx -= 1; /* overwrite last '\0' */
while (*st != '\0')
{ /* copy to staging buffer */
CHECK_STGBUFFER(stgidx);
stgbuf[stgidx++] = *st++;
} /* while */
CHECK_STGBUFFER(stgidx);
stgbuf[stgidx++] = '\0';
}
else
{
CHECK_STGBUFFER(strlen(stgbuf) + strlen(st) + 1);
strcat(stgbuf, st);
len = strlen(stgbuf);
if (len > 0 && stgbuf[len - 1] == '\n')
{
filewrite(stgbuf);
stgbuf[0] = '\0';
} /* if */
} /* if */
}
/* stgout
@ -187,16 +199,18 @@ SC_FUNC void stgwrite(char *st)
* stgbuf (referred to only)
* staging (referred to only)
*/
SC_FUNC void stgout(int index)
SC_FUNC void
stgout(int index)
{
if (!staging)
return;
stgstring(&stgbuf[index],&stgbuf[stgidx]);
stgidx=index;
if (!staging)
return;
stgstring(&stgbuf[index], &stgbuf[stgidx]);
stgidx = index;
}
typedef struct {
char *start,*end;
typedef struct
{
char *start, *end;
} argstack;
/* stgstring
@ -221,63 +235,76 @@ typedef struct {
* '[...|...] invalid, first string doesn't start with '|'
* '[|...|] invalid
*/
static void stgstring(char *start,char *end)
static void
stgstring(char *start, char *end)
{
char *ptr;
int nest,argc,arg;
argstack *stack;
char *ptr;
int nest, argc, arg;
argstack *stack;
while (start<end) {
if (*start==sSTARTREORDER) {
start+=1; /* skip token */
/* allocate a argstack with sMAXARGS items */
stack=(argstack *)malloc(sMAXARGS*sizeof(argstack));
if (stack==NULL)
error(103); /* insufficient memory */
nest=1; /* nesting counter */
argc=0; /* argument counter */
arg=-1; /* argument index; no valid argument yet */
do {
switch (*start) {
case sSTARTREORDER:
nest++;
start++;
break;
case sENDREORDER:
nest--;
start++;
break;
default:
if ((*start & sEXPRSTART)==sEXPRSTART) {
if (nest==1) {
if (arg>=0)
stack[arg].end=start-1; /* finish previous argument */
arg=(unsigned char)*start - sEXPRSTART;
stack[arg].start=start+1;
if (arg>=argc)
argc=arg+1;
} /* if */
start++;
} else {
start+=strlen(start)+1;
} /* if */
} /* switch */
} while (nest); /* enddo */
if (arg>=0)
stack[arg].end=start-1; /* finish previous argument */
while (argc>0) {
argc--;
stgstring(stack[argc].start,stack[argc].end);
} /* while */
free(stack);
} else {
ptr=start;
while (ptr<end && *ptr!=sSTARTREORDER)
ptr+=strlen(ptr)+1;
stgopt(start,ptr);
start=ptr;
} /* if */
} /* while */
while (start < end)
{
if (*start == sSTARTREORDER)
{
start += 1; /* skip token */
/* allocate a argstack with sMAXARGS items */
stack = (argstack *) malloc(sMAXARGS * sizeof(argstack));
if (stack == NULL)
error(103); /* insufficient memory */
nest = 1; /* nesting counter */
argc = 0; /* argument counter */
arg = -1; /* argument index; no valid argument yet */
do
{
switch (*start)
{
case sSTARTREORDER:
nest++;
start++;
break;
case sENDREORDER:
nest--;
start++;
break;
default:
if ((*start & sEXPRSTART) == sEXPRSTART)
{
if (nest == 1)
{
if (arg >= 0)
stack[arg].end = start - 1; /* finish previous argument */
arg = (unsigned char)*start - sEXPRSTART;
stack[arg].start = start + 1;
if (arg >= argc)
argc = arg + 1;
} /* if */
start++;
}
else
{
start += strlen(start) + 1;
} /* if */
} /* switch */
}
while (nest); /* enddo */
if (arg >= 0)
stack[arg].end = start - 1; /* finish previous argument */
while (argc > 0)
{
argc--;
stgstring(stack[argc].start, stack[argc].end);
} /* while */
free(stack);
}
else
{
ptr = start;
while (ptr < end && *ptr != sSTARTREORDER)
ptr += strlen(ptr) + 1;
stgopt(start, ptr);
start = ptr;
} /* if */
} /* while */
}
/* stgdel
@ -287,21 +314,25 @@ static void stgstring(char *start,char *end)
* Global references: stgidx (altered)
* staging (reffered to only)
*/
SC_FUNC void stgdel(int index,cell code_index)
SC_FUNC void
stgdel(int index, cell code_index)
{
if (staging) {
stgidx=index;
code_idx=code_index;
} /* if */
if (staging)
{
stgidx = index;
code_idx = code_index;
} /* if */
}
SC_FUNC int stgget(int *index,cell *code_index)
SC_FUNC int
stgget(int *index, cell * code_index)
{
if (staging) {
*index=stgidx;
*code_index=code_idx;
} /* if */
return staging;
if (staging)
{
*index = stgidx;
*code_index = code_idx;
} /* if */
return staging;
}
/* stgset
@ -314,20 +345,22 @@ SC_FUNC int stgget(int *index,cell *code_index)
* stgidx (altered)
* stgbuf (contents altered)
*/
SC_FUNC void stgset(int onoff)
SC_FUNC void
stgset(int onoff)
{
staging=onoff;
if (staging){
assert(stgidx==0);
stgidx=0;
CHECK_STGBUFFER(stgidx);
/* write any contents that may be put in the buffer by stgwrite()
* when "staging" was 0
*/
if (strlen(stgbuf)>0)
filewrite(stgbuf);
} /* if */
stgbuf[0]='\0';
staging = onoff;
if (staging)
{
assert(stgidx == 0);
stgidx = 0;
CHECK_STGBUFFER(stgidx);
/* write any contents that may be put in the buffer by stgwrite()
* when "staging" was 0
*/
if (strlen(stgbuf) > 0)
filewrite(stgbuf);
} /* if */
stgbuf[0] = '\0';
}
/* phopt_init
@ -335,215 +368,241 @@ SC_FUNC void stgset(int onoff)
* are embedded in the .EXE file in compressed format, here we expand
* them (and allocate memory for the sequences).
*/
static SEQUENCE *sequences;
static SEQUENCE *sequences;
SC_FUNC int phopt_init(void)
SC_FUNC int
phopt_init(void)
{
int number, i, len;
char str[160];
int number, i, len;
char str[160];
/* count number of sequences */
for (number=0; sequences_cmp[number].find!=NULL; number++)
/* nothing */;
number++; /* include an item for the NULL terminator */
/* count number of sequences */
for (number = 0; sequences_cmp[number].find != NULL; number++)
/* nothing */ ;
number++; /* include an item for the NULL terminator */
if ((sequences=(SEQUENCE*)malloc(number * sizeof(SEQUENCE)))==NULL)
return FALSE;
if ((sequences = (SEQUENCE *) malloc(number * sizeof(SEQUENCE))) == NULL)
return FALSE;
/* pre-initialize all to NULL (in case of failure) */
for (i=0; i<number; i++) {
sequences[i].find=NULL;
sequences[i].replace=NULL;
sequences[i].savesize=0;
} /* for */
/* pre-initialize all to NULL (in case of failure) */
for (i = 0; i < number; i++)
{
sequences[i].find = NULL;
sequences[i].replace = NULL;
sequences[i].savesize = 0;
} /* for */
/* expand all strings */
for (i=0; i<number-1; i++) {
len = strexpand(str,(unsigned char*)sequences_cmp[i].find,sizeof str,SCPACK_TABLE);
assert(len<=sizeof str);
assert(len==(int)strlen(str)+1);
sequences[i].find=(char*)malloc(len);
if (sequences[i].find!=NULL)
strcpy(sequences[i].find,str);
len = strexpand(str,(unsigned char*)sequences_cmp[i].replace,sizeof str,SCPACK_TABLE);
assert(len<=sizeof str);
assert(len==(int)strlen(str)+1);
sequences[i].replace=(char*)malloc(len);
if (sequences[i].replace!=NULL)
strcpy(sequences[i].replace,str);
sequences[i].savesize=sequences_cmp[i].savesize;
if (sequences[i].find==NULL || sequences[i].replace==NULL)
return phopt_cleanup();
} /* for */
/* expand all strings */
for (i = 0; i < number - 1; i++)
{
len =
strexpand(str, (unsigned char *)sequences_cmp[i].find, sizeof str,
SCPACK_TABLE);
assert(len <= sizeof str);
assert(len == (int)strlen(str) + 1);
sequences[i].find = (char *)malloc(len);
if (sequences[i].find != NULL)
strcpy(sequences[i].find, str);
len =
strexpand(str, (unsigned char *)sequences_cmp[i].replace, sizeof str,
SCPACK_TABLE);
assert(len <= sizeof str);
assert(len == (int)strlen(str) + 1);
sequences[i].replace = (char *)malloc(len);
if (sequences[i].replace != NULL)
strcpy(sequences[i].replace, str);
sequences[i].savesize = sequences_cmp[i].savesize;
if (sequences[i].find == NULL || sequences[i].replace == NULL)
return phopt_cleanup();
} /* for */
return TRUE;
return TRUE;
}
SC_FUNC int phopt_cleanup(void)
SC_FUNC int
phopt_cleanup(void)
{
int i;
if (sequences!=NULL) {
i=0;
while (sequences[i].find!=NULL || sequences[i].replace!=NULL) {
if (sequences[i].find!=NULL)
free(sequences[i].find);
if (sequences[i].replace!=NULL)
free(sequences[i].replace);
i++;
} /* while */
free(sequences);
sequences=NULL;
} /* if */
return FALSE;
int i;
if (sequences != NULL)
{
i = 0;
while (sequences[i].find != NULL || sequences[i].replace != NULL)
{
if (sequences[i].find != NULL)
free(sequences[i].find);
if (sequences[i].replace != NULL)
free(sequences[i].replace);
i++;
} /* while */
free(sequences);
sequences = NULL;
} /* if */
return FALSE;
}
#define _maxoptvars 4
#define _aliasmax 10 /* a 32-bit number can be represented in
* 9 decimal digits */
#define _aliasmax 10 /* a 32-bit number can be represented in
* 9 decimal digits */
static int matchsequence(char *start,char *end,char *pattern,
char symbols[_maxoptvars][_aliasmax+1],
int *match_length)
static int
matchsequence(char *start, char *end, char *pattern,
char symbols[_maxoptvars][_aliasmax + 1], int *match_length)
{
int var,i;
char str[_aliasmax+1];
char *start_org=start;
int var, i;
char str[_aliasmax + 1];
char *start_org = start;
*match_length=0;
for (var=0; var<_maxoptvars; var++)
symbols[var][0]='\0';
*match_length = 0;
for (var = 0; var < _maxoptvars; var++)
symbols[var][0] = '\0';
while (*start=='\t' || *start==' ')
start++;
while (*pattern) {
if (start>=end)
return FALSE;
switch (*pattern) {
case '%': /* new "symbol" */
pattern++;
assert(isdigit(*pattern));
var=atoi(pattern) - 1;
assert(var>=0 && var<_maxoptvars);
assert(alphanum(*start));
for (i=0; start<end && alphanum(*start); i++,start++) {
assert(i<=_aliasmax);
str[i]=*start;
} /* for */
str[i]='\0';
if (symbols[var][0]!='\0') {
if (strcmp(symbols[var],str)!=0)
return FALSE; /* symbols should be identical */
} else {
strcpy(symbols[var],str);
} /* if */
break;
case ' ':
if (*start!='\t' && *start!=' ')
return FALSE;
while (start<end && *start=='\t' || *start==' ')
start++;
break;
case '!':
while (start<end && *start=='\t' || *start==' ')
start++; /* skip trailing white space */
if (*start!='\n')
return FALSE;
assert(*(start+1)=='\0');
start+=2; /* skip '\n' and '\0' */
if (*(pattern+1)!='\0')
while (start<end && *start=='\t' || *start==' ')
start++; /* skip leading white space of next instruction */
break;
default:
if (tolower(*start) != tolower(*pattern))
return FALSE;
while (*start == '\t' || *start == ' ')
start++;
} /* switch */
pattern++;
} /* while */
while (*pattern)
{
if (start >= end)
return FALSE;
switch (*pattern)
{
case '%': /* new "symbol" */
pattern++;
assert(isdigit(*pattern));
var = atoi(pattern) - 1;
assert(var >= 0 && var < _maxoptvars);
assert(alphanum(*start));
for (i = 0; start < end && alphanum(*start); i++, start++)
{
assert(i <= _aliasmax);
str[i] = *start;
} /* for */
str[i] = '\0';
if (symbols[var][0] != '\0')
{
if (strcmp(symbols[var], str) != 0)
return FALSE; /* symbols should be identical */
}
else
{
strcpy(symbols[var], str);
} /* if */
break;
case ' ':
if (*start != '\t' && *start != ' ')
return FALSE;
while (start < end && *start == '\t' || *start == ' ')
start++;
break;
case '!':
while (start < end && *start == '\t' || *start == ' ')
start++; /* skip trailing white space */
if (*start != '\n')
return FALSE;
assert(*(start + 1) == '\0');
start += 2; /* skip '\n' and '\0' */
if (*(pattern + 1) != '\0')
while (start < end && *start == '\t' || *start == ' ')
start++; /* skip leading white space of next instruction */
break;
default:
if (tolower(*start) != tolower(*pattern))
return FALSE;
start++;
} /* switch */
pattern++;
} /* while */
*match_length=(int)(start-start_org);
return TRUE;
*match_length = (int)(start - start_org);
return TRUE;
}
static char *replacesequence(char *pattern,char symbols[_maxoptvars][_aliasmax+1],int *repl_length)
static char *
replacesequence(char *pattern, char symbols[_maxoptvars][_aliasmax + 1],
int *repl_length)
{
char *lptr;
int var;
char *buffer;
char *lptr;
int var;
char *buffer;
/* calculate the length of the new buffer
* this is the length of the pattern plus the length of all symbols (note
* that the same symbol may occur multiple times in the pattern) plus
* line endings and startings ('\t' to start a line and '\n\0' to end one)
*/
assert(repl_length!=NULL);
*repl_length=0;
lptr=pattern;
while (*lptr) {
switch (*lptr) {
case '%':
lptr++; /* skip '%' */
assert(isdigit(*lptr));
var=atoi(lptr) - 1;
assert(var>=0 && var<_maxoptvars);
assert(symbols[var][0]!='\0'); /* variable should be defined */
*repl_length+=strlen(symbols[var]);
break;
case '!':
*repl_length+=3; /* '\t', '\n' & '\0' */
break;
default:
*repl_length+=1;
} /* switch */
lptr++;
} /* while */
/* calculate the length of the new buffer
* this is the length of the pattern plus the length of all symbols (note
* that the same symbol may occur multiple times in the pattern) plus
* line endings and startings ('\t' to start a line and '\n\0' to end one)
*/
assert(repl_length != NULL);
*repl_length = 0;
lptr = pattern;
while (*lptr)
{
switch (*lptr)
{
case '%':
lptr++; /* skip '%' */
assert(isdigit(*lptr));
var = atoi(lptr) - 1;
assert(var >= 0 && var < _maxoptvars);
assert(symbols[var][0] != '\0'); /* variable should be defined */
*repl_length += strlen(symbols[var]);
break;
case '!':
*repl_length += 3; /* '\t', '\n' & '\0' */
break;
default:
*repl_length += 1;
} /* switch */
lptr++;
} /* while */
/* allocate a buffer to replace the sequence in */
if ((buffer=malloc(*repl_length))==NULL)
return (char*)error(103);
/* allocate a buffer to replace the sequence in */
if ((buffer = malloc(*repl_length)) == NULL)
return (char *)error(103);
/* replace the pattern into this temporary buffer */
lptr=buffer;
*lptr++='\t'; /* the "replace" patterns do not have tabs */
while (*pattern) {
assert((int)(lptr-buffer)<*repl_length);
switch (*pattern) {
case '%':
/* write out the symbol */
pattern++;
assert(isdigit(*pattern));
var=atoi(pattern) - 1;
assert(var>=0 && var<_maxoptvars);
assert(symbols[var][0]!='\0'); /* variable should be defined */
strcpy(lptr,symbols[var]);
lptr+=strlen(symbols[var]);
break;
case '!':
/* finish the line, optionally start the next line with an indent */
*lptr++='\n';
*lptr++='\0';
if (*(pattern+1)!='\0')
*lptr++='\t';
break;
default:
*lptr++=*pattern;
} /* switch */
pattern++;
} /* while */
/* replace the pattern into this temporary buffer */
lptr = buffer;
*lptr++ = '\t'; /* the "replace" patterns do not have tabs */
while (*pattern)
{
assert((int)(lptr - buffer) < *repl_length);
switch (*pattern)
{
case '%':
/* write out the symbol */
pattern++;
assert(isdigit(*pattern));
var = atoi(pattern) - 1;
assert(var >= 0 && var < _maxoptvars);
assert(symbols[var][0] != '\0'); /* variable should be defined */
strcpy(lptr, symbols[var]);
lptr += strlen(symbols[var]);
break;
case '!':
/* finish the line, optionally start the next line with an indent */
*lptr++ = '\n';
*lptr++ = '\0';
if (*(pattern + 1) != '\0')
*lptr++ = '\t';
break;
default:
*lptr++ = *pattern;
} /* switch */
pattern++;
} /* while */
assert((int)(lptr-buffer)==*repl_length);
return buffer;
assert((int)(lptr - buffer) == *repl_length);
return buffer;
}
static void strreplace(char *dest,char *replace,int sub_length,int repl_length,int dest_length)
static void
strreplace(char *dest, char *replace, int sub_length, int repl_length,
int dest_length)
{
int offset=sub_length-repl_length;
if (offset>0) /* delete a section */
memmove(dest,dest+offset,dest_length-offset);
else if (offset<0) /* insert a section */
memmove(dest-offset, dest, dest_length);
memcpy(dest, replace, repl_length);
int offset = sub_length - repl_length;
if (offset > 0) /* delete a section */
memmove(dest, dest + offset, dest_length - offset);
else if (offset < 0) /* insert a section */
memmove(dest - offset, dest, dest_length);
memcpy(dest, replace, repl_length);
}
/* stgopt
@ -555,52 +614,68 @@ static void strreplace(char *dest,char *replace,int sub_length,int repl_length,i
* The longest sequences must be checked first.
*/
static void stgopt(char *start,char *end)
static void
stgopt(char *start, char *end)
{
char symbols[_maxoptvars][_aliasmax+1];
int seq,match_length,repl_length;
char symbols[_maxoptvars][_aliasmax + 1];
int seq, match_length, repl_length;
assert(sequences!=NULL);
while (start<end) {
if ((sc_debug & sNOOPTIMIZE)!=0 || sc_status!=statWRITE) {
/* do not match anything if debug-level is maximum */
filewrite(start);
} else {
seq=0;
while (sequences[seq].find!=NULL) {
assert(seq>=0);
if (matchsequence(start,end,sequences[seq].find,symbols,&match_length)) {
char *replace=replacesequence(sequences[seq].replace,symbols,&repl_length);
/* If the replacement is bigger than the original section, we may need
* to "grow" the staging buffer. This is quite complex, due to the
* re-ordering of expressions that can also happen in the staging
* buffer. In addition, it should not happen: the peephole optimizer
* must replace sequences with *shorter* sequences, not longer ones.
* So, I simply forbid sequences that are longer than the ones they
* are meant to replace.
*/
assert(match_length>=repl_length);
if (match_length>=repl_length) {
strreplace(start,replace,match_length,repl_length,(int)(end-start));
end-=match_length-repl_length;
free(replace);
code_idx-=sequences[seq].savesize;
seq=0; /* restart search for matches */
} else {
/* actually, we should never get here (match_length<repl_length) */
assert(0);
seq++;
} /* if */
} else {
seq++;
} /* if */
} /* while */
assert(sequences[seq].find==NULL);
filewrite(start);
} /* if */
assert(start < end);
start += strlen(start) + 1; /* to next string */
} /* while (start<end) */
assert(sequences != NULL);
while (start < end)
{
if ((sc_debug & sNOOPTIMIZE) != 0 || sc_status != statWRITE)
{
/* do not match anything if debug-level is maximum */
filewrite(start);
}
else
{
seq = 0;
while (sequences[seq].find != NULL)
{
assert(seq >= 0);
if (matchsequence
(start, end, sequences[seq].find, symbols, &match_length))
{
char *replace =
replacesequence(sequences[seq].replace, symbols,
&repl_length);
/* If the replacement is bigger than the original section, we may need
* to "grow" the staging buffer. This is quite complex, due to the
* re-ordering of expressions that can also happen in the staging
* buffer. In addition, it should not happen: the peephole optimizer
* must replace sequences with *shorter* sequences, not longer ones.
* So, I simply forbid sequences that are longer than the ones they
* are meant to replace.
*/
assert(match_length >= repl_length);
if (match_length >= repl_length)
{
strreplace(start, replace, match_length,
repl_length, (int)(end - start));
end -= match_length - repl_length;
free(replace);
code_idx -= sequences[seq].savesize;
seq = 0; /* restart search for matches */
}
else
{
/* actually, we should never get here (match_length<repl_length) */
assert(0);
seq++;
} /* if */
}
else
{
seq++;
} /* if */
} /* while */
assert(sequences[seq].find == NULL);
filewrite(start);
} /* if */
assert(start < end);
start += strlen(start) + 1; /* to next string */
} /* while (start<end) */
}
#undef SCPACK_TABLE

File diff suppressed because it is too large Load Diff

View File

@ -16,52 +16,38 @@
#define STACKSIZE 16
SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2])
int
strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2])
{
unsigned char stack[STACKSIZE];
short c, top = 0;
int len;
unsigned char stack[STACKSIZE];
short c, top = 0;
int len;
assert(maxlen > 0);
len = 1; /* already 1 byte for '\0' */
for (;;) {
/* Pop byte from stack or read byte from the input string */
if (top)
c = stack[--top];
else if ((c = *(unsigned char *)source++) == '\0')
break;
/* Push pair on stack or output byte to the output string */
if (c > 127) {
assert(top+2 <= STACKSIZE);
stack[top++] = pairtable[c-128][1];
stack[top++] = pairtable[c-128][0];
}
else {
len++;
if (maxlen > 1) { /* reserve one byte for the '\0' */
*dest++ = (char)c;
maxlen--;
}
}
}
*dest = '\0';
return len; /* return number of bytes decoded */
len = 1; /* already 1 byte for '\0' */
for (;;)
{
/* Pop byte from stack or read byte from the input string */
if (top)
c = stack[--top];
else if ((c = *(unsigned char *)source++) == '\0')
break;
/* Push pair on stack or output byte to the output string */
if (c > 127)
{
stack[top++] = pairtable[c - 128][1];
stack[top++] = pairtable[c - 128][0];
}
else
{
len++;
if (maxlen > 1)
{
*dest++ = (char)c;
maxlen--;
}
}
}
*dest = '\0';
return len;
}
#if 0 /*for testing*/
#include "sc5.scp"
int main (int argc, char **argv)
{
int i;
char str[128];
for (i=0; i<58; i++) {
strexpand(str, errmsg[i], sizeof str, SCPACK_TABLE);
printf("%s", str);
} /* for */
return 0;
}
#endif

View File

@ -1,34 +1,11 @@
/*
* Things needed to compile under linux.
*
* Should be reworked totally to use GNU's 'configure'
*/
#include "config.h"
/*
* Getchar is not a 'cool' replacement for MSDOS getch: Linux/unix depends on the features activated or not about the
* controlling terminal's tty. This means that ioctl(2) calls must be performed, for instance to have the controlling terminal tty's
* in 'raw' mode, if we want to be able to fetch a single character. This also means that everything must be put back
* correctly when the program ends.
*
* For interactive use of SRUN/SDBG if would be much better to use GNU's readline package: the user would be able to have
* a complete emacs/vi like line editing system.
*
* So we stick to getchar at the moment... (one needs to key ctrl-d to terminate input if getch is called with a controlling
* terminal driven by a tty having -raw)
*/
#if defined LINUX
#include "config.h"
#endif
/* Linux NOW has these */
#if !defined BIG_ENDIAN
#define BIG_ENDIAN 4321
# define BIG_ENDIAN 4321
#endif
#if !defined LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
# define LITTLE_ENDIAN 1234
#endif
/* educated guess, BYTE_ORDER is undefined, i386 is common => little endian */
#ifdef WORDS_BIGENDIAN
# undef BYTE_ORDER
# define BYTE_ORDER BIG_ENDIAN
@ -41,32 +18,6 @@
#define stricmp(a,b) strcasecmp(a,b)
#define strnicmp(a,b,c) strncasecmp(a,b,c)
/*
* WinWorld wants '\'. Unices do not.
*/
/* unix sep char- shoudl just assume this. */
#define DIRECTORY_SEP_CHAR '/'
#define DIRECTORY_SEP_STR "/"
/*
* SC assumes that a computer is Little Endian unless told otherwise. It uses
* (and defines) the macros BYTE_ORDER and BIG_ENDIAN.
* For Linux, we must overrule these settings with those defined in glibc.
*/
#if !defined __BYTE_ORDER
# include <stdlib.h>
#endif
#ifndef __BYTE_ORDER
# define __BYTE_ORDER BYTE_ORDER
#endif
#ifndef __LITTLE_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
#endif
#ifndef __BIG_ENDIAN
# define __BIG_ENDIAN BIG_ENDIAN
#endif
#if !defined __BYTE_ORDER
# error "Can't figure computer byte order (__BYTE_ORDER macro not found)"
#endif

View File

@ -28,252 +28,281 @@
#include <string.h>
#include "embryo_cc_sc.h"
#if defined FORTIFY
#include "fortify.h"
#endif
/* a "private" implementation of strdup(), so that porting
* to other memory allocators becomes easier.
* By Søren Hannibal.
*/
SC_FUNC char* duplicatestring(const char* sourcestring)
char *
duplicatestring(const char *sourcestring)
{
char* result=malloc(strlen(sourcestring)+1);
strcpy(result,sourcestring);
return result;
char *result = malloc(strlen(sourcestring) + 1);
strcpy(result, sourcestring);
return result;
}
static stringpair *insert_stringpair(stringpair *root,char *first,char *second,int matchlength)
static stringpair *
insert_stringpair(stringpair * root, char *first, char *second, int matchlength)
{
stringpair *cur,*pred;
stringpair *cur, *pred;
assert(root!=NULL);
assert(first!=NULL);
assert(second!=NULL);
/* create a new node, and check whether all is okay */
if ((cur=(stringpair*)malloc(sizeof(stringpair)))==NULL)
return NULL;
cur->first=duplicatestring(first);
cur->second=duplicatestring(second);
cur->matchlength=matchlength;
if (cur->first==NULL || cur->second==NULL) {
if (cur->first!=NULL)
free(cur->first);
if (cur->second!=NULL)
free(cur->second);
free(cur);
return NULL;
} /* if */
/* link the node to the tree, find the position */
for (pred=root; pred->next!=NULL && strcmp(pred->next->first,first)<0; pred=pred->next)
/* nothing */;
cur->next=pred->next;
pred->next=cur;
return cur;
assert(root != NULL);
assert(first != NULL);
assert(second != NULL);
/* create a new node, and check whether all is okay */
if ((cur = (stringpair *) malloc(sizeof(stringpair))) == NULL)
return NULL;
cur->first = duplicatestring(first);
cur->second = duplicatestring(second);
cur->matchlength = matchlength;
if (cur->first == NULL || cur->second == NULL)
{
if (cur->first != NULL)
free(cur->first);
if (cur->second != NULL)
free(cur->second);
free(cur);
return NULL;
} /* if */
/* link the node to the tree, find the position */
for (pred = root; pred->next != NULL && strcmp(pred->next->first, first) < 0;
pred = pred->next)
/* nothing */ ;
cur->next = pred->next;
pred->next = cur;
return cur;
}
static void delete_stringpairtable(stringpair *root)
static void
delete_stringpairtable(stringpair * root)
{
stringpair *cur, *next;
stringpair *cur, *next;
assert(root!=NULL);
cur=root->next;
while (cur!=NULL) {
next=cur->next;
assert(cur->first!=NULL);
assert(cur->second!=NULL);
free(cur->first);
free(cur->second);
free(cur);
cur=next;
} /* while */
memset(root,0,sizeof(stringpair));
assert(root != NULL);
cur = root->next;
while (cur != NULL)
{
next = cur->next;
assert(cur->first != NULL);
assert(cur->second != NULL);
free(cur->first);
free(cur->second);
free(cur);
cur = next;
} /* while */
memset(root, 0, sizeof(stringpair));
}
static stringpair *find_stringpair(stringpair *cur,char *first,int matchlength)
static stringpair *
find_stringpair(stringpair * cur, char *first, int matchlength)
{
int result=0;
int result = 0;
assert(matchlength>0); /* the function cannot handle zero-length comparison */
assert(first!=NULL);
while (cur!=NULL && result<=0) {
result=(int)*cur->first - (int)*first;
if (result==0 && matchlength==cur->matchlength) {
result=strncmp(cur->first,first,matchlength);
if (result==0)
return cur;
} /* if */
cur=cur->next;
} /* while */
return NULL;
assert(matchlength > 0); /* the function cannot handle zero-length comparison */
assert(first != NULL);
while (cur != NULL && result <= 0)
{
result = (int)*cur->first - (int)*first;
if (result == 0 && matchlength == cur->matchlength)
{
result = strncmp(cur->first, first, matchlength);
if (result == 0)
return cur;
} /* if */
cur = cur->next;
} /* while */
return NULL;
}
static int delete_stringpair(stringpair *root,stringpair *item)
static int
delete_stringpair(stringpair * root, stringpair * item)
{
stringpair *cur;
stringpair *cur;
assert(root!=NULL);
cur=root;
while (cur->next!=NULL) {
if (cur->next==item) {
cur->next=item->next; /* unlink from list */
assert(item->first!=NULL);
assert(item->second!=NULL);
free(item->first);
free(item->second);
free(item);
return TRUE;
} /* if */
cur=cur->next;
} /* while */
return FALSE;
assert(root != NULL);
cur = root;
while (cur->next != NULL)
{
if (cur->next == item)
{
cur->next = item->next; /* unlink from list */
assert(item->first != NULL);
assert(item->second != NULL);
free(item->first);
free(item->second);
free(item);
return TRUE;
} /* if */
cur = cur->next;
} /* while */
return FALSE;
}
/* ----- alias table --------------------------------------------- */
static stringpair alias_tab = {NULL, NULL, NULL}; /* alias table */
static stringpair alias_tab = { NULL, NULL, NULL }; /* alias table */
SC_FUNC stringpair *insert_alias(char *name,char *alias)
stringpair *
insert_alias(char *name, char *alias)
{
stringpair *cur;
stringpair *cur;
assert(name!=NULL);
assert(strlen(name)<=sNAMEMAX);
assert(alias!=NULL);
assert(strlen(alias)<=sEXPMAX);
if ((cur=insert_stringpair(&alias_tab,name,alias,strlen(name)))==NULL)
error(103); /* insufficient memory (fatal error) */
return cur;
assert(name != NULL);
assert(strlen(name) <= sNAMEMAX);
assert(alias != NULL);
assert(strlen(alias) <= sEXPMAX);
if ((cur = insert_stringpair(&alias_tab, name, alias, strlen(name))) == NULL)
error(103); /* insufficient memory (fatal error) */
return cur;
}
SC_FUNC stringpair *find_alias(char *name)
stringpair *
find_alias(char *name)
{
return find_stringpair(alias_tab.next,name,strlen(name));
return find_stringpair(alias_tab.next, name, strlen(name));
}
SC_FUNC int lookup_alias(char *target,char *name)
int
lookup_alias(char *target, char *name)
{
stringpair *cur=find_stringpair(alias_tab.next,name,strlen(name));
if (cur!=NULL) {
assert(strlen(cur->second)<=sEXPMAX);
strcpy(target,cur->second);
} /* if */
return cur!=NULL;
stringpair *cur =
find_stringpair(alias_tab.next, name, strlen(name));
if (cur != NULL)
{
assert(strlen(cur->second) <= sEXPMAX);
strcpy(target, cur->second);
} /* if */
return cur != NULL;
}
SC_FUNC void delete_aliastable(void)
void
delete_aliastable(void)
{
delete_stringpairtable(&alias_tab);
delete_stringpairtable(&alias_tab);
}
/* ----- include paths list -------------------------------------- */
static stringlist includepaths = {NULL, NULL}; /* directory list for include files */
static stringlist includepaths = { NULL, NULL }; /* directory list for include files */
SC_FUNC stringlist *insert_path(char *path)
stringlist *
insert_path(char *path)
{
stringlist *cur;
stringlist *cur;
assert(path!=NULL);
if ((cur=(stringlist*)malloc(sizeof(stringlist)))==NULL)
error(103); /* insufficient memory (fatal error) */
if ((cur->line=duplicatestring(path))==NULL)
error(103); /* insufficient memory (fatal error) */
cur->next=includepaths.next;
includepaths.next=cur;
return cur;
assert(path != NULL);
if ((cur = (stringlist *) malloc(sizeof(stringlist))) == NULL)
error(103); /* insufficient memory (fatal error) */
if ((cur->line = duplicatestring(path)) == NULL)
error(103); /* insufficient memory (fatal error) */
cur->next = includepaths.next;
includepaths.next = cur;
return cur;
}
SC_FUNC char *get_path(int index)
char *
get_path(int index)
{
stringlist *cur = includepaths.next;
stringlist *cur = includepaths.next;
while (cur!=NULL && index-->0)
cur=cur->next;
if (cur!=NULL) {
assert(cur->line!=NULL);
return cur->line;
} /* if */
return NULL;
while (cur != NULL && index-- > 0)
cur = cur->next;
if (cur != NULL)
{
assert(cur->line != NULL);
return cur->line;
} /* if */
return NULL;
}
SC_FUNC void delete_pathtable(void)
void
delete_pathtable(void)
{
stringlist *cur=includepaths.next, *next;
stringlist *cur = includepaths.next, *next;
while (cur!=NULL) {
next=cur->next;
assert(cur->line!=NULL);
free(cur->line);
free(cur);
cur=next;
} /* while */
memset(&includepaths,0,sizeof(stringlist));
while (cur != NULL)
{
next = cur->next;
assert(cur->line != NULL);
free(cur->line);
free(cur);
cur = next;
} /* while */
memset(&includepaths, 0, sizeof(stringlist));
}
/* ----- text substitution patterns ------------------------------ */
#if !defined NO_DEFINE
static stringpair substpair = { NULL, NULL, NULL}; /* list of substitution pairs */
static stringpair substpair = { NULL, NULL, NULL }; /* list of substitution pairs */
static stringpair *substindex['z' - 'A' + 1]; /* quick index to first character */
static stringpair *substindex['z'-'A'+1]; /* quick index to first character */
static void adjustindex(char c)
static void
adjustindex(char c)
{
stringpair *cur;
assert(c>='A' && c<='Z' || c>='a' && c<='z' || c=='_');
assert('A'<'_' && '_'<'z');
stringpair *cur;
for (cur=substpair.next; cur!=NULL && cur->first[0]!=c; cur=cur->next)
/* nothing */;
substindex[(int)c-'A']=cur;
assert(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_');
assert('A' < '_' && '_' < 'z');
for (cur = substpair.next; cur != NULL && cur->first[0] != c;
cur = cur->next)
/* nothing */ ;
substindex[(int)c - 'A'] = cur;
}
SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen)
stringpair *
insert_subst(char *pattern, char *substitution, int prefixlen)
{
stringpair *cur;
stringpair *cur;
assert(pattern!=NULL);
assert(substitution!=NULL);
if ((cur=insert_stringpair(&substpair,pattern,substitution,prefixlen))==NULL)
error(103); /* insufficient memory (fatal error) */
adjustindex(*pattern);
return cur;
assert(pattern != NULL);
assert(substitution != NULL);
if ((cur =
insert_stringpair(&substpair, pattern, substitution,
prefixlen)) == NULL)
error(103); /* insufficient memory (fatal error) */
adjustindex(*pattern);
return cur;
}
SC_FUNC stringpair *find_subst(char *name,int length)
stringpair *
find_subst(char *name, int length)
{
stringpair *item;
assert(name!=NULL);
assert(length>0);
assert(*name>='A' && *name<='Z' || *name>='a' && *name<='z' || *name=='_');
item=substindex[(int)*name-'A'];
if (item!=NULL)
item=find_stringpair(item,name,length);
return item;
stringpair *item;
assert(name != NULL);
assert(length > 0);
assert(*name >= 'A' && *name <= 'Z' || *name >= 'a' && *name <= 'z'
|| *name == '_');
item = substindex[(int)*name - 'A'];
if (item != NULL)
item = find_stringpair(item, name, length);
return item;
}
SC_FUNC int delete_subst(char *name,int length)
int
delete_subst(char *name, int length)
{
stringpair *item;
assert(name!=NULL);
assert(length>0);
assert(*name>='A' && *name<='Z' || *name>='a' && *name<='z' || *name=='_');
item=substindex[(int)*name-'A'];
if (item!=NULL)
item=find_stringpair(item,name,length);
if (item==NULL)
return FALSE;
delete_stringpair(&substpair,item);
adjustindex(*name);
return TRUE;
stringpair *item;
assert(name != NULL);
assert(length > 0);
assert(*name >= 'A' && *name <= 'Z' || *name >= 'a' && *name <= 'z'
|| *name == '_');
item = substindex[(int)*name - 'A'];
if (item != NULL)
item = find_stringpair(item, name, length);
if (item == NULL)
return FALSE;
delete_stringpair(&substpair, item);
adjustindex(*name);
return TRUE;
}
SC_FUNC void delete_substtable(void)
void
delete_substtable(void)
{
int i;
delete_stringpairtable(&substpair);
for (i=0; i<sizeof substindex/sizeof substindex[0]; i++)
substindex[i]=NULL;
}
int i;
#endif /* !defined NO_SUBST */
delete_stringpairtable(&substpair);
for (i = 0; i < sizeof substindex / sizeof substindex[0]; i++)
substindex[i] = NULL;
}

View File

@ -23,7 +23,7 @@
* Version: $Id$
*/
#include <stdio.h>
#include <stdlib.h> /* for _MAX_PATH */
#include <stdlib.h> /* for _MAX_PATH */
#include "embryo_cc_sc.h"
/* global variables
@ -31,69 +31,57 @@
* All global variables that are shared amongst the compiler files are
* declared here.
*/
SC_VDEFINE symbol loctab; /* local symbol table */
SC_VDEFINE symbol glbtab; /* global symbol table */
SC_VDEFINE cell *litq; /* the literal queue */
SC_VDEFINE char pline[sLINEMAX+1]; /* the line read from the input file */
SC_VDEFINE char *lptr; /* points to the current position in "pline" */
SC_VDEFINE constvalue tagname_tab = { NULL, "", 0, 0}; /* tagname table */
SC_VDEFINE constvalue libname_tab = { NULL, "", 0, 0}; /* library table (#pragma library "..." syntax) */
SC_VDEFINE constvalue *curlibrary = NULL;/* current library */
SC_VDEFINE symbol *curfunc; /* pointer to current function */
SC_VDEFINE char *inpfname; /* pointer to name of the file currently read from */
SC_VDEFINE char outfname[_MAX_PATH]; /* output file name */
SC_VDEFINE char errfname[_MAX_PATH]; /* error file name */
SC_VDEFINE char sc_ctrlchar = CTRL_CHAR;/* the control character (or escape character)*/
SC_VDEFINE int litidx = 0; /* index to literal table */
SC_VDEFINE int litmax = sDEF_LITMAX;/* current size of the literal table */
SC_VDEFINE int stgidx = 0; /* index to the staging buffer */
SC_VDEFINE int labnum = 0; /* number of (internal) labels */
SC_VDEFINE int staging = 0; /* true if staging output */
SC_VDEFINE cell declared = 0; /* number of local cells declared */
SC_VDEFINE cell glb_declared=0; /* number of global cells declared */
SC_VDEFINE cell code_idx = 0; /* number of bytes with generated code */
SC_VDEFINE int ntv_funcid= 0; /* incremental number of native function */
SC_VDEFINE int errnum = 0; /* number of errors */
SC_VDEFINE int warnnum = 0; /* number of warnings */
SC_VDEFINE int sc_debug = sCHKBOUNDS; /* by default: bounds checking+assertions */
SC_VDEFINE int charbits = 8; /* a "char" is 8 bits */
SC_VDEFINE int sc_packstr= FALSE; /* strings are packed by default? */
SC_VDEFINE int sc_asmfile= FALSE; /* create .ASM file? */
SC_VDEFINE int sc_listing= FALSE; /* create .LST file? */
SC_VDEFINE int sc_compress=TRUE; /* compress bytecode? */
SC_VDEFINE int sc_needsemicolon=TRUE;/* semicolon required to terminate expressions? */
SC_VDEFINE int sc_dataalign=sizeof(cell);/* data alignment value */
SC_VDEFINE int sc_alignnext=FALSE; /* must frame of the next function be aligned? */
SC_VDEFINE int curseg = 0; /* 1 if currently parsing CODE, 2 if parsing DATA */
SC_VDEFINE cell sc_stksize=sDEF_AMXSTACK;/* default stack size */
SC_VDEFINE int freading = FALSE; /* Is there an input file ready for reading? */
SC_VDEFINE int fline = 0; /* the line number in the current file */
SC_VDEFINE int fnumber = 0; /* the file number in the file table (debugging) */
SC_VDEFINE int fcurrent = 0; /* current file being processed (debugging) */
SC_VDEFINE int intest = 0; /* true if inside a test */
SC_VDEFINE int sideeffect= 0; /* true if an expression causes a side-effect */
SC_VDEFINE int stmtindent= 0; /* current indent of the statement */
SC_VDEFINE int indent_nowarn=FALSE;/* skip warning "217 loose indentation" */
SC_VDEFINE int sc_tabsize=8; /* number of spaces that a TAB represents */
SC_VDEFINE int sc_allowtags=TRUE; /* allow/detect tagnames in lex() */
SC_VDEFINE int sc_status; /* read/write status */
SC_VDEFINE int sc_rationaltag=0; /* tag for rational numbers */
SC_VDEFINE int rational_digits=0; /* number of fractional digits */
symbol loctab; /* local symbol table */
symbol glbtab; /* global symbol table */
cell *litq; /* the literal queue */
char pline[sLINEMAX + 1]; /* the line read from the input file */
char *lptr; /* points to the current position in "pline" */
constvalue tagname_tab = { NULL, "", 0, 0 }; /* tagname table */
constvalue libname_tab = { NULL, "", 0, 0 }; /* library table (#pragma library "..." syntax) */
constvalue *curlibrary = NULL; /* current library */
symbol *curfunc; /* pointer to current function */
char *inpfname; /* pointer to name of the file currently read from */
char outfname[_MAX_PATH]; /* output file name */
char errfname[_MAX_PATH]; /* error file name */
char sc_ctrlchar = CTRL_CHAR; /* the control character (or escape character) */
int litidx = 0; /* index to literal table */
int litmax = sDEF_LITMAX; /* current size of the literal table */
int stgidx = 0; /* index to the staging buffer */
int labnum = 0; /* number of (internal) labels */
int staging = 0; /* true if staging output */
cell declared = 0; /* number of local cells declared */
cell glb_declared = 0; /* number of global cells declared */
cell code_idx = 0; /* number of bytes with generated code */
int ntv_funcid = 0; /* incremental number of native function */
int errnum = 0; /* number of errors */
int warnnum = 0; /* number of warnings */
int sc_debug = sCHKBOUNDS; /* by default: bounds checking+assertions */
int charbits = 8; /* a "char" is 8 bits */
int sc_packstr = FALSE; /* strings are packed by default? */
int sc_asmfile = FALSE; /* create .ASM file? */
int sc_listing = FALSE; /* create .LST file? */
int sc_compress = TRUE; /* compress bytecode? */
int sc_needsemicolon = TRUE; /* semicolon required to terminate expressions? */
int sc_dataalign = sizeof(cell); /* data alignment value */
int sc_alignnext = FALSE; /* must frame of the next function be aligned? */
int curseg = 0; /* 1 if currently parsing CODE, 2 if parsing DATA */
cell sc_stksize = sDEF_AMXSTACK; /* default stack size */
int freading = FALSE; /* Is there an input file ready for reading? */
int fline = 0; /* the line number in the current file */
int fnumber = 0; /* the file number in the file table (debugging) */
int fcurrent = 0; /* current file being processed (debugging) */
int intest = 0; /* true if inside a test */
int sideeffect = 0; /* true if an expression causes a side-effect */
int stmtindent = 0; /* current indent of the statement */
int indent_nowarn = FALSE; /* skip warning "217 loose indentation" */
int sc_tabsize = 8; /* number of spaces that a TAB represents */
int sc_allowtags = TRUE; /* allow/detect tagnames in lex() */
int sc_status; /* read/write status */
int sc_rationaltag = 0; /* tag for rational numbers */
int rational_digits = 0; /* number of fractional digits */
SC_VDEFINE FILE *inpf = NULL; /* file read from (source or include) */
SC_VDEFINE FILE *inpf_org= NULL; /* main source file */
SC_VDEFINE FILE *outf = NULL; /* file written to */
FILE *inpf = NULL; /* file read from (source or include) */
FILE *inpf_org = NULL; /* main source file */
FILE *outf = NULL; /* file written to */
SC_VDEFINE jmp_buf errbuf;
#if !defined SC_LIGHT
SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */
#endif
#if defined __WATCOMC__ && !defined NDEBUG
/* Watcom's CVPACK dislikes .OBJ files without functions */
static int dummyfunc(void)
{
return 0;
}
#endif
jmp_buf errbuf;