From 57f7de9e97b0f20de036bf8c027ac841b0e60e6a Mon Sep 17 00:00:00 2001 From: "thiadmer.riemersma" Date: Mon, 26 Nov 2007 14:16:30 +0000 Subject: [PATCH] Merged in eCos port. Fixed problems on Big Endian processors with the debug information. Completed overlay support (also in the assembler versions). amxFile: extended fstat() function. Bug fixes with overlay table generation. Removed #emit and #endscript. Removed PASCAL-like syntax for instructions ("if ... then begin ... end" instead of "if (...) { ... }"). --- amx/CMakeLists.txt | 1 - amx/amx.c | 65 ++++++++------- amx/amx.h | 16 ++-- amx/amxargs.c | 8 +- amx/amxcons.c | 84 ++++++++++++++------ amx/amxcore.c | 11 ++- amx/amxdbg.h | 6 +- amx/amxdgram.c | 6 +- amx/amxfile.c | 20 +++-- amx/amxprocess.c | 36 ++++----- amx/osdefs.h | 70 +++++++++++++--- amx/pawndbg.c | 16 ++-- amx/pawnrun.c | 6 +- compiler/CMakeLists.txt | 2 +- compiler/sc.h | 125 +++++++++++++++-------------- compiler/sc1.c | 171 +++++++++++++++++++++------------------- compiler/sc2.c | 94 ++++++---------------- compiler/sc3.c | 77 +++++++++++------- compiler/sc5.c | 134 +++++++++++++++++++++++++++++-- compiler/sc6.c | 33 +++++--- compiler/sc7.c | 4 +- compiler/sci18n.c | 4 +- compiler/scstate.c | 42 +++++++--- include/AMXDLL.INC | 6 +- include/args.inc | 6 +- include/bstring.inc | 8 +- include/console.inc | 6 +- include/core.inc | 6 +- include/datagram.inc | 6 +- include/file.inc | 6 +- include/fixed.inc | 6 +- include/float.inc | 4 - include/process.inc | 6 +- include/rational.inc | 10 +-- include/string.inc | 4 - include/time.inc | 4 - 36 files changed, 649 insertions(+), 460 deletions(-) diff --git a/amx/CMakeLists.txt b/amx/CMakeLists.txt index 95fe995..c4fb3d5 100644 --- a/amx/CMakeLists.txt +++ b/amx/CMakeLists.txt @@ -23,7 +23,6 @@ ENDIF(HAVE_ALLOCA_H) ADD_DEFINITIONS(-DFLOATPOINT -DFIXEDPOINT) IF (UNIX) - ADD_DEFINITIONS(-DLINUX) CHECK_INCLUDE_FILE("ffi.h" HAVE_FFI_H) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../linux) ENDIF (UNIX) diff --git a/amx/amx.c b/amx/amx.c index f38534c..8f9e588 100644 --- a/amx/amx.c +++ b/amx/amx.c @@ -18,7 +18,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: amx.c 3831 2007-10-19 17:25:41Z thiadmer $ + * Version: $Id: amx.c 3853 2007-11-26 13:59:01Z thiadmer $ */ #if BUILD_PLATFORM == WINDOWS && BUILD_TYPE == RELEASE && BUILD_COMPILER == MSVC && PAWN_CELL_SIZE == 64 @@ -42,7 +42,7 @@ #include /* for getenv() */ #include #include "osdefs.h" -#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ +#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ #include #if !defined AMX_NODYNALOAD #include @@ -52,16 +52,23 @@ #include #endif #endif -#if defined __LCC__ || defined LINUX +#if defined __LCC__ || defined __LINUX__ #include /* for wcslen() */ #endif -#include "amx.h" + +#if defined __ECOS__ + /* eCos puts include files in cyg/package_name */ + #include +#else + #include "amx.h" +#endif + #if (defined _Windows && !defined AMX_NODYNALOAD) || (defined JIT && __WIN32__) #include #endif -/* When one or more of the AMX_funcname macris are defined, we want +/* When one or more of the AMX_funcname macros are defined, we want * to compile only those functions. However, when none of these macros * is present, we want to compile everything. */ @@ -1097,12 +1104,12 @@ int AMXAPI amx_Init(AMX *amx,void *program) AMX_HEADER *hdr; int err,i; unsigned char *data; - #if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD + #if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD #if defined _Windows char libname[sNAMEMAX+8]; /* +1 for '\0', +3 for 'amx' prefix, +4 for extension */ typedef int (FAR WINAPI *AMX_ENTRY)(AMX _FAR *amx); HINSTANCE hlib; - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ char libname[_MAX_PATH]; char *root; typedef int (*AMX_ENTRY)(AMX *amx); @@ -1292,8 +1299,8 @@ int AMXAPI amx_Init(AMX *amx,void *program) return err; /* load any extension modules that the AMX refers to */ - #if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD - #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD + #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ root=getenv("AMXLIB"); #endif hdr=(AMX_HEADER *)amx->base; @@ -1301,7 +1308,7 @@ int AMXAPI amx_Init(AMX *amx,void *program) for (i=0; ibase; assert(hdr->magic==AMX_MAGIC); numlibraries=NUMENTRIES(hdr,libraries,pubvars); @@ -1476,14 +1483,14 @@ int AMXAPI amx_Cleanup(AMX *amx) strcat(funcname,"Cleanup"); #if defined _Windows libcleanup=(AMX_ENTRY)GetProcAddress((HINSTANCE)lib->address,funcname); - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ libcleanup=(AMX_ENTRY)dlsym((void*)lib->address,funcname); #endif if (libcleanup!=NULL) libcleanup(amx); #if defined _Windows FreeLibrary((HINSTANCE)lib->address); - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ dlclose((void*)lib->address); #endif } /* if */ @@ -1639,7 +1646,7 @@ int AMXAPI amx_NumPublics(AMX *amx, int *number) return AMX_ERR_NONE; } -int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname) +int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname, ucell *address) { AMX_HEADER *hdr; AMX_FUNCSTUB *func; @@ -1652,7 +1659,10 @@ int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname) return AMX_ERR_INDEX; func=GETENTRY(hdr,publics,index); - strcpy(funcname,GETENTRYNAME(hdr,func)); + if (funcname!=NULL) + strcpy(funcname,GETENTRYNAME(hdr,func)); + if (address!=NULL) + *address=func->address; return AMX_ERR_NONE; } @@ -1667,7 +1677,7 @@ int AMXAPI amx_FindPublic(AMX *amx, const char *name, int *index) /* binary search */ while (first<=last) { mid=(first+last)/2; - amx_GetPublic(amx,mid,pname); + amx_GetPublic(amx,mid,pname,NULL); result=strcmp(pname,name); if (result>0) { last=mid-1; @@ -2145,7 +2155,6 @@ static const void * const amx_opcodelist[] = { cell pri,alt,stk,frm,hea; cell reset_stk, reset_hea, *cip; cell offs,val; - ucell codesize; int num,i; assert(amx!=NULL); @@ -2548,7 +2557,7 @@ static const void * const amx_opcodelist[] = { POP(frm); POP(offs); /* verify the return address */ - if ((ucell)offs>=amx->codesize) + if ((long)offs>=amx->codesize) ABORT(amx,AMX_ERR_MEMACCESS); cip=(cell *)(amx->code+(int)offs); NEXT(cip); @@ -2556,7 +2565,7 @@ static const void * const amx_opcodelist[] = { POP(frm); POP(offs); /* verify the return address */ - if ((ucell)offs>=amx->codesize) + if ((long)offs>=amx->codesize) ABORT(amx,AMX_ERR_MEMACCESS); cip=(cell *)(amx->code+(int)offs); stk+= _R(data,stk) + sizeof(cell); /* remove parameters from the stack */ @@ -2589,7 +2598,7 @@ static const void * const amx_opcodelist[] = { /* verify the index */ stk+=_R(data,stk)+sizeof(cell); /* remove parameters from the stack */ num=amx->overlay(amx,amx->ovl_index); /* reload overlay */ - if (num!=AMX_ERR_NONE || (ucell)offs>=(ucell)amx->codesize) + if (num!=AMX_ERR_NONE || (long)offs>=amx->codesize) ABORT(amx,AMX_ERR_MEMACCESS); cip=(cell *)(amx->code+(int)offs); NEXT(cip); @@ -4044,7 +4053,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index) POP(frm); POP(offs); /* verify the return address */ - if ((ucell)offs>=amx->codesize) + if ((long)offs>=amx->codesize) ABORT(amx,AMX_ERR_MEMACCESS); cip=(cell *)(amx->code+(int)offs); break; @@ -4052,7 +4061,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index) POP(frm); POP(offs); /* verify the return address */ - if ((ucell)offs>=amx->codesize) + if ((long)offs>=amx->codesize) ABORT(amx,AMX_ERR_MEMACCESS); cip=(cell *)(amx->code+(int)offs); stk+=_R(data,stk)+sizeof(cell); /* remove parameters from the stack */ @@ -4085,7 +4094,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index) /* verify the index */ stk+=_R(data,stk)+sizeof(cell); /* remove parameters from the stack */ num=amx->overlay(amx,amx->ovl_index); /* reload overlay */ - if (num!=AMX_ERR_NONE || (ucell)offs>=(ucell)amx->codesize) + if (num!=AMX_ERR_NONE || (long)offs>=amx->codesize) ABORT(amx,AMX_ERR_MEMACCESS); cip=(cell *)(amx->code+(int)offs); break; diff --git a/amx/amx.h b/amx/amx.h index 0c27878..6603027 100644 --- a/amx/amx.h +++ b/amx/amx.h @@ -18,7 +18,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: amx.h 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: amx.h 3853 2007-11-26 13:59:01Z thiadmer $ */ #ifndef AMX_H_INCLUDED @@ -27,17 +27,20 @@ #include /* for size_t */ #include +#if defined __linux || defined __linux__ + #define __LINUX__ +#endif #if defined FREEBSD && !defined __FreeBSD__ #define __FreeBSD__ #endif -#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ +#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ #include #endif #if defined HAVE_STDINT_H #include #else - #if defined __LCC__ || defined __DMC__ || defined LINUX || (defined __WATCOMC__ && __WATCOMC__ >= 1200) + #if defined __LCC__ || defined __DMC__ || defined __LINUX__ || (defined __WATCOMC__ && __WATCOMC__ >= 1200) #if defined HAVE_INTTYPES_H #include #else @@ -213,7 +216,7 @@ typedef int (AMXAPI *AMX_IDLE)(struct tagAMX *amx, int AMXAPI Exec(struct tagAMX #endif #if !defined AMX_NO_ALIGN - #if defined LINUX || defined __FreeBSD__ + #if defined __LINUX__ || defined __FreeBSD__ #pragma pack(1) /* structures must be packed (byte-aligned) */ #elif defined MACOS && defined __MWERKS__ #pragma options align=mac68k @@ -405,6 +408,7 @@ enum { else (result) = NULL; \ } while (0) + uint16_t * AMXAPI amx_Align16(uint16_t *v); uint32_t * AMXAPI amx_Align32(uint32_t *v); #if defined _I64_MAX || defined HAVE_I64 @@ -422,7 +426,7 @@ 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_GetPublic(AMX *amx, int index, char *funcname, ucell *address); int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr); int AMXAPI amx_GetString(char *dest,const cell *source, int use_wchar, size_t size); int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id); @@ -466,7 +470,7 @@ int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value); amx_Register((amx), amx_NativeInfo((name),(func)), 1); #if !defined AMX_NO_ALIGN - #if defined LINUX || defined __FreeBSD__ + #if defined __LINUX__ || defined __FreeBSD__ #pragma pack() /* reset default packing */ #elif defined MACOS && defined __MWERKS__ #pragma options align=reset diff --git a/amx/amxargs.c b/amx/amxargs.c index 08db3b1..d909e13 100644 --- a/amx/amxargs.c +++ b/amx/amxargs.c @@ -18,7 +18,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: amxargs.c 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: amxargs.c 3853 2007-11-26 13:59:01Z thiadmer $ */ #if defined _UNICODE || defined __UNICODE__ || defined UNICODE # if !defined UNICODE /* for Windows */ @@ -35,13 +35,13 @@ #include #include #include -#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined __MSDOS__ +#include "osdefs.h" +#if defined __WIN32__ || defined __MSDOS__ #include #endif -#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined _Windows +#if defined __WIN32__ || defined _Windows #include #endif -#include "osdefs.h" #include "amx.h" #if defined _UNICODE diff --git a/amx/amxcons.c b/amx/amxcons.c index d0958df..ef90e0f 100644 --- a/amx/amxcons.c +++ b/amx/amxcons.c @@ -22,7 +22,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: amxcons.c 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: amxcons.c 3853 2007-11-26 13:59:01Z thiadmer $ */ #if defined _UNICODE || defined __UNICODE__ || defined UNICODE @@ -46,7 +46,16 @@ #if defined USE_CURSES #include #endif -#include "amx.h" +#include "osdefs.h" +#if defined __ECOS__ + /* eCos puts include files in cyg/package_name */ + #include + #include + #include + #include +#else + #include "amx.h" +#endif #if defined __WIN32__ || defined _WIN32 || defined WIN32 #include #endif @@ -95,14 +104,44 @@ unsigned int amx_setattr(int foregr,int backgr,int highlight); void amx_console(int columns, int lines, int flags); int amx_kbhit(void); -#elif defined VT100 || defined LINUX || defined ANSITERM +#elif defined VT100 || defined __LINUX__ || defined ANSITERM || defined __ECOS__ /* ANSI/VT100 terminal, or shell emulating "xterm" */ - #define amx_putstr(s) printf("%s",(s)) - #define amx_putchar(c) putchar(c) - #define amx_fflush() fflush(stdout) - #define amx_getch() getch() - #define amx_gets(s,n) fgets(s,n,stdin) - #define amx_kbhit() kbhit() + #if defined __ECOS__ + #define AMXCONSOLE_NOIDLE + #endif + + #if CYGPKG_PAWN_AMXCONSOLE_DIAG==1 + /* eCos has basically two ways to make simple exchanges with a terminal: + * - with the diag_*() functions (no input provided!) + * - with f*() functions (fprintf(),fputs(), etc). + */ + #define amx_fflush() + + static int amx_putstr(TCHAR *s) + { + diag_write_string(s); + return 1; + } + static int amx_putchar(TCHAR c) + { + diag_write_char(c); + return c; + } + static char amx_getch(void) + { + char c=-1; + HAL_DIAG_READ_CHAR(c); + return c; + } + #else + + #define amx_putstr(s) fputs((s),stdout) + #define amx_putchar(c) putchar(c) + #define amx_fflush() fflush(stdout) + #define amx_getch() getch() + #define amx_gets(s,n) fgets(s,n,stdin) + #define amx_kbhit() kbhit() + #endif int amx_termctl(int code,int value) { @@ -350,11 +389,11 @@ #define amx_gets(s,n) getnstr(s,n) #define amx_clrscr() clear() #define amx_clreol() clrtoeol() - #define amx_gotoxy(x,y) (0) + #define amx_gotoxy(x,y) ((void)(x),(void)(y),(0)) #define amx_wherexy(x,y) (*(x)=*(y)=0) - #define amx_setattr(c,b,h) (0) - #define amx_termctl(c,v) (0) - #define amx_console(c,l,f) (void)(0) + #define amx_setattr(c,b,h) ((void)(c),(void)(b),(void)(h),(0)) + #define amx_termctl(c,v) ((void)(c),(void)(v),(0)) + #define amx_console(c,l,f) ((void)(c),(void)(l),(void)(f)) #define amx_kbhit() kbhit() #else /* assume a streaming terminal; limited features (no colour, no cursor @@ -999,18 +1038,19 @@ static cell AMX_NATIVE_CALL n_getchar(AMX *amx,const cell *params) static cell AMX_NATIVE_CALL n_getstring(AMX *amx,const cell *params) { int c,chars,max; - TCHAR *str; cell *cptr; CreateConsole(); - max=(int)params[2]; - if (max<=0) - return 0; - chars=0; - - str=(TCHAR *)alloca(max*sizeof(TCHAR)); - if (str!=NULL) { + max=(int)params[2]; + if (max>0) { + #if __STDC_VERSION__ >= 199901L + TCHAR str[max]; /* use C99 feature if available */ + #else + TCHAR *str=(TCHAR *)alloca(max*sizeof(TCHAR)); + if (str==NULL) + return chars; + #endif c=amx_getch(); while (c!=EOF && c!=EOL_CHAR && chars #include #include -#include "amx.h" +#include "osdefs.h" +#if defined __ECOS__ + /* eCos puts include files in cyg/package_name */ + #include + #define stricmp(a,b) strcasecmp(a,b) +#else + #include "amx.h" +#endif #if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined _Windows #include #endif diff --git a/amx/amxdbg.h b/amx/amxdbg.h index f8a77fe..89be313 100644 --- a/amx/amxdbg.h +++ b/amx/amxdbg.h @@ -21,7 +21,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: amxdbg.h 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: amxdbg.h 3845 2007-11-16 14:41:29Z thiadmer $ */ #ifndef AMXDBG_H_INCLUDED @@ -49,7 +49,7 @@ extern "C" { #endif #if !defined AMX_NO_ALIGN - #if defined LINUX || defined __FreeBSD__ + #if defined __LINUX__ || defined __FreeBSD__ #pragma pack(1) /* structures must be packed (byte-aligned) */ #elif defined MACOS && defined __MWERKS__ #pragma options align=mac68k @@ -157,7 +157,7 @@ int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX #if !defined AMX_NO_ALIGN - #if defined LINUX || defined __FreeBSD__ + #if defined __LINUX__ || defined __FreeBSD__ #pragma pack() /* reset default packing */ #elif defined MACOS && defined __MWERKS__ #pragma options align=reset diff --git a/amx/amxdgram.c b/amx/amxdgram.c index ea418e9..8d2dc4d 100644 --- a/amx/amxdgram.c +++ b/amx/amxdgram.c @@ -20,12 +20,13 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: amxdgram.c 3681 2006-12-01 10:20:23Z thiadmer $ + * Version: $Id: amxdgram.c 3845 2007-11-16 14:41:29Z thiadmer $ */ #include #include #include -#if defined LINUX +#include "osdefs.h" +#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ #include #include #include @@ -37,7 +38,6 @@ #include #include #endif -#include "osdefs.h" #include "amx.h" diff --git a/amx/amxfile.c b/amx/amxfile.c index b46e30f..ae77e19 100644 --- a/amx/amxfile.c +++ b/amx/amxfile.c @@ -18,7 +18,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: amxfile.c 3764 2007-05-22 10:29:16Z thiadmer $ + * Version: $Id: amxfile.c 3845 2007-11-16 14:41:29Z thiadmer $ */ #if defined _UNICODE || defined __UNICODE__ || defined UNICODE # if !defined UNICODE /* for Windows */ @@ -35,17 +35,17 @@ #include #include #include -#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined __MSDOS__ +#include "osdefs.h" +#if defined __WIN32__ || defined __MSDOS__ #include #include #endif -#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined _Windows +#if defined __WIN32__ || defined _Windows #include #endif -#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS +#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS #include #endif -#include "osdefs.h" #include "amx.h" #include "fpattern.c" @@ -662,7 +662,7 @@ static cell AMX_NATIVE_CALL n_fremove(AMX *amx, const cell *params) } /* bool: frename(const oldname[], const newname[]) */ -static cell AMX_NATIVE_CALL n_fremove(AMX *amx, const cell *params) +static cell AMX_NATIVE_CALL n_frename(AMX *amx, const cell *params) { int r=1; TCHAR *name,oldname[_MAX_PATH],newname[_MAX_PATH]; @@ -670,7 +670,7 @@ static cell AMX_NATIVE_CALL n_fremove(AMX *amx, const cell *params) amx_StrParam(amx,params[1],name); if (name!=NULL && completename(oldname,name,sizearray(oldname))!=NULL) { amx_StrParam(amx,params[2],name); - if (name!=NULL && completename(newname,name,sizearray(newname))!=NULL) { + if (name!=NULL && completename(newname,name,sizearray(newname))!=NULL) r=_trename(oldname,newname); } /* if */ return r==0; @@ -785,7 +785,7 @@ static cell AMX_NATIVE_CALL n_fmatch(AMX *amx, const cell *params) return fullname[0]!='\0'; } -/* bool: fstat(const name[], &size = 0, ×tamp = 0) */ +/* bool: fstat(const name[], &size = 0, ×tamp = 0, &mode = 0, &inode = 0) */ static cell AMX_NATIVE_CALL n_fstat(AMX *amx, const cell *params) { #if !(defined __WIN32__ || defined _WIN32 || defined WIN32) @@ -803,6 +803,10 @@ static cell AMX_NATIVE_CALL n_fstat(AMX *amx, const cell *params) *cptr=stbuf.st_size; amx_GetAddr(amx,params[3],&cptr); *cptr=stbuf.st_mtime; + amx_GetAddr(amx,params[4],&cptr); + *cptr=stbuf.st_mode; /* mode/protection bits */ + amx_GetAddr(amx,params[5],&cptr); + *cptr=stbuf.st_ino; /* inode number, unique id for a file */ result=1; } /* if */ } /* if */ diff --git a/amx/amxprocess.c b/amx/amxprocess.c index 8d0a89b..e144f6e 100644 --- a/amx/amxprocess.c +++ b/amx/amxprocess.c @@ -18,7 +18,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: amxprocess.c 3664 2006-11-08 12:09:25Z thiadmer $ + * Version: $Id: amxprocess.c 3845 2007-11-16 14:41:29Z thiadmer $ */ #if defined _UNICODE || defined __UNICODE__ || defined UNICODE # if !defined UNICODE /* for Windows */ @@ -35,12 +35,13 @@ #include #include #include -#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined _Windows +#include "osdefs.h" +#if defined __WIN32__ || defined __MSDOS__ #include #endif -#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined _Windows +#if defined __WIN32__ || defined _Windows #include -#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ +#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ #include #include #include @@ -54,7 +55,6 @@ */ #include #endif -#include "osdefs.h" #include "amx.h" #if defined _UNICODE @@ -104,7 +104,7 @@ static MODLIST ModRoot = { NULL }; /* pipes for I/O redirection */ #if defined __WIN32__ || defined _WIN32 || defined WIN32 static HANDLE newstdin,newstdout,read_stdout,write_stdin; -#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ +#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ static int pipe_to[2]={-1,-1}; static int pipe_from[2]={-1,-1}; void *inst_ffi=NULL; /* open handle for libffi */ @@ -157,7 +157,7 @@ static MODLIST _FAR *addlib(MODLIST *root, AMX *amx, const TCHAR *name) if (item->inst <= 32) item->inst = 0; #endif - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ /* also load the FFI library, if this is the first call */ inst_ffi=dlopen("libffi.so",RTLD_NOW); if (inst_ffi==NULL) @@ -184,7 +184,7 @@ static MODLIST _FAR *addlib(MODLIST *root, AMX *amx, const TCHAR *name) if (item->inst != 0) { #if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined _Windows FreeLibrary((HINSTANCE)item->inst); - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ dlclose((void*)item->inst); #else #error Unsupported environment @@ -209,7 +209,7 @@ static int freelib(MODLIST *root, AMX *amx, const TCHAR *name) assert(item->inst != 0); #if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined _Windows FreeLibrary((HINSTANCE)item->inst); - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ dlclose((void*)item->inst); #else #error Unsupported environment @@ -220,7 +220,7 @@ static int freelib(MODLIST *root, AMX *amx, const TCHAR *name) count++; } /* if */ } /* for */ - #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ if (amx==NULL && name==NULL && inst_ffi!=NULL) dlclose(inst_ffi); #endif @@ -399,7 +399,7 @@ static cell AMX_NATIVE_CALL n_libcall(AMX *amx, const cell *params) PARAM ps[MAXPARAMS]; cell *cptr,result; LIBFUNC LibFunc; - #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ ffi_cif cif; ffi_type *ptypes[MAXPARAMS]; void *pvalues[MAXPARAMS]; @@ -535,7 +535,7 @@ static cell AMX_NATIVE_CALL n_libcall(AMX *amx, const cell *params) * function should remove the parameters from the stack) */ result=LibFunc(); - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ /* use libffi (foreign function interface) */ for (idx = 0; idx < paramidx; idx++) { /* copy parameter types */ @@ -670,7 +670,7 @@ static void closepipe(void) CloseHandle(write_stdin); write_stdin=NULL; } /* if */ - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ if (pipe_to[0]>=0) { close(pipe_to[0]); pipe_to[0]=-1; @@ -706,7 +706,7 @@ static cell AMX_NATIVE_CALL n_procexec(AMX *amx, const cell *params) PROCESS_INFORMATION pi; #elif defined _Windows HINSTANCE hinst; - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ pid_t pid; #endif @@ -763,7 +763,7 @@ static cell AMX_NATIVE_CALL n_procexec(AMX *amx, const cell *params) if (hinst<=32) hinst=0; return (cell)hinst; - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ /* set up communication pipes first */ closepipe(); if (pipe(pipe_to)!=0 || pipe(pipe_from)!=0) { @@ -833,7 +833,7 @@ static cell AMX_NATIVE_CALL n_procwrite(AMX *amx, const cell *params) WriteFile(write_stdin,line,_tcslen(line),&num,NULL); //send it to stdin if (params[2]) WriteFile(write_stdin,__T("\n"),1,&num,NULL); - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ if (pipe_to[1]<0) return 0; write(pipe_to[1],line,_tcslen(line)); @@ -861,7 +861,7 @@ static cell AMX_NATIVE_CALL n_procread(AMX *amx, const cell *params) break; index++; } while (index includes + * and in this later file we can find CYGPKG_PAWN + * if the Pawn package was included with configtool and so we know + * that we are compiling for eCos. + */ +#include +#if defined CYGPKG_PAWN +# define __ECOS__ 1 +# define HAVE_ALLOCA_H 0 +#endif + + #if defined __FreeBSD__ - #include -#elif defined LINUX - #include +# include +#elif defined __LINUX__ +# include +#elif defined __ECOS__ +# include +# define BIG_ENDIAN 4321 +# define LITTLE_ENDIAN 1234 +# if (CYG_BYTEORDER == CYG_LSBFIRST) +# define BYTE_ORDER LITTLE_ENDIAN +# else +# define BYTE_ORDER BIG_ENDIAN +# endif + /* + * eCos option management. + */ +# include +# if CYGPKG_PAWN_AMX_ANSIONLY==1 +# define AMX_ANSIONLY +# endif +# define PAWN_CELL_SIZE CYGPKG_PAWN_AMX_CELLSIZE +# if CYGPKG_PAWN_CORE_RANDOM==0 +# define AMX_NORANDOM +# endif +# if CYGPKG_PAWN_CORE_PROPERTY==0 +# define AMX_NOPROPLIST +# endif +# if CYGPKG_PAWN_AMX_CONS_FIXEDPOINT==1 +# define FIXEDPOINT +# endif +# if CYGPKG_PAWN_AMX_CONS_FLOATPOINT==1 +# define FLOATPOINT +# endif #endif -/* Linux NOW has these */ +/* Linux now has these */ #if !defined BIG_ENDIAN #define BIG_ENDIAN 4321 #endif diff --git a/amx/pawndbg.c b/amx/pawndbg.c index abac102..4a2eb88 100644 --- a/amx/pawndbg.c +++ b/amx/pawndbg.c @@ -33,7 +33,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: pawndbg.c 3827 2007-10-16 14:53:31Z thiadmer $ + * Version: $Id: pawndbg.c 3845 2007-11-16 14:41:29Z thiadmer $ * * * Command line options: @@ -64,13 +64,13 @@ #include #include #endif -#include "osdefs.h" /* for _MAX_PATH */ +#include "osdefs.h" /* for _MAX_PATH and other macros */ #include "amx.h" #include "amxdbg.h" -#if defined __WIN32 || defined _WIN32 || defined __WIN32__ || defined __MSDOS__ || defined __WATCOMC__ +#if defined __WIN32__ || defined __MSDOS__ || defined __WATCOMC__ #include - #if defined __WIN32 || defined _WIN32 || defined __WIN32__ || defined __WATCOMC__ + #if defined __WIN32__ || defined __WATCOMC__ #if !defined __WIN32__ #define __WIN32__ 1 #endif @@ -86,7 +86,7 @@ #include #endif -#if !defined AMX_NODYNALOAD && (defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) +#if !defined AMX_NODYNALOAD && (defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) #include /* from BinReloc, see www.autopackage.org */ #endif @@ -127,9 +127,9 @@ #define CHR_HLINE '-' #endif #define CHR_VLINE '|' -#elif defined VT100 || defined LINUX || defined ANSITERM +#elif defined VT100 || defined __LINUX__ || defined ANSITERM /* ANSI/VT100 terminal, or shell emulating "xterm" */ - #if !defined VT100 && !defined ANSITERM && defined LINUX + #if !defined VT100 && !defined ANSITERM && defined __LINUX__ #define VT100 #endif #define amx_printf printf @@ -2675,7 +2675,7 @@ extern AMX_NATIVE_INFO console_Natives[]; unsigned short flags; char *ptr; - #if !defined AMX_NODYNALOAD && (defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) + #if !defined AMX_NODYNALOAD && (defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) /* see www.autopackage.org for the BinReloc module */ if (br_init(NULL)) { char *libroot=br_find_exe_dir(""); diff --git a/amx/pawnrun.c b/amx/pawnrun.c index d9fc2ef..25a16b8 100644 --- a/amx/pawnrun.c +++ b/amx/pawnrun.c @@ -19,7 +19,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: pawnrun.c 3830 2007-10-19 15:03:32Z thiadmer $ + * Version: $Id: pawnrun.c 3845 2007-11-16 14:41:29Z thiadmer $ */ #include #include @@ -34,7 +34,7 @@ #define CLOCKS_PER_SEC CLK_TCK #endif -#if !defined AMX_NODYNALOAD && (defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) +#if !defined AMX_NODYNALOAD && (defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) #include /* from BinReloc, see www.autopackage.org */ #endif @@ -323,7 +323,7 @@ int main(int argc,char *argv[]) if (argc < 2) PrintUsage(argv[0]); /* function "usage" aborts the program */ - #if !defined AMX_NODYNALOAD && (defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) + #if !defined AMX_NODYNALOAD && (defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) /* see www.autopackage.org for the BinReloc module */ if (br_init(NULL)) { char *libroot=br_find_exe_dir(""); diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt index 6e6919c..6c01169 100644 --- a/compiler/CMakeLists.txt +++ b/compiler/CMakeLists.txt @@ -22,7 +22,7 @@ IF(HAVE_ALLOCA_H) ENDIF(HAVE_ALLOCA_H) IF(UNIX) - ADD_DEFINITIONS(-DLINUX -DENABLE_BINRELOC -g) + ADD_DEFINITIONS(-DENABLE_BINRELOC -g) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../linux) LINK_LIBRARIES(pthread) #CMake adds the "lib" prefix, so "pthread" becomes "libpthread" ENDIF(UNIX) diff --git a/compiler/sc.h b/compiler/sc.h index 378035a..95516e9 100644 --- a/compiler/sc.h +++ b/compiler/sc.h @@ -25,7 +25,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: sc.h 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: sc.h 3853 2007-11-26 13:59:01Z thiadmer $ */ #ifndef SC_H_INCLUDED #define SC_H_INCLUDED @@ -314,13 +314,16 @@ typedef struct s_valuepair { #if !defined sizearray #define sizearray(a) (sizeof(a) / sizeof((a)[0])) #endif +#if !defined makelong + #define makelong(low,high) ((long)(low) | ((long)(high) << (sizeof(long)*4))) +#endif /* Tokens recognized by lex() * Some of these constants are assigned as well to the variable "lastst" (see SC1.C) */ #define tFIRST 256 /* value of first multi-character operator */ #define tMIDDLE 280 /* value of last multi-character operator */ -#define tLAST 328 /* value of last multi-character match-able token */ +#define tLAST 323 /* value of last multi-character match-able token */ /* multi-character operators */ #define taMULT 256 /* *= */ #define taDIV 257 /* /= */ @@ -349,65 +352,60 @@ typedef struct s_valuepair { #define tDBLCOLON 280 /* :: */ /* reserved words (statements) */ #define tASSERT 281 -#define tBEGIN 282 -#define tBREAK 283 -#define tCASE 284 -#define tCHAR 285 -#define tCONST 286 -#define tCONTINUE 287 -#define tDEFAULT 288 -#define tDEFINED 289 -#define tDO 290 -#define tELSE 291 -#define tEND 292 -#define tENUM 293 -#define tEXIT 294 -#define tFOR 295 -#define tFORWARD 296 -#define tGOTO 297 -#define tIF 298 -#define tNATIVE 299 -#define tNEW 300 -#define tOPERATOR 301 -#define tPUBLIC 302 -#define tRETURN 303 -#define tSIZEOF 304 -#define tSLEEP 305 -#define tSTATE 306 -#define tSTATIC 307 -#define tSTOCK 308 -#define tSWITCH 309 -#define tTAGOF 310 -#define tTHEN 311 -#define tWHILE 312 +#define tBREAK 282 +#define tCASE 283 +#define tCHAR 284 +#define tCONST 285 +#define tCONTINUE 286 +#define tDEFAULT 287 +#define tDEFINED 288 +#define tDO 289 +#define tELSE 290 +#define tENUM 291 +#define tEXIT 292 +#define tFOR 293 +#define tFORWARD 294 +#define tGOTO 295 +#define tIF 296 +#define tNATIVE 297 +#define tNEW 298 +#define tOPERATOR 299 +#define tPUBLIC 300 +#define tRETURN 301 +#define tSIZEOF 302 +#define tSLEEP 303 +#define tSTATE 304 +#define tSTATIC 305 +#define tSTOCK 306 +#define tSWITCH 307 +#define tTAGOF 308 +#define tWHILE 309 /* compiler directives */ -#define tpASSERT 313 /* #assert */ -#define tpDEFINE 314 -#define tpELSE 315 /* #else */ -#define tpELSEIF 316 /* #elseif */ -#define tpEMIT 317 -#define tpENDIF 318 -#define tpENDINPUT 319 -#define tpENDSCRPT 320 -#define tpERROR 321 -#define tpFILE 322 -#define tpIF 323 /* #if */ -#define tINCLUDE 324 -#define tpLINE 325 -#define tpPRAGMA 326 -#define tpTRYINCLUDE 327 -#define tpUNDEF 328 +#define tpASSERT 310 /* #assert */ +#define tpDEFINE 311 +#define tpELSE 312 /* #else */ +#define tpELSEIF 313 /* #elseif */ +#define tpENDIF 314 +#define tpENDINPUT 315 +#define tpERROR 316 +#define tpFILE 317 +#define tpIF 318 /* #if */ +#define tINCLUDE 319 +#define tpLINE 320 +#define tpPRAGMA 321 +#define tpTRYINCLUDE 322 +#define tpUNDEF 323 /* semicolon is a special case, because it can be optional */ -#define tTERM 329 /* semicolon or newline */ -#define tENDEXPR 330 /* forced end of expression */ +#define tTERM 324 /* semicolon or newline */ +#define tENDEXPR 325 /* forced end of expression */ /* other recognized tokens */ -#define tNUMBER 331 /* integer number */ -#define tRATIONAL 332 /* rational number */ -#define tSYMBOL 333 -#define tLABEL 334 -#define tSTRING 335 -#define tEXPR 336 /* for assigment to "lastst" only (see SC1.C) */ -#define tENDLESS 337 /* endless loop, for assigment to "lastst" only */ +#define tNUMBER 326 /* integer number */ +#define tRATIONAL 327 /* rational number */ +#define tSYMBOL 328 +#define tLABEL 329 +#define tSTRING 330 +#define tEXPR 331 /* for assigment to "lastst" only (see SC1.C) */ +#define tENDLESS 332 /* endless loop, for assigment to "lastst" only */ /* (reversed) evaluation of staging buffer */ #define sSTARTREORDER 0x01 @@ -691,8 +689,13 @@ SC_FUNC void jmp_eq0(int number); SC_FUNC void outval(cell val,int fullcell,int newline); /* function prototypes in SC5.C */ -SC_FUNC int error(int number,...); +SC_FUNC int error(long number,...); +SC_FUNC int error_suggest(int error,const char *name,int ident); SC_FUNC void errorset(int code,int line); +#define MAX_EDIT_DIST 2 /* allow two mis-typed characters; when there are more, + * the names are too different, and no match is returned */ +SC_FUNC int levenshtein_distance(const char *s,const char*t); +SC_FUNC symbol *find_closestsymbol(const char *name,int symboltype); /* function prototypes in SC6.C */ SC_FUNC ucell getparamvalue(const char *s,const char **n); @@ -769,10 +772,10 @@ SC_FUNC int scan_utf8(FILE *fp,const char *filename); /* function prototypes in SCSTATE.C */ SC_FUNC constvalue *automaton_add(const char *name); -SC_FUNC constvalue *automaton_find(const char *name); +SC_FUNC constvalue *automaton_find(const char *name,char *closestmatch); SC_FUNC constvalue *automaton_findid(int id); SC_FUNC constvalue *state_add(const char *name,int fsa_id); -SC_FUNC constvalue *state_find(const char *name,int fsa_id); +SC_FUNC constvalue *state_find(const char *name,int fsa_id,char *closestmatch); SC_FUNC constvalue *state_findid(int id); SC_FUNC void state_buildlist(int **list,int *listsize,int *count,int stateid); SC_FUNC int state_addlist(int *list,int count,int fsa_id); diff --git a/compiler/sc1.c b/compiler/sc1.c index 860abba..abc3a7f 100644 --- a/compiler/sc1.c +++ b/compiler/sc1.c @@ -20,7 +20,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: sc1.c 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: sc1.c 3853 2007-11-26 13:59:01Z thiadmer $ */ #include #include @@ -35,7 +35,7 @@ #include #endif -#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ +#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ #include #include /* from BinReloc, see www.autopackage.org */ #endif @@ -64,8 +64,8 @@ #include "lstring.h" #include "sc.h" #include "svnrev.h" -#define VERSION_STR "3.3." SVN_REVSTR -#define VERSION_INT 0x0303 +#define VERSION_STR "4.0." SVN_REVSTR +#define VERSION_INT 0x0400 static void resetglobals(void); static void initglobals(void); @@ -111,7 +111,7 @@ static void destructsymbols(symbol *root,int level); static constvalue *find_constval_byval(constvalue *table,cell val); static symbol *fetchlab(char *name); static void statement(int *lastindent,int allow_decl); -static void compound(int stmt_sameline,int starttok); +static void compound(int stmt_sameline); static int test(int label,int parens,int invert); static int doexpr(int comma,int chkeffect,int allowarray,int mark_endexpr, int *tag,symbol **symptr,int chkfuncresult); @@ -133,12 +133,6 @@ static void addwhile(int *ptr); static void delwhile(void); static int *readwhile(void); -enum { - TEST_PLAIN, /* no parentheses */ - TEST_THEN, /* '(' ')' or 'then' */ - TEST_DO, /* '(' ')' or 'do' */ - TEST_OPT, /* '(' ')' or */ -}; static int lastst = 0; /* last executed statement type */ static int nestlevel = 0; /* number of active (open) compound statements */ static int endlessloop= 0; /* nesting level of endless loop */ @@ -400,6 +394,9 @@ long pc_lengthbin(void *handle) /* "main" of the compiler */ +# if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined __NT__ + __declspec (dllexport) +#endif #if defined __cplusplus extern "C" #endif @@ -632,10 +629,10 @@ int pc_compile(int argc, char *argv[]) lexinit(); /* clear internal flags of lex() */ sc_status=statWRITE; /* allow to write --this variable was reset by resetglobals() */ i=writeleader(&glbtab); + reduce_referrers(&glbtab); /* test for unused functions */ gen_ovlinfo(&glbtab); /* generate overlay information */ writestatetables(&glbtab,i); /* create state tables and additional overlay information */ /* reset "defined" flag of all functions and global variables */ - reduce_referrers(&glbtab); delete_symbols(&glbtab,0,TRUE,FALSE); insert_dbgfile(inpfname); if (strlen(incfname)>0) { @@ -678,31 +675,35 @@ int pc_compile(int argc, char *argv[]) #if !defined PAWN_LIGHT if (errnum==0 && strlen(errfname)==0) { int recursion; - long stacksize=max_stacksize(&glbtab,&recursion); int flag_exceed=0; + long stacksize=max_stacksize(&glbtab,&recursion); long max_ovlsize=(pc_overlays>0) ? max_overlaysize(&glbtab) : 0; - if (pc_amxlimit>0) { - long totalsize=hdrsize; - if (pc_overlays==0) - totalsize+=code_idx; - else if (pc_overlays==1) - totalsize+=max_ovlsize; - if (pc_amxram==0) - totalsize+=(glb_declared+pc_stksize)*sizeof(cell); - if (totalsize>=pc_amxlimit) - flag_exceed=1; - } /* if */ + long totalsize=hdrsize; + if (pc_overlays==0) + totalsize+=code_idx; + else if (pc_overlays==1) + totalsize+=max_ovlsize; + else + totalsize+=pc_overlays; + if (pc_amxram==0) + totalsize+=(glb_declared+pc_stksize)*sizeof(cell); + if (pc_amxlimit>0 && totalsize>=pc_amxlimit) + flag_exceed=1; if (pc_amxram>0 && (glb_declared+pc_stksize)*sizeof(cell)>=(unsigned long)pc_amxram) flag_exceed=1; if ((sc_debug & sSYMBOLIC)!=0 || verbosity>=2 || stacksize+32>=(long)pc_stksize || flag_exceed) { if (errnum>0 || warnnum>0) pc_printf("\n"); - pc_printf("Header size: %8ld bytes\n", (long)hdrsize); - pc_printf("Code size: %8ld bytes\n", (long)code_idx); - if (pc_overlays>0) - pc_printf("Max. overlay size: %8ld bytes\n", max_ovlsize); - pc_printf("Data size: %8ld bytes\n", (long)glb_declared*sizeof(cell)); - pc_printf("Stack/heap size: %8ld bytes; ", (long)pc_stksize*sizeof(cell)); + pc_printf("Header size: %8ld bytes\n",(long)hdrsize); + pc_printf("Code size: %8ld bytes\n",(long)code_idx); + if (pc_overlays>0) { + if (pc_overlays>1) + pc_printf("Max. overlay size: %8ld bytes; largest overlay=%ld bytes\n",(long)pc_overlays,(long)max_ovlsize); + else + pc_printf("Largest overlay: %8ld bytes\n",(long)max_ovlsize); + } /* if */ + pc_printf("Data size: %8ld bytes\n",(long)glb_declared*sizeof(cell)); + pc_printf("Stack/heap size: %8ld bytes; ",(long)pc_stksize*sizeof(cell)); pc_printf("estimated max. use"); if (recursion) pc_printf(": unknown, due to recursion\n"); @@ -710,7 +711,10 @@ int pc_compile(int argc, char *argv[]) pc_printf(": unknown, due to \"sleep\" instruction\n"); else pc_printf("=%ld cells (%ld bytes)\n",stacksize,stacksize*sizeof(cell)); - pc_printf("Total requirements:%8ld bytes\n", (long)hdrsize+(long)code_idx+(long)glb_declared*sizeof(cell)+(long)pc_stksize*sizeof(cell)); + pc_printf("Total requirements:%8ld bytes",(long)totalsize); + if (pc_amxram>0) + pc_printf(" plus %ld bytes for data/stack",(long)(glb_declared+pc_stksize)*sizeof(cell)); + pc_printf("\n"); } /* if */ if (pc_overlays>1 && max_ovlsize>pc_overlays) error(112,max_ovlsize-(1<<4*sizeof(cell))); //??? should also tell which function is causing this error @@ -764,8 +768,6 @@ int pc_compile(int argc, char *argv[]) retcode=0; /* use "0", so that MAKE and similar tools continue */ } else { retcode=jmpcode; - if (retcode==0 && verbosity>=2) - pc_printf("\nDone.\n"); } /* if */ #if defined __WIN32__ || defined _WIN32 || defined _Windows if (IsWindow(hwndFinish)) @@ -777,6 +779,9 @@ int pc_compile(int argc, char *argv[]) return retcode; } +# if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined __NT__ + __declspec (dllexport) +#endif #if defined __cplusplus extern "C" #endif @@ -788,6 +793,9 @@ int pc_addconstant(char *name,cell value,int tag) return 1; } +# if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined __NT__ + __declspec (dllexport) +#endif #if defined __cplusplus extern "C" #endif @@ -1327,7 +1335,7 @@ static void setconfig(char *root) /* add the default "include" directory */ #if defined __WIN32__ || defined _WIN32 GetModuleFileName(NULL,path,_MAX_PATH); - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ /* see www.autopackage.org for the BinReloc module */ br_init_lib(NULL); ptr=br_find_exe("/opt/Pawn/bin/pawncc"); @@ -3482,7 +3490,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc check_operatortag(opertok,tag,symbolname); } else { if (tok!=tSYMBOL && freading) { - error(20,str); /* invalid symbol name */ + error_suggest(20,str,iFUNCTN); /* invalid symbol name */ return FALSE; } /* if */ assert(strlen(str)<=sNAMEMAX); @@ -3860,7 +3868,7 @@ static int declargs(symbol *sym,int chkshadow) for (altidx=0; altidx=argcnt) { - error(17,ptr); /* undefined symbol */ + error(17,ptr); /* undefined symbol */ //??? search through argument names } else { assert(arglist[idx].defvalue.size.symname!=NULL); /* check the level against the number of dimensions */ @@ -4162,7 +4170,7 @@ static char *xmlencode(char *dest,char *source) static void make_report(symbol *root,FILE *log,char *sourcefile) { char symname[_MAX_PATH]; - int i,arg; + int i,arg,dim; symbol *sym,*ref; constvalue *tagsym; constvalue *enumroot; @@ -4279,7 +4287,18 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) continue; /* hierarchical data type */ if (sym->ident!=iVARIABLE && sym->ident!=iARRAY) continue; - fprintf(log,"\t\t\n",funcdisplayname(symname,sym->name)); + funcdisplayname(symname,sym->name); + fprintf(log,"\t\tident==iARRAY) { + for (ref=sym; ref!=NULL; ref=finddepend(ref)) { + tagsym=(ref->x.tags.index!=0) ? find_tag_byval(ref->x.tags.index) : NULL; + if (tagsym!=NULL) + fprintf(log,"[%s]",tagsym->name); + else + fprintf(log,"[%ld]",(long)ref->dim.array.length); + } /* for */ + } /* if */ + fprintf(log,"\">\n",funcdisplayname(symname,sym->name)); if (sym->tag!=0) { tagsym=find_tag_byval(sym->tag); assert(tagsym!=NULL); @@ -4311,7 +4330,6 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) /* print only the names of the parameters between the parentheses */ assert(sym->dim.arglist!=NULL); for (arg=0; sym->dim.arglist[arg].ident!=0; arg++) { - int dim; if (arg>0) fprintf(log,", "); switch (sym->dim.arglist[arg].ident) { @@ -4415,8 +4433,11 @@ static void make_report(symbol *root,FILE *log,char *sourcefile) if (sym->dim.arglist[arg].dim[dim]==0) { fprintf(log,"[]"); } else { - //??? find index tag - fprintf(log,"[%d]",sym->dim.arglist[arg].dim[dim]); + tagsym=(sym->dim.arglist[arg].idxtag[dim]!=0) ? find_tag_byval(sym->dim.arglist[arg].idxtag[dim]) : NULL; + if (tagsym!=NULL) + fprintf(log,"[%s]",tagsym->name); + else + fprintf(log,"[%d]",sym->dim.arglist[arg].dim[dim]); } /* if */ } /* for */ break; @@ -4688,7 +4709,7 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst) case iLABEL: if (testlabs) { if ((sym->usage & uDEFINE)==0) { - error(19,sym->name); /* not a label: ... */ + error_suggest(19,sym->name,iLABEL); /* not a label: ... */ } else if ((sym->usage & uREAD)==0) { errorset(sSETPOS,sym->lnumber); error(203,sym->name); /* symbol isn't used: ... */ @@ -5013,10 +5034,9 @@ static void statement(int *lastindent,int allow_decl) } /* if */ break; case '{': - case tBEGIN: save=fline; if (!matchtoken('}')) /* {} is the empty statement */ - compound(save==fline,tok); + compound(save==fline); /* lastst (for "last statement") does not change */ break; case ';': @@ -5094,24 +5114,23 @@ static void statement(int *lastindent,int allow_decl) } /* switch */ } -static void compound(int stmt_sameline,int starttok) +static void compound(int stmt_sameline) { int indent=-1; cell save_decl=declared; int count_stmt=0; int block_start=fline; /* save line where the compound block started */ - int endtok; /* if there is more text on this line, we should adjust the statement indent */ if (stmt_sameline) { int i; const unsigned char *p=lptr; /* go back to the opening brace */ - while (*p!=starttok) { + while (*p!='{') { assert(p>pline); p--; } /* while */ - assert(*p==starttok); /* it should be found */ + assert(*p=='{'); /* it should be found */ /* go forward, skipping white-space */ p++; while (*p<=' ' && *p!='\0') @@ -5125,9 +5144,8 @@ static void compound(int stmt_sameline,int starttok) stmtindent++; } /* if */ - endtok=(starttok=='{') ? '}' : tEND; nestlevel+=1; /* increase compound statement level */ - while (matchtoken(endtok)==0){/* repeat until compound statement is closed */ + while (!matchtoken('}')){ /* repeat until compound statement is closed */ if (!freading){ error(30,block_start); /* compound block not closed at end of file */ break; @@ -5231,7 +5249,6 @@ static int test(int label,int parens,int invert) int index,tok; cell cidx; int ident,tag; - int endtok; cell constval; symbol *sym; int localstaging=FALSE; @@ -5247,15 +5264,8 @@ static int test(int label,int parens,int invert) PUSHSTK_I(sc_intest); sc_intest=TRUE; - endtok=0; - if (parens!=TEST_PLAIN) { - if (matchtoken('(')) - endtok=')'; - else if (parens==TEST_THEN) - endtok=tTHEN; - else if (parens==TEST_DO) - endtok=tDO; - } /* if */ + if (parens) + needtoken('('); do { stgget(&index,&cidx); /* mark position (of last expression) in * code generator */ @@ -5264,8 +5274,8 @@ static int test(int label,int parens,int invert) if (tok) markexpr(sEXPR,NULL,0); } while (tok); /* do */ - if (endtok!=0) - needtoken(endtok); + if (parens) + needtoken(')'); if (ident==iARRAY || ident==iREFARRAY) { char *ptr=(sym->name!=NULL) ? sym->name : "-unknown-"; error(33,ptr); /* array must be indexed */ @@ -5312,7 +5322,7 @@ static int doif(void) ifindent=stmtindent; /* save the indent of the "if" instruction */ flab1=getlabel(); /* get label number for false branch */ - test(flab1,TEST_THEN,FALSE); /* get expression, branch to flab1 if false */ + test(flab1,TRUE,FALSE); /* get expression, branch to flab1 if false */ statement(NULL,FALSE); /* if true, do a statement */ if (!matchtoken(tELSE)) { /* if...else ? */ setlabel(flab1); /* no, simple if..., print false label */ @@ -5351,7 +5361,7 @@ static int dowhile(void) * tiniest loop, set it below the top of the loop */ setline(TRUE); - endlessloop=test(wq[wqEXIT],TEST_DO,FALSE);/* branch to wq[wqEXIT] if false */ + endlessloop=test(wq[wqEXIT],TRUE,FALSE);/* branch to wq[wqEXIT] if false */ statement(NULL,FALSE); /* if so, do a statement */ jumplabel(wq[wqLOOP]); /* and loop to "while" start */ setlabel(wq[wqEXIT]); /* exit label */ @@ -5379,7 +5389,7 @@ static int dodo(void) needtoken(tWHILE); setlabel(wq[wqLOOP]); /* "continue" always jumps to WQLOOP. */ setline(TRUE); - endlessloop=test(wq[wqEXIT],TEST_OPT,FALSE); + endlessloop=test(wq[wqEXIT],TRUE,FALSE); jumplabel(top); setlabel(wq[wqEXIT]); delwhile(); @@ -5444,7 +5454,7 @@ static int dofor(void) if (matchtoken(';')) { endlessloop=1; } else { - endlessloop=test(wq[wqEXIT],TEST_PLAIN,FALSE);/* expression 2 (jump to wq[wqEXIT] if false) */ + endlessloop=test(wq[wqEXIT],FALSE,FALSE);/* expression 2 (jump to wq[wqEXIT] if false) */ needtoken(';'); } /* if */ stgmark((char)(sEXPRSTART+1)); /* mark start of 3th expression in stage */ @@ -5494,16 +5504,16 @@ static void doswitch(void) { int lbl_table,lbl_exit,lbl_case; int swdefault,casecount; - int tok,endtok; + int tok; cell val; char *str; constvalue caselist = { NULL, "", 0, 0}; /* case list starts empty */ constvalue *cse,*csp; int label; - endtok= matchtoken('(') ? ')' : tDO; + needtoken('('); doexpr(TRUE,FALSE,FALSE,FALSE,NULL,NULL,TRUE);/* evaluate switch expression */ - needtoken(endtok); + needtoken(')'); /* generate the code for the switch statement, the label is the address * of the case table (to be generated later). */ @@ -5511,12 +5521,7 @@ static void doswitch(void) lbl_case=0; /* just to avoid a compiler warning */ ffswitch(lbl_table,FALSE); - if (matchtoken(tBEGIN)) { - endtok=tEND; - } else { - endtok='}'; - needtoken('{'); - } /* if */ + needtoken('{'); lbl_exit=getlabel(); /* get label number for jumping out of switch */ swdefault=FALSE; casecount=0; @@ -5603,13 +5608,13 @@ static void doswitch(void) jumplabel(lbl_exit); break; default: - if (tok!=endtok) { + if (tok!='}') { error(2); indent_nowarn=TRUE; /* disable this check */ - tok=endtok; /* break out of the loop after an error */ + tok='}'; /* break out of the loop after an error */ } /* if */ } /* switch */ - } while (tok!=endtok); + } while (tok!='}'); #if !defined NDEBUG /* verify that the case table is sorted (unfortunatly, duplicates can @@ -5644,7 +5649,7 @@ static void doassert(void) if ((sc_debug & sCHKBOUNDS)!=0) { flab1=getlabel(); /* get label number for "OK" branch */ - test(flab1,TEST_PLAIN,TRUE);/* get expression and branch to flab1 if true */ + test(flab1,FALSE,TRUE);/* get expression and branch to flab1 if true */ insert_dbgline(fline); /* make sure we can find the correct line number */ ffabort(xASSERTION); setlabel(flab1); @@ -5672,12 +5677,12 @@ static void dogoto(void) if (lex(&val,&st)==tSYMBOL) { sym=fetchlab(st); jumplabel((int)sym->addr); - sym->usage|=uREAD; /* set "uREAD" bit */ + sym->usage|=uREAD; /* set "uREAD" bit */ // ??? if the label is defined (check sym->usage & uDEFINE), check // sym->compound (nesting level of the label) against nestlevel; // if sym->compound < nestlevel, call the destructor operator } else { - error(20,st); /* illegal symbol name */ + error_suggest(20,st,iLABEL);/* illegal symbol name */ } /* if */ needtoken(tTERM); } @@ -5715,7 +5720,7 @@ static symbol *fetchlab(char *name) sym=findloc(name); /* labels are local in scope */ if (sym){ if (sym->ident!=iLABEL) - error(19,sym->name); /* not a label: ... */ + error_suggest(19,sym->name,iLABEL); /* not a label: ... */ } else { sym=addsym(name,getlabel(),iLABEL,sLOCAL,0,0); assert(sym!=NULL); /* fatal error 103 must be given on error */ @@ -5941,7 +5946,7 @@ static void dostate(void) if (matchtoken('(')) { flabel=getlabel(); /* get label number for "false" branch */ pc_docexpr=TRUE; /* attach expression as a documentation string */ - test(flabel,TEST_PLAIN,FALSE);/* get expression, branch to flabel if false */ + test(flabel,FALSE,FALSE);/* get expression, branch to flabel if false */ pc_docexpr=FALSE; needtoken(')'); } else { diff --git a/compiler/sc2.c b/compiler/sc2.c index 564cc5c..a3c8b66 100644 --- a/compiler/sc2.c +++ b/compiler/sc2.c @@ -18,7 +18,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: sc2.c 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: sc2.c 3853 2007-11-26 13:59:01Z thiadmer $ */ #include #include @@ -28,7 +28,7 @@ #include #include "lstring.h" #include "sc.h" -#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ +#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ #include #endif @@ -175,7 +175,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths) int result=FALSE; if (try_currentpath) { - /* try to open the file in the same directory as the current file --but + /* try to open the file in the same directory as the current file --but * first check whether there is a (relative) path for the current file */ char *ptr; @@ -189,7 +189,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths) } /* if */ } else { /* there is no path for the current source file, meaning that it comes - * from the active directory; try to open the file from the active + * from the active directory; try to open the file from the active * directory too */ result=plungequalifiedfile(name); @@ -206,7 +206,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths) result=plungequalifiedfile(path); } /* while */ } /* if */ - + return result; } @@ -271,12 +271,23 @@ static void doinclude(int silent) strlcat(symname,ptr+1,sizeof symname); else strlcat(symname,name,sizeof symname); + /* replace invalid characters by '_' (anything not a digit, character or underscore) */ + for (i=0; symname[i]!='\0'; i++) + if (!alphanum(symname[i])) + symname[i]='_'; + #if defined __WIN32__ || defined _WIN32 || defined _Windows || defined __MSDOS__ + /* on systems with case-insentive filenames, force the symbol for the file + * to lower case + */ + strlwr(symname); + #endif if (find_symbol(&glbtab,symname,fcurrent,-1,NULL)==NULL) { /* constant is not present, so this file has not been included yet */ - /* Include files between "..." or without quotes are read from the current - * directory, or from a list of "include directories". Include files - * between <...> are only read from the list of include directories. + /* Include files between "..." or without quotes are read from the same + * relative path as the current file, from the active directory, or from + * a list of "include directories". Include files between <...> are only + * read from the list of include directories. */ result=plungefile(name,(c!='>'),TRUE); if (result) @@ -1191,7 +1202,6 @@ static int command(void) } /* if */ break; case tpENDINPUT: - case tpENDSCRPT: if (!SKIPPING) { check_empty(lptr); assert(inpf!=NULL); @@ -1200,62 +1210,6 @@ static int command(void) inpf=NULL; } /* if */ break; -#if !defined NOEMIT - case tpEMIT: { - /* write opcode to output file */ - char name[40]; - int i; - while (*lptr<=' ' && *lptr!='\0') - lptr++; - for (i=0; i<40 && (isalpha(*lptr) || *lptr=='.'); i++,lptr++) - name[i]=(char)tolower(*lptr); - name[i]='\0'; - stgwrite("\t"); - stgwrite(name); - stgwrite(" "); - code_idx+=opcodes(1); - /* write parameter (if any) */ - while (*lptr<=' ' && *lptr!='\0') - lptr++; - if (*lptr!='\0') { - symbol *sym; - tok=lex(&val,&str); - switch (tok) { - case tNUMBER: - case tRATIONAL: - outval(val,TRUE,FALSE); - code_idx+=opargs(1); - break; - case tSYMBOL: - sym=findloc(str); - if (sym==NULL) - sym=findglb(str,sSTATEVAR); - if (sym==NULL || sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) { - error(17,str); /* undefined symbol */ - } else { - outval(sym->addr,TRUE,FALSE); - /* mark symbol as "used", unknown whether for read or write */ - markusage(sym,uREAD | uWRITTEN); - code_idx+=opargs(1); - } /* if */ - break; - default: { - char s2[20]; - extern char *sc_tokens[];/* forward declaration */ - if (tok<256) - sprintf(s2,"%c",(char)tok); - else - strcpy(s2,sc_tokens[tok-tFIRST]); - error(1,sc_tokens[tSYMBOL-tFIRST],s2); - break; - } /* case */ - } /* switch */ - } /* if */ - stgwrite("\n"); - check_empty(lptr); - break; - } /* case */ -#endif #if !defined NO_DEFINE case tpDEFINE: { ret=CMD_DEFINE; @@ -1835,12 +1789,12 @@ char *sc_tokens[] = { "*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=", "||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--", "...", "..", "::", - "assert", "*begin", "break", "case", "char", "const", "continue", "default", - "defined", "do", "else", "*end", "enum", "exit", "for", "forward", "goto", + "assert", "break", "case", "char", "const", "continue", "default", + "defined", "do", "else", "enum", "exit", "for", "forward", "goto", "if", "native", "new", "operator", "public", "return", "sizeof", - "sleep", "state", "static", "stock", "switch", "tagof", "*then", "while", - "#assert", "#define", "#else", "#elseif", "#emit", "#endif", "#endinput", - "#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma", + "sleep", "state", "static", "stock", "switch", "tagof", "while", + "#assert", "#define", "#else", "#elseif", "#endif", "#endinput", + "#error", "#file", "#if", "#include", "#line", "#pragma", "#tryinclude", "#undef", ";", ";", "-integer value-", "-rational value-", "-identifier-", "-label-", "-string-" diff --git a/compiler/sc3.c b/compiler/sc3.c index 04d2d45..82fba1d 100644 --- a/compiler/sc3.c +++ b/compiler/sc3.c @@ -18,7 +18,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: sc3.c 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: sc3.c 3848 2007-11-20 11:48:34Z thiadmer $ */ #include #include @@ -140,10 +140,10 @@ static int isbinaryop(int tok) '=' }; int idx; - + for (idx=0; idxusage & uDEFINE)==0*/) { /* ??? should not check uDEFINE; first pass clears these bits */ + if (sym==NULL /*|| (sym->usage & uDEFINE)==0*/) { /* should not check uDEFINE; first pass clears these bits */ /* check for commutative operators */ if (tag1==tag2 || oper==NULL || !commutative(oper)) return FALSE; /* not commutative, cannot swap operands */ @@ -846,7 +846,7 @@ SC_FUNC int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult) SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state,char *statename) { - char name[sNAMEMAX+1]; + char name[sNAMEMAX+1],closestmatch[sNAMEMAX+1]; cell val; char *str; int fsa,islabel; @@ -861,7 +861,7 @@ SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state,char *staten strcpy(name,str); if (islabel || matchtoken(':')) { /* token is an automaton name, add the name and get a new token */ - *automaton=automaton_find(name); + *automaton=automaton_find(name,closestmatch); /* read in the state name before checking the automaton, to keep the parser * going (an "unknown automaton" error may occur when the "state" instruction * precedes any state definition) @@ -870,14 +870,17 @@ SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state,char *staten return 0; tokeninfo(&val,&str); /* do not copy the name yet, must check automaton first */ if (*automaton==NULL) { - error(86,name); /* unknown automaton */ + if (*closestmatch!='\0') + error(makelong(86,1),name,closestmatch); + else + error(86,name); /* unknown automaton */ return 0; } /* if */ assert((*automaton)->index>0); assert(strlen(str)index==0); } /* if */ @@ -887,12 +890,15 @@ SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state,char *staten if (statename!=NULL) strcpy(statename,name); - *state=state_find(name,fsa); + *state=state_find(name,fsa,closestmatch); if (*state==NULL) { char *fsaname=(*automaton)->name; if (*fsaname=='\0') fsaname="
"; - error(87,name,fsaname); /* unknown state for automaton */ + if (*closestmatch!='\0') + error(makelong(87,1),name,fsaname,closestmatch); + else + error(87,name,fsaname); /* unknown state for automaton */ return 0; } /* if */ @@ -1369,7 +1375,7 @@ static int hier2(value *lval) paranthese++; tok=lex(&val,&st); if (tok!=tSYMBOL) - return error(20,st); /* illegal symbol name */ + return error_suggest(20,st,iVARIABLE); /* illegal symbol name */ sym=findloc(st); if (sym==NULL) sym=findglb(st,sSTATEVAR); @@ -1392,18 +1398,18 @@ static int hier2(value *lval) paranthese++; tok=lex(&val,&st); if (tok!=tSYMBOL) - return error(20,st); /* illegal symbol name */ + return error_suggest(20,st,iVARIABLE); /* illegal symbol name */ sym=findloc(st); if (sym==NULL) sym=findglb(st,sSTATEVAR); if (sym==NULL) - return error(17,st); /* undefined symbol */ + return error_suggest(17,st,iVARIABLE); /* undefined symbol */ if (sym->ident==iCONSTEXPR) error(39); /* constant symbol has no size */ else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) error(72); /* "function" symbol has no size */ else if ((sym->usage & uDEFINE)==0) - return error(17,st); /* undefined symbol (symbol is in the table, but it is "used" only) */ + return error_suggest(17,st,iVARIABLE); /* undefined symbol (symbol is in the table, but it is "used" only) */ clear_value(lval); lval->ident=iCONSTEXPR; lval->constval=1; /* preset */ @@ -1418,7 +1424,7 @@ static int hier2(value *lval) int cmptag=subsym->x.tags.index; tokeninfo(&val,&idxname); if ((idxsym=findconst(idxname,&cmptag))==NULL) - error(80,idxname); /* unknown symbol, or non-constant */ + error_suggest(80,idxname,iCONSTEXPR); /* unknown symbol, or non-constant */ else if (cmptag>1) error(91,idxname); /* ambiguous constant */ } /* if */ @@ -1445,7 +1451,7 @@ static int hier2(value *lval) paranthese++; tok=lex(&val,&st); if (tok!=tSYMBOL && tok!=tLABEL) - return error(20,st); /* illegal symbol name */ + return error_suggest(20,st,iVARIABLE); /* illegal symbol name */ if (tok==tLABEL) { constvalue *tagsym=find_constval(&tagname_tab,st,0); tag=(int)((tagsym!=NULL) ? tagsym->value : 0); @@ -1454,9 +1460,9 @@ static int hier2(value *lval) if (sym==NULL) sym=findglb(st,sSTATEVAR); if (sym==NULL) - return error(17,st); /* undefined symbol */ + return error_suggest(17,st,iVARIABLE); /* undefined symbol */ if ((sym->usage & uDEFINE)==0) - return error(17,st); /* undefined symbol (symbol is in the table, but it is "used" only) */ + return error_suggest(17,st,iVARIABLE); /* undefined symbol (symbol is in the table, but it is "used" only) */ tag=sym->tag; } /* if */ if (sym->ident==iARRAY || sym->ident==iREFARRAY) { @@ -1470,7 +1476,7 @@ static int hier2(value *lval) int cmptag=subsym->x.tags.index; tokeninfo(&val,&idxname); if ((idxsym=findconst(idxname,&cmptag))==NULL) - error(80,idxname); /* unknown symbol, or non-constant */ + error_suggest(80,idxname,iCONSTEXPR); /* unknown symbol, or non-constant */ else if (cmptag>1) error(91,idxname); /* ambiguous constant */ } /* if */ @@ -1614,7 +1620,7 @@ static int hier1(value *lval1) if (sym==NULL && symtok!=tSYMBOL) { /* we do not have a valid symbol and we appear not to have read a valid * symbol name (so it is unlikely that we would have read a name of an - * undefined symbol) + * undefined symbol) */ error(29); /* expression error, assumed 0 */ lexpush(); /* analyse '(', '{' or '[' again later */ @@ -1631,7 +1637,7 @@ static int hier1(value *lval1) needtoken(close); return FALSE; } else if (sym->dim.array.level>0 && close!=']') { - error(51); /* invalid subscript, must use [ ] */ + error(51); /* invalid subscript, must use [ ] */ needtoken(close); return FALSE; } /* if */ @@ -1883,10 +1889,10 @@ static int primary(value *lval,int *symtok) * implemented, issue an error */ if ((sym->usage & uPROTOTYPED)==0) - return error(17,st); + return error_suggest(17,st,iVARIABLE); /* undefined symbol */ } else { if ((sym->usage & uDEFINE)==0) - error(17,st); + error_suggest(17,st,iVARIABLE); /* undefined symbol */ lval->sym=sym; lval->ident=sym->ident; lval->tag=sym->tag; @@ -1903,7 +1909,7 @@ static int primary(value *lval,int *symtok) strcpy(symbolname,st); if (!sc_allowproccall || isbinaryop(lexpeek())) { lexclr(FALSE); - return error(17,symbolname); /* undefined symbol */ + return error_suggest(17,st,iVARIABLE); /* undefined symbol */ } /* if */ /* an unknown symbol, but used in a way compatible with the "procedure * call" syntax. So assume that the symbol refers to a function. @@ -1985,13 +1991,24 @@ static void setdefarray(cell *string,cell size,cell array_sz,cell *dataaddr,int } /* if */ } -static int findnamedarg(arginfo *arg,char *name) +static int findnamedarg(const arginfo *arg,const char *name, char *closestarg) { int i; + int dist,closestdist=INT_MAX; - for (i=0; arg[i].ident!=0 && arg[i].ident!=iVARARGS; i++) + if (closestarg!=NULL) + *closestarg='\0'; + for (i=0; arg[i].ident!=0 && arg[i].ident!=iVARARGS; i++) { if (strcmp(arg[i].name,name)==0) return i; + if (closestarg!=NULL) { + dist=levenshtein_distance(arg[i].name,name); + if (dist=(1<' ' || v>=(1<<(sizeof(cell)*4)-1) && v<=~(1<<(sizeof(cell)*4)-1)) return FALSE; /* reconvert the value to a string (without signs or expressions) */ ptr=itoh(v); diff --git a/compiler/sci18n.c b/compiler/sci18n.c index f004d69..a53b45d 100644 --- a/compiler/sci18n.c +++ b/compiler/sci18n.c @@ -30,7 +30,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: sci18n.c 3612 2006-07-22 09:59:46Z thiadmer $ + * Version: $Id: sci18n.c 3845 2007-11-16 14:41:29Z thiadmer $ */ #include #include @@ -47,7 +47,7 @@ #define _MAX_PATH 250 #endif #if !defined DIRSEP_CHAR - #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ + #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ #define DIRSEP_CHAR '/' #elif defined macintosh #define DIRSEP_CHAR ':' diff --git a/compiler/scstate.c b/compiler/scstate.c index da6dd12..4773ada 100644 --- a/compiler/scstate.c +++ b/compiler/scstate.c @@ -43,7 +43,7 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * - * Version: $Id: scstate.c 3821 2007-10-15 16:54:20Z thiadmer $ + * Version: $Id: scstate.c 3848 2007-11-20 11:48:34Z thiadmer $ */ #include #include @@ -51,7 +51,7 @@ #include #include #include "sc.h" -#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ +#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ #include #endif @@ -70,16 +70,26 @@ typedef struct s_statepool { static statepool statepool_tab = { NULL, NULL, 0, 0, 0}; /* state combinations table */ -static constvalue *find_automaton(const char *name,int *last) +static constvalue *find_automaton(const char *name,int *last,char *closestmatch) { constvalue *ptr; + int dist,closestdist=INT_MAX; assert(last!=NULL); *last=0; + if (closestmatch!=NULL) + *closestmatch='\0'; ptr=sc_automaton_tab.next; while (ptr!=NULL) { if (strcmp(name,ptr->name)==0) return ptr; + if (closestmatch!=NULL) { + dist=levenshtein_distance(name,ptr->name); + if (distname); + closestdist=dist; + } /* if */ + } /* if */ if (ptr->index>*last) *last=ptr->index; ptr=ptr->next; @@ -93,7 +103,7 @@ SC_FUNC constvalue *automaton_add(const char *name) int last; assert(strlen(name)name)); - ptr=find_automaton(name,&last); + ptr=find_automaton(name,&last,NULL); if (ptr==NULL) { assert(last+1 <= SHRT_MAX); ptr=append_constval(&sc_automaton_tab,name,(cell)0,(short)(last+1)); @@ -101,10 +111,10 @@ SC_FUNC constvalue *automaton_add(const char *name) return ptr; } -SC_FUNC constvalue *automaton_find(const char *name) +SC_FUNC constvalue *automaton_find(const char *name,char *closestmatch) { - int last; - return find_automaton(name,&last); + int last; /* dummy, never used */ + return find_automaton(name,&last,closestmatch); } SC_FUNC constvalue *automaton_findid(int id) @@ -116,17 +126,27 @@ SC_FUNC constvalue *automaton_findid(int id) } -static constvalue *find_state(const char *name,int fsa,int *last) +static constvalue *find_state(const char *name,int fsa,int *last,char *closestmatch) { constvalue *ptr; + int dist,closestdist=INT_MAX; assert(last!=NULL); *last=0; + if (closestmatch!=NULL) + *closestmatch='\0'; ptr=sc_state_tab.next; while (ptr!=NULL) { if (ptr->index==fsa) { if (strcmp(name,ptr->name)==0) return ptr; + if (closestmatch!=NULL) { + dist=levenshtein_distance(name,ptr->name); + if (distname); + closestdist=dist; + } /* if */ + } /* if */ if ((int)ptr->value>*last) *last=(int)ptr->value; } /* if */ @@ -141,7 +161,7 @@ SC_FUNC constvalue *state_add(const char *name,int fsa) int last; assert(strlen(name)name)); - ptr=find_state(name,fsa,&last); + ptr=find_state(name,fsa,&last,NULL); if (ptr==NULL) { assert(fsa <= SHRT_MAX); ptr=append_constval(&sc_state_tab,name,(cell)(last+1),(short)fsa); @@ -149,10 +169,10 @@ SC_FUNC constvalue *state_add(const char *name,int fsa) return ptr; } -SC_FUNC constvalue *state_find(const char *name,int fsa_id) +SC_FUNC constvalue *state_find(const char *name,int fsa_id,char *closestmatch) { int last; /* dummy */ - return find_state(name,fsa_id,&last); + return find_state(name,fsa_id,&last,closestmatch); } SC_FUNC constvalue *state_findid(int id) diff --git a/include/AMXDLL.INC b/include/AMXDLL.INC index 2bca1ad..f19113f 100644 --- a/include/AMXDLL.INC +++ b/include/AMXDLL.INC @@ -1,13 +1,9 @@ /* An assortment of additional functions in the DLL version of the * Abstract Machine. * - * (c) Copyright 2000-2005, ITB CompuPhase + * (c) Copyright 2000-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _amxdll_included - #endinput -#endif -#define _amxdll_included enum { diff --git a/include/args.inc b/include/args.inc index 238d811..cf49aff 100644 --- a/include/args.inc +++ b/include/args.inc @@ -1,12 +1,8 @@ /* Script Arguments support functions * - * (c) Copyright 2005, ITB CompuPhase + * (c) Copyright 2005-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _args_included - #endinput -#endif -#define _args_included #pragma library Args native argcount(); diff --git a/include/bstring.inc b/include/bstring.inc index 60b9dc5..1e5fde7 100644 --- a/include/bstring.inc +++ b/include/bstring.inc @@ -1,12 +1,8 @@ -/* Wrapper for the "Better String library" by Paul Hsieh +/* Minimalistic wrapper for the "Better String library" by Paul Hsieh * - * (c) Copyright 2004-2005, ITB CompuPhase + * (c) Copyright 2004-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _bstring_included - #endinput -#endif -#define _bstring_included #pragma library BString /* native functions */ diff --git a/include/console.inc b/include/console.inc index 0d93630..f7f18a1 100644 --- a/include/console.inc +++ b/include/console.inc @@ -1,12 +1,8 @@ /* Console input/output functions * - * (c) Copyright 1998-2005, ITB CompuPhase + * (c) Copyright 1998-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _console_included - #endinput -#endif -#define _console_included #pragma library Console enum diff --git a/include/core.inc b/include/core.inc index bee14ed..0133435 100644 --- a/include/core.inc +++ b/include/core.inc @@ -1,12 +1,8 @@ /* Core functions * - * (c) Copyright 1998-2005, ITB CompuPhase + * (c) Copyright 1998-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _core_included - #endinput -#endif -#define _core_included #pragma library Core native heapspace(); diff --git a/include/datagram.inc b/include/datagram.inc index dfa3aa9..cf510c3 100644 --- a/include/datagram.inc +++ b/include/datagram.inc @@ -1,12 +1,8 @@ /* Datagram sending/receiving * - * (c) Copyright 2005, ITB CompuPhase + * (c) Copyright 2005-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _datagram_included - #endinput -#endif -#define _datagram_included #pragma library DGram native sendstring(const message[], const destination[]=""); diff --git a/include/file.inc b/include/file.inc index 0ee611a..13dae33 100644 --- a/include/file.inc +++ b/include/file.inc @@ -3,10 +3,6 @@ * (c) Copyright 2004-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _file_included - #endinput -#endif -#define _file_included #pragma library File enum filemode @@ -43,4 +39,4 @@ native fseek(File: handle, position = 0, seek_whence: whence = seek_start) native flength(File: handle); native fexist(const pattern[]); native bool: fmatch(name[], const pattern[], index = 0, size = sizeof name); -native bool: fstat(name[], &size = 0, ×tamp = 0); +native bool: fstat(name[], &size = 0, ×tamp = 0, &mode = 0, &inode = 0); diff --git a/include/fixed.inc b/include/fixed.inc index fd7d9e6..a4ef112 100644 --- a/include/fixed.inc +++ b/include/fixed.inc @@ -1,12 +1,8 @@ /* Fixed point arithmetic * - * (c) Copyright 1998-2005, ITB CompuPhase + * (c) Copyright 1998-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _Fixed_included - #endinput -#endif -#define _Fixed_included #pragma library Fixed enum fround_method { diff --git a/include/float.inc b/include/float.inc index cb0a5b5..bc27120 100644 --- a/include/float.inc +++ b/include/float.inc @@ -7,10 +7,6 @@ * * This file is provided as is (no warranties). */ -#if defined _Float_included - #endinput -#endif -#define _Float_included #pragma library Float /* Different methods of rounding */ diff --git a/include/process.inc b/include/process.inc index c421f6c..2898c9e 100644 --- a/include/process.inc +++ b/include/process.inc @@ -1,13 +1,9 @@ /* Process control and Foreign Function Interface (calling functions * in DLLs or shared libraries) * - * (c) Copyright 2006, ITB CompuPhase + * (c) Copyright 2006-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _process_included - #endinput -#endif -#define _process_included #pragma library Process native libcall(const libname[], const funcname[], const typestring[], ...); diff --git a/include/rational.inc b/include/rational.inc index 0b37d2d..57f293b 100644 --- a/include/rational.inc +++ b/include/rational.inc @@ -1,19 +1,15 @@ /* Rational number support * Loads either Float.inc or Fixed.inc, depending on the configuration * - * (c) Copyright 2004-2005, ITB CompuPhase + * (c) Copyright 2004-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _Rational_included - #endinput -#endif -#define _Rational_included /* first try to include floating point support */ #if !defined NOFLOAT #tryinclude #endif -#if defined _Float_included +#if defined _inc_float #define Rational: Float: #define rval(%1) strfloat(%1) #define rround(%1, %2) floatround(%1, %2) @@ -33,7 +29,7 @@ #if !defined NOFIXED #tryinclude #endif -#if defined _Fixed_included +#if defined _inc_fixed #define Rational: Fixed: #define rval(%1) strfixed(%1) #define rround(%1, %2) fround(%1, %2) diff --git a/include/string.inc b/include/string.inc index 6f69b3d..13d6f9e 100644 --- a/include/string.inc +++ b/include/string.inc @@ -3,10 +3,6 @@ * (c) Copyright 2005-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _string_included - #endinput -#endif -#define _string_included #pragma library String native strlen(const string[]); diff --git a/include/time.inc b/include/time.inc index fdd5a27..d923f85 100644 --- a/include/time.inc +++ b/include/time.inc @@ -3,10 +3,6 @@ * (c) Copyright 2001-2007, ITB CompuPhase * This file is provided as is (no warranties). */ -#if defined _time_included - #endinput -#endif -#define _time_included #pragma library Time native gettime(&hour=0, &minute=0, &second=0);