From afaa6474398d2ece1fddd205f856fb673553ab7a Mon Sep 17 00:00:00 2001 From: Sergei Marochkin Date: Wed, 24 Aug 2016 13:45:54 +0300 Subject: [PATCH 1/6] Fix for Linux compilation --- amx/amxargs.c | 1 + amx/amxfile.c | 33 +++++++++++++++++---------------- amx/amxprocess.c | 2 +- amx/amxtime.c | 2 ++ amx/fpattern.c | 2 +- amx/minIni.c | 1 + amx/pawndbg.c | 4 +++- compiler/sc1.c | 1 + 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/amx/amxargs.c b/amx/amxargs.c index fc25258..53f72e0 100644 --- a/amx/amxargs.c +++ b/amx/amxargs.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "osdefs.h" #if defined __WIN32__ || defined __MSDOS__ #include diff --git a/amx/amxfile.c b/amx/amxfile.c index 4c541cc..f23940a 100644 --- a/amx/amxfile.c +++ b/amx/amxfile.c @@ -50,6 +50,7 @@ #endif #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS || defined __APPLE__ #include + #include #else #include #endif @@ -90,7 +91,7 @@ #define _tgetenv getenv #define _tremove remove #define _trename rename - #if defined __APPLE__ + #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS || defined __APPLE__ #define _tmkdir mkdir #define _trmdir rmdir #define _tstat stat @@ -505,14 +506,14 @@ static cell AMX_NATIVE_CALL n_fopen(AMX *amx, const cell *params) if (f==NULL && altattrib!=NULL) f=_tfopen(fullname,altattrib); } /* if */ - return (cell)f; + return *(cell*)f; } /* fclose(File: handle) */ static cell AMX_NATIVE_CALL n_fclose(AMX *amx, const cell *params) { (void)amx; - return fclose((FILE*)params[1]) == 0; + return fclose((FILE*)¶ms[1]) == 0; } /* fwrite(File: handle, const string[]) */ @@ -533,11 +534,11 @@ static cell AMX_NATIVE_CALL n_fwrite(AMX *amx, const cell *params) /* the string is packed, write it as an ASCII/ANSI string */ if ((str=(char*)alloca(len + 1))!=NULL) { amx_GetString(str,cptr,0,len); - r=fputs(str,(FILE*)params[1]); + r=fputs(str,(FILE*)¶ms[1]); } /* if */ } else { /* the string is unpacked, write it as UTF-8 */ - r=fputs_cell((FILE*)params[1],cptr,1); + r=fputs_cell((FILE*)¶ms[1],cptr,1); } /* if */ return (cell)r; } @@ -565,12 +566,12 @@ static cell AMX_NATIVE_CALL n_fread(AMX *amx, const cell *params) if (params[4]) { /* store as packed string, read an ASCII/ANSI string */ - chars=fgets_char((FILE*)params[1],str,max); + chars=fgets_char((FILE*)¶ms[1],str,max); assert((int)chars #include +#elif defined __linux || defined __linux__ || defined __LINUX__ || defined __APPLE__ + #include #endif #define CELLMIN (-1 << (8*sizeof(cell) - 1)) diff --git a/amx/fpattern.c b/amx/fpattern.c index b88fed9..55c9bb8 100644 --- a/amx/fpattern.c +++ b/amx/fpattern.c @@ -99,7 +99,7 @@ #define hexdigit(c) ( ((c)>='0' && (c)<='9') ? (c) - '0' : 10 + \ ( ((c)>='a' && (c)<='f') ? (c) - 'a' : (c) - 'A' ) ) #if !defined tolower -# define tolower(c) ( (c)>='A' && (c)<='Z' ? (c) - 'A' + 'a' : (c) ) + #include #endif #define BITSET(set,idx) ( (set)[(idx)/8] |= (unsigned char)(1 << ((idx) & 7)) ) diff --git a/amx/minIni.c b/amx/minIni.c index a784dbf..d4bd621 100644 --- a/amx/minIni.c +++ b/amx/minIni.c @@ -79,6 +79,7 @@ #endif #endif #if !defined _totupper + #include #define _totupper toupper #endif diff --git a/amx/pawndbg.c b/amx/pawndbg.c index db626af..1422cd7 100644 --- a/amx/pawndbg.c +++ b/amx/pawndbg.c @@ -140,6 +140,8 @@ extern int chdir(const char *path); /* position of this function in header files #define amx_setattr(c,b,h) (_False) #define amx_termctl(c,v) (_False) #define amx_console(c,l,f) (void)(0) + int getnstr(char *str, int n); + int printw(const char *fmt, ...); #define STR_PROMPT "dbg> " #define CHR_HLINE '-' #define CHR_VLINE '|' @@ -851,7 +853,7 @@ static int send_rs232(const char *buffer, int len) FlushFileBuffers(hCom); #else size=write(fdCom,buffer,len); - fflush(fileno(fcCom)); + fflush((FILE*)(intptr_t)fileno((FILE*)&fdCom)); #endif assert((unsigned long)len==size); return size; diff --git a/compiler/sc1.c b/compiler/sc1.c index 6eaa858..1d8fd38 100644 --- a/compiler/sc1.c +++ b/compiler/sc1.c @@ -68,6 +68,7 @@ #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ #include #include /* from BinReloc, see www.autopackage.org */ + #include #endif #include "svnrev.h" From 66bf394a5d58542a9bbffff13a9b6205b19a43e7 Mon Sep 17 00:00:00 2001 From: Sergei Marochkin Date: Sat, 29 Oct 2016 14:08:48 +0300 Subject: [PATCH 2/6] Fix latest changes --- amx/pawndbg.c | 1 - compiler/sc1.c | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/amx/pawndbg.c b/amx/pawndbg.c index be812e1..71ce25e 100644 --- a/amx/pawndbg.c +++ b/amx/pawndbg.c @@ -140,7 +140,6 @@ extern int chdir(const char *path); /* position of this function in header files #define amx_setattr(c,b,h) (_False) #define amx_termctl(c,v) (_False) #define amx_console(c,l,f) (void)(0) - int getnstr(char *str, int n); int printw(const char *fmt, ...); #define STR_PROMPT "dbg> " #define CHR_HLINE '-' diff --git a/compiler/sc1.c b/compiler/sc1.c index 274759f..4396451 100644 --- a/compiler/sc1.c +++ b/compiler/sc1.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #if defined __WIN32__ || defined _WIN32 || defined __MSDOS__ #include #include + #include #endif #if defined __GNUC__ || defined __clang__ #include @@ -642,11 +642,13 @@ int pc_compile(int argc, char *argv[]) if (makestategraph) { /* run stategraph to create a dot file */ char dotname[_MAX_PATH]; - char pgmname[_MAX_PATH]; strcpy(dotname,reportname); set_extension(dotname,".dot",TRUE); - sprintf(pgmname,"%s%cstategraph.exe",sc_binpath,DIRSEP_CHAR); - spawnl(P_WAIT,pgmname,pgmname,reportname,dotname,NULL); + #if defined __WIN32__ || defined _WIN32 || defined __MSDOS__ + char pgmname[_MAX_PATH]; + sprintf(pgmname,"%s%cstategraph.exe",sc_binpath,DIRSEP_CHAR); + spawnl(P_WAIT,pgmname,pgmname,reportname,dotname,NULL); + #endif } } /* if */ if (pc_globaldoc!=NULL) { From 9256a14fa56d94c02362cb846a263ad72ea9cf89 Mon Sep 17 00:00:00 2001 From: Sergei Marochkin Date: Sat, 29 Oct 2016 14:12:29 +0300 Subject: [PATCH 3/6] Turn makestategraph only for Windows and DOS --- compiler/sc1.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/sc1.c b/compiler/sc1.c index 4396451..f273d84 100644 --- a/compiler/sc1.c +++ b/compiler/sc1.c @@ -639,17 +639,17 @@ int pc_compile(int argc, char *argv[]) make_report(&glbtab,frep,get_sourcefile(0),&makestategraph); fclose(frep); } /* if */ - if (makestategraph) { - /* run stategraph to create a dot file */ - char dotname[_MAX_PATH]; - strcpy(dotname,reportname); - set_extension(dotname,".dot",TRUE); - #if defined __WIN32__ || defined _WIN32 || defined __MSDOS__ + #if defined __WIN32__ || defined _WIN32 || defined __MSDOS__ + if (makestategraph) { + /* run stategraph to create a dot file */ + char dotname[_MAX_PATH]; char pgmname[_MAX_PATH]; + strcpy(dotname,reportname); + set_extension(dotname,".dot",TRUE); sprintf(pgmname,"%s%cstategraph.exe",sc_binpath,DIRSEP_CHAR); spawnl(P_WAIT,pgmname,pgmname,reportname,dotname,NULL); - #endif - } + } + #endif } /* if */ if (pc_globaldoc!=NULL) { free(pc_globaldoc); From bfd594e8e2bec5ab8c33f7716c8d56d3ac77b25b Mon Sep 17 00:00:00 2001 From: Sergei Marochkin Date: Sat, 29 Oct 2016 14:30:05 +0300 Subject: [PATCH 4/6] Sync with latest changes --- amx/amxargs.c | 1 - amx/amxfile.c | 1 - amx/amxtime.c | 2 -- amx/fpattern.c | 2 +- amx/minIni.c | 4 +++- amx/pawndbg.c | 1 - compiler/sc1.c | 1 - 7 files changed, 4 insertions(+), 8 deletions(-) diff --git a/amx/amxargs.c b/amx/amxargs.c index 039f403..b99913c 100644 --- a/amx/amxargs.c +++ b/amx/amxargs.c @@ -31,7 +31,6 @@ #include #include #include -#include #include "osdefs.h" #if defined __WIN32__ || defined __MSDOS__ #include diff --git a/amx/amxfile.c b/amx/amxfile.c index d4899f1..cf62d46 100644 --- a/amx/amxfile.c +++ b/amx/amxfile.c @@ -50,7 +50,6 @@ #endif #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined MACOS || defined __APPLE__ #include - #include #else #include #endif diff --git a/amx/amxtime.c b/amx/amxtime.c index 05f04fa..ce22383 100644 --- a/amx/amxtime.c +++ b/amx/amxtime.c @@ -22,8 +22,6 @@ #if defined __WIN32__ || defined _WIN32 || defined _Windows #include #include -#elif defined __linux || defined __linux__ || defined __LINUX__ || defined __APPLE__ - #include #endif #if defined __GNUC__ || defined __clang__ #include diff --git a/amx/fpattern.c b/amx/fpattern.c index 55c9bb8..b88fed9 100644 --- a/amx/fpattern.c +++ b/amx/fpattern.c @@ -99,7 +99,7 @@ #define hexdigit(c) ( ((c)>='0' && (c)<='9') ? (c) - '0' : 10 + \ ( ((c)>='a' && (c)<='f') ? (c) - 'a' : (c) - 'A' ) ) #if !defined tolower - #include +# define tolower(c) ( (c)>='A' && (c)<='Z' ? (c) - 'A' + 'a' : (c) ) #endif #define BITSET(set,idx) ( (set)[(idx)/8] |= (unsigned char)(1 << ((idx) & 7)) ) diff --git a/amx/minIni.c b/amx/minIni.c index d4bd621..f5ca04d 100644 --- a/amx/minIni.c +++ b/amx/minIni.c @@ -79,9 +79,11 @@ #endif #endif #if !defined _totupper - #include #define _totupper toupper #endif +#if !defined toupper + #define toupper(c) ( (c)>='A' && (c)<='Z' ? (c) + 'A' - 'a' : (c) ) +#endif #if !defined INI_LINETERM #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ diff --git a/amx/pawndbg.c b/amx/pawndbg.c index 71ce25e..c73ece7 100644 --- a/amx/pawndbg.c +++ b/amx/pawndbg.c @@ -140,7 +140,6 @@ extern int chdir(const char *path); /* position of this function in header files #define amx_setattr(c,b,h) (_False) #define amx_termctl(c,v) (_False) #define amx_console(c,l,f) (void)(0) - int printw(const char *fmt, ...); #define STR_PROMPT "dbg> " #define CHR_HLINE '-' #define CHR_VLINE '|' diff --git a/compiler/sc1.c b/compiler/sc1.c index f273d84..ed6033a 100644 --- a/compiler/sc1.c +++ b/compiler/sc1.c @@ -72,7 +72,6 @@ #if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ #include #include /* from BinReloc, see www.autopackage.org */ - #include #endif #include "svnrev.h" From a417412e68a3594eb51438c0a41c57a94bd5cdcc Mon Sep 17 00:00:00 2001 From: Sergei Marochkin Date: Sun, 30 Oct 2016 19:50:12 +0300 Subject: [PATCH 5/6] Removed previous changes, add diagnostic ignored rules --- amx/amx.h | 9 ++++++--- amx/amxfile.c | 30 +++++++++++++++--------------- amx/amxprocess.c | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/amx/amx.h b/amx/amx.h index bb8621e..631ca62 100644 --- a/amx/amx.h +++ b/amx/amx.h @@ -219,10 +219,13 @@ typedef int (AMXAPI *AMX_IDLE)(struct tagAMX *amx, int AMXAPI Exec(struct tagAMX #pragma warning(disable:4103) /* disable warning message 4103 that complains about pragma pack in a header file */ #pragma warning(disable:4127) /* "conditional expression is constant" (needed for static_assert) */ #pragma warning(disable:4996) /* POSIX name is deprecated */ -#elif defined __GNUC__ #elif defined __clang__ - #pragma GCC diagnostic ignored "-Wlogical-op-parentheses" - #pragma GCC diagnostic ignored "-Wbitwise-op-parentheses" + #pragma clang diagnostic ignored "-Wlogical-op-parentheses" + #pragma clang diagnostic ignored "-Wbitwise-op-parentheses" + #pragma clang diagnostic ignored "-Wint-to-pointer-cast" +#elif defined __GNUC__ + #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" + #pragma GCC diagnostic ignored "-Wpointer-to-int-cast" #endif /* Some compilers do not support the #pragma align, which should be fine. Some diff --git a/amx/amxfile.c b/amx/amxfile.c index cf62d46..52071de 100644 --- a/amx/amxfile.c +++ b/amx/amxfile.c @@ -508,14 +508,14 @@ static cell AMX_NATIVE_CALL n_fopen(AMX *amx, const cell *params) if (f==NULL && altattrib!=NULL) f=_tfopen(fullname,altattrib); } /* if */ - return *(cell*)f; + return (cell)f; } /* fclose(File: handle) */ static cell AMX_NATIVE_CALL n_fclose(AMX *amx, const cell *params) { (void)amx; - return fclose((FILE*)¶ms[1]) == 0; + return fclose((FILE*)params[1]) == 0; } /* fwrite(File: handle, const string[]) */ @@ -536,11 +536,11 @@ static cell AMX_NATIVE_CALL n_fwrite(AMX *amx, const cell *params) /* the string is packed, write it as an ASCII/ANSI string */ if ((str=(char*)alloca(len + 1))!=NULL) { amx_GetString(str,cptr,0,len); - r=fputs(str,(FILE*)¶ms[1]); + r=fputs(str,(FILE*)params[1]); } /* if */ } else { /* the string is unpacked, write it as UTF-8 */ - r=fputs_cell((FILE*)¶ms[1],cptr,1); + r=fputs_cell((FILE*)params[1],cptr,1); } /* if */ return (cell)r; } @@ -568,12 +568,12 @@ static cell AMX_NATIVE_CALL n_fread(AMX *amx, const cell *params) if (params[4]) { /* store as packed string, read an ASCII/ANSI string */ - chars=fgets_char((FILE*)¶ms[1],str,max); + chars=fgets_char((FILE*)params[1],str,max); assert((int)chars Date: Sun, 30 Oct 2016 19:51:52 +0300 Subject: [PATCH 6/6] Remove last comma from AMX_ERR_* enumeration --- amx/amx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amx/amx.h b/amx/amx.h index 631ca62..63f6a17 100644 --- a/amx/amx.h +++ b/amx/amx.h @@ -383,7 +383,7 @@ enum { AMX_ERR_PARAMS, /* parameter error */ AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */ AMX_ERR_GENERAL, /* general error (unknown or unspecific error) */ - AMX_ERR_OVERLAY, /* overlays are unsupported (JIT) or uninitialized */ + AMX_ERR_OVERLAY /* overlays are unsupported (JIT) or uninitialized */ }; #define AMX_FLAG_OVERLAY 0x01 /* all function calls use overlays */