From 53c0a2d01d8dc5520134b4be4ecf94e39fb602aa Mon Sep 17 00:00:00 2001 From: doursse Date: Fri, 21 Mar 2008 17:18:25 +0000 Subject: [PATCH] * add evil support and remove evil windows code * correctly handle alloca include * remove trailing spaces SVN revision: 34072 --- legacy/embryo/configure.in | 9 ++- legacy/embryo/src/bin/Makefile.am | 5 +- legacy/embryo/src/bin/embryo_cc_prefix.c | 84 ++---------------------- legacy/embryo/src/bin/embryo_cc_sc1.c | 76 ++++++++------------- legacy/embryo/src/lib/Embryo.h | 29 ++++---- legacy/embryo/src/lib/embryo_private.h | 23 ++++++- 6 files changed, 79 insertions(+), 147 deletions(-) diff --git a/legacy/embryo/configure.in b/legacy/embryo/configure.in index 019afc1ae3..d62ad1cbb8 100644 --- a/legacy/embryo/configure.in +++ b/legacy/embryo/configure.in @@ -35,11 +35,14 @@ AC_CHECK_FUNCS(gettimeofday) create_shared_lib="" case "$host_os" in - mingw|mingw32) - create_shared_lib="-no-undefined " + mingw|mingw32*|cegcc) + PKG_CHECK_MODULES([EVIL], evil) + AC_DEFINE(HAVE_EVIL, 1, [Set to 1 if evil package is installed]) + dnl needed for correct definition of EAPI + AC_DEFINE(EFL_EMBRYO_BUILD, 1, [Define to mention that embryo is built]) + create_shared_lib="-no-undefined" ;; esac - AC_SUBST(create_shared_lib) AC_CHECK_HEADERS(fnmatch.h,, AC_MSG_ERROR([Cannot find fnmatch.h. Make sure your CFLAGS environment variable contains include lines for the location of this file])) diff --git a/legacy/embryo/src/bin/Makefile.am b/legacy/embryo/src/bin/Makefile.am index e2adb4a683..38fa3d6731 100644 --- a/legacy/embryo/src/bin/Makefile.am +++ b/legacy/embryo/src/bin/Makefile.am @@ -8,7 +8,8 @@ AM_CPPFLAGS = \ -I$(top_builddir) \ -DPACKAGE_BIN_DIR=\"$(bindir)\" \ -DPACKAGE_LIB_DIR=\"$(libdir)\" \ --DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" +-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ +@EVIL_CFLAGS@ bin_PROGRAMS = embryo_cc @@ -29,7 +30,7 @@ embryo_cc_scvars.c \ embryo_cc_prefix.c \ embryo_cc_prefix.h -embryo_cc_LDADD = -lm +embryo_cc_LDADD = @EVIL_LIBS@ -lm embryo_cc_DEPENDENCIES = EXTRA_DIST = \ diff --git a/legacy/embryo/src/bin/embryo_cc_prefix.c b/legacy/embryo/src/bin/embryo_cc_prefix.c index ae2f3b9cd3..dbd46574c8 100644 --- a/legacy/embryo/src/bin/embryo_cc_prefix.c +++ b/legacy/embryo/src/bin/embryo_cc_prefix.c @@ -17,93 +17,17 @@ #include #include #include -#ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# include -# undef WIN32_LEAN_AND_MEAN -# include -# include -# include +#include /* dlopen,dlclose,etc */ +#ifdef HAVE_EVIL +# include /* for realpath */ #else -# include /* dlopen,dlclose,etc */ # include # include # include -#endif /* _WIN32 */ +#endif /* HAVE_E_WIN32 */ #include "embryo_cc_prefix.h" -/* FIXME: that hack is a temporary one. That code will be in MinGW soon */ -#ifdef _WIN32 - -#define RTLD_LAZY 1 /* lazy function call binding */ -#define RTLD_NOW 2 /* immediate function call binding */ -#define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible - to other dlopen'ed objs */ - -static char *dlerr_ptr; -static char dlerr_data[80]; - -void *dlopen (const char *file, int mode) -{ - HMODULE hmodule; - - hmodule = LoadLibrary(file); - if (hmodule == NULL) { - int error; - - error = GetLastError(); - sprintf(dlerr_data, "LoadLibraryEx returned %d.", error); - dlerr_ptr = dlerr_data; - } - return hmodule; -} - -int dlclose (void *handle) -{ - if (FreeLibrary(handle)) { - return 0; - } - else { - int error; - - error = GetLastError(); - sprintf(dlerr_data, "FreeLibrary returned %d.", error); - dlerr_ptr = dlerr_data; - return -1; - } -} - -void *dlsym (void *handle, const char *name) -{ - FARPROC fp; - - fp = GetProcAddress(handle, name); - if (fp == NULL) { - int error; - - error = GetLastError(); - sprintf(dlerr_data, "GetProcAddress returned %d.", error); - dlerr_ptr = dlerr_data; - } - return fp; -} - -char *dlerror (void) -{ - if (dlerr_ptr != NULL) { - dlerr_ptr = NULL; - return dlerr_data; - } - else { - return NULL; - } -} - -#define realpath(file_name, resolved_name) _fullpath((resolved_name), (file_name), PATH_MAX) - -#endif /* _WIN32 */ - /* local subsystem functions */ static int _e_prefix_share_hunt(void); static int _e_prefix_fallbacks(void); diff --git a/legacy/embryo/src/bin/embryo_cc_sc1.c b/legacy/embryo/src/bin/embryo_cc_sc1.c index 0e3949257b..e704f8c21f 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc1.c +++ b/legacy/embryo/src/bin/embryo_cc_sc1.c @@ -20,7 +20,7 @@ * 2. Altered source versions must be plainly marked as such, and * must not be misrepresented as being the original software. * 3. This notice may not be removed or altered from any source - * distribution. + * distribution. * Version: $Id$ */ @@ -36,12 +36,9 @@ #include #include #include -#ifdef _WIN32 -# include -# include -# include -# include -#endif /* _WIN32 */ +#ifdef HAVE_EVIL +# include +#endif /* HAVE_EVIL */ #include "embryo_cc_osdefs.h" #include "embryo_cc_sc.h" @@ -143,7 +140,7 @@ main(int argc, char *argv[], char *env[]) snprintf(argv0, _MAX_PATH, "%s/%s", pwd, argv[0]); } /* if */ argv[0] = argv0; /* set location to new first parameter */ - + e_prefix_determine(argv0); return sc_compile(argc, argv); @@ -318,30 +315,15 @@ sc_compile(int argc, char *argv[]) /* open the output file */ -#ifndef _WIN32 +#ifndef HAVE_EVIL tmpdir = getenv("TMPDIR"); if (!tmpdir) tmpdir = "/tmp"; +#else + tmpdir = evil_tmpdir_get(); +#endif /* ! HAVE_EVIL */ snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir); fd_out = mkstemp(outfname); -#else - tmpdir = getenv("TMP"); - if (!tmpdir) tmpdir = getenv("TEMP"); - if (!tmpdir) tmpdir = getenv("USERPROFILE"); - if (!tmpdir) tmpdir = getenv("WINDIR"); - if (!tmpdir) error(101, "embryo_cc.asm-tmp-XXXXXX (unable to get a valid temp path)"); - - snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir); -# ifdef __MINGW32__ - if (!mktemp(outfname)) - error(101, outfname); - fd_out = _sopen(outfname, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE); -# else - if (_mktemp_s(outfname, _MAX_PATH)) - error(101, outfname); - _sopen_s(&fd_out, outfname, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE); -# endif /* __MINGW32__ */ -#endif /* _WIN32 */ if (fd_out < 0) error(101, outfname); @@ -706,10 +688,10 @@ setconfig(char *root) if ((ptr = strrchr(path, DIRSEP_CHAR)) != NULL || (ptr = strchr(path, ':')) != NULL) { - /* If there was no terminating "\" or ":", + /* If there was no terminating "\" or ":", * the filename probably does not * contain the path; so we just don't add it - * to the list in that case + * to the list in that case */ *(ptr + 1) = '\0'; if (strlen(path) < (sizeof(path) - 1 - 7)) @@ -2139,7 +2121,7 @@ funcstub(int native) /* "declargs()" found the ")" */ if (!operatoradjust(opertok, sym, symbolname, tag)) sym->usage &= ~uDEFINE; - /* for a native operator, also need to specify an "exported" + /* for a native operator, also need to specify an "exported" * function name; for a native function, this is optional */ if (native) @@ -2406,7 +2388,7 @@ argcompare(arginfo * a1, arginfo * a2) result = a1->numdim == a2->numdim; for (level = 0; result && level < a1->numdim; level++) result = a1->dim[level] == a2->dim[level]; - /* ??? should also check contents of the default array + /* ??? should also check contents of the default array * (these troubles go away in a 2-pass compiler that forbids * double declarations, but Small currently does not forbid them) */ @@ -2433,8 +2415,8 @@ argcompare(arginfo * a1, arginfo * a2) /* declargs() * - * This routine adds an entry in the local symbol table for each - * argument found in the argument list. + * This routine adds an entry in the local symbol table for each + * argument found in the argument list. * It returns the number of arguments. */ static int @@ -2537,7 +2519,7 @@ declargs(symbol * sym) if (sym->dim.arglist == 0) error(103); /* insufficient memory */ sym->dim.arglist[argcnt] = arg; - sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list + sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list * terminated */ } else @@ -2573,7 +2555,7 @@ declargs(symbol * sym) (argcnt + 2) * sizeof(arginfo)); if (sym->dim.arglist == 0) error(103); /* insufficient memory */ - sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list + sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list * terminated */ sym->dim.arglist[argcnt].ident = iVARARGS; sym->dim.arglist[argcnt].hasdefault = FALSE; @@ -2614,7 +2596,7 @@ declargs(symbol * sym) int altidx; /* Find the argument with the name mentioned after the "sizeof". - * Note that we cannot use findloc here because we need the + * Note that we cannot use findloc here because we need the * arginfo struct, not the symbol. */ ptr = arglist[idx].defvalue.size.symname; @@ -2704,7 +2686,7 @@ doarg(char *name, int ident, int offset, int tags[], int numtags, lexpush(); /* initials() needs the "=" token again */ assert(numtags > 0); /* for the moment, when a default value is given for the array, - * all dimension sizes, except the last, must be non-zero + * all dimension sizes, except the last, must be non-zero * (function initials() requires to know the major dimensions) */ for (level = 0; level < arg->numdim - 1; level++) @@ -2813,7 +2795,7 @@ doarg(char *name, int ident, int offset, int tags[], int numtags, if (ident == iREFERENCE) argsym->usage |= uREAD; /* because references are passed back */ if (fpublic) - argsym->usage |= uREAD; /* arguments of public functions + argsym->usage |= uREAD; /* arguments of public functions * are always "used" */ if (fconst) argsym->usage |= uCONST; @@ -3182,8 +3164,8 @@ add_constant(char *name, cell val, int vclass, int tag) /* statement - The Statement Parser * - * This routine is called whenever the parser needs to know what - * statement it encounters (i.e. whenever program syntax requires a + * This routine is called whenever the parser needs to know what + * statement it encounters (i.e. whenever program syntax requires a * statement). */ static void @@ -3206,11 +3188,11 @@ statement(int *lastindent, int allow_decl) /* lex() has set stmtindent */ if (lastindent != NULL && tok != tLABEL) { -#if 0 +#if 0 if (*lastindent >= 0 && *lastindent != stmtindent && !indent_nowarn && sc_tabsize > 0) error(217); /* loose indentation */ -#endif +#endif *lastindent = stmtindent; indent_nowarn = TRUE; /* if warning was blocked, re-enable it */ } /* if */ @@ -3534,10 +3516,10 @@ doif(void) { /* to avoid the "dangling else" error, we want a warning if the "else" * has a lower indent than the matching "if" */ -#if 0 +#if 0 if (stmtindent < ifindent && sc_tabsize > 0) error(217); /* loose indentation */ -#endif +#endif flab2 = getlabel(); if ((lastst != tRETURN) && (lastst != tGOTO)) jumplabel(flab2); @@ -3632,7 +3614,7 @@ dofor(void) setlabel(wq[wqLOOP]); /* "continue" goes to this label: expr3 */ setline(fline, fcurrent); /* Expressions 2 and 3 are reversed in the generated code: - * expression 3 precedes expression 2. + * expression 3 precedes expression 2. * When parsing, the code is buffered and marks for * the start of each expression are insterted in the buffer. */ @@ -3646,7 +3628,7 @@ dofor(void) setlabel(skiplab); /*jump to this point after 1st expression */ if (matchtoken(';') == 0) { - test(wq[wqEXIT], FALSE, FALSE); /* expression 2 + test(wq[wqEXIT], FALSE, FALSE); /* expression 2 *(jump to wq[wqEXIT] if false) */ needtoken(';'); } /* if */ @@ -3753,7 +3735,7 @@ doswitch(void) /* nothing */ ; if (cse != NULL && cse->value == val) error(40, val); /* duplicate "case" label */ - /* Since the label is stored as a string in the + /* Since the label is stored as a string in the * "constvalue", the size of an identifier must * be at least 8, as there are 8 * hexadecimal digits in a 32-bit number. diff --git a/legacy/embryo/src/lib/Embryo.h b/legacy/embryo/src/lib/Embryo.h index e187516e08..50ab73149e 100644 --- a/legacy/embryo/src/lib/Embryo.h +++ b/legacy/embryo/src/lib/Embryo.h @@ -2,14 +2,19 @@ #define _EMBRYO_H #ifdef EAPI -#undef EAPI +# undef EAPI #endif -#ifdef _MSC_VER -# ifdef BUILDING_DLL -# define EAPI __declspec(dllexport) + +#ifdef _WIN32 +# ifdef EFL_EMBRYO_BUILD +# ifdef DLL_EXPORT +# define EAPI __declspec(dllexport) +# else +# define EAPI +# endif /* ! DLL_EXPORT */ # else # define EAPI __declspec(dllimport) -# endif +# endif /* ! EFL_EMBRYO_BUILD */ #else # ifdef __GNUC__ # if __GNUC__ >= 4 @@ -20,7 +25,7 @@ # else # define EAPI # endif -#endif +#endif /* ! _WIN32 */ #ifdef __cplusplus extern "C" { @@ -43,7 +48,7 @@ extern "C" { EMBRYO_ERROR_NATIVE, /** Native function failed */ EMBRYO_ERROR_DIVIDE, /** Divide by zero */ EMBRYO_ERROR_SLEEP, /** Go into sleepmode - code can be restarted */ - + EMBRYO_ERROR_MEMORY = 16, /** Out of memory */ EMBRYO_ERROR_FORMAT, /** Invalid file format */ EMBRYO_ERROR_VERSION, /** File is for a newer version of the Embryo_Program */ @@ -62,7 +67,7 @@ extern "C" { #define EMBRYO_FUNCTION_MAIN -1 /* Start at program entry point */ #define EMBRYO_FUNCTION_CONT -2 /* Continue from last address */ /** An invalid cell reference */ -#define EMBRYO_CELL_NONE 0x7fffffff +#define EMBRYO_CELL_NONE 0x7fffffff /* program run return values */ #define EMBRYO_PROGRAM_OK 1 #define EMBRYO_PROGRAM_SLEEP 2 @@ -85,10 +90,10 @@ extern "C" { #define EMBRYO_FLOAT_TO_CELL(f) ((Embryo_Float_Cell) f).c /** Embryo_Cell to float */ #define EMBRYO_CELL_TO_FLOAT(c) ((Embryo_Float_Cell) c).f - + EAPI int embryo_init(void); EAPI int embryo_shutdown(void); - + EAPI Embryo_Program *embryo_program_new(void *data, int size); EAPI Embryo_Program *embryo_program_const_new(void *data, int size); EAPI Embryo_Program *embryo_program_load(char *file); @@ -122,9 +127,9 @@ extern "C" { EAPI int embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell); EAPI int embryo_parameter_string_push(Embryo_Program *ep, const char *str); EAPI int embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num); - + #ifdef __cplusplus -} +} #endif #endif diff --git a/legacy/embryo/src/lib/embryo_private.h b/legacy/embryo/src/lib/embryo_private.h index 157497670c..cc5a4f24b1 100644 --- a/legacy/embryo/src/lib/embryo_private.h +++ b/legacy/embryo/src/lib/embryo_private.h @@ -8,12 +8,29 @@ #include #include #include -#if HAVE_ALLOCA_H -#include + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_ALLOCA_H +# include +#elif defined __GNUC__ +# define alloca __builtin_alloca +#elif defined _AIX +# define alloca __alloca +#elif defined _MSC_VER +# include +# define alloca _alloca +#else +# include +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); #endif #include "Embryo.h" -#include "config.h" #ifdef __GNUC__ # if __GNUC__ >= 4