From 95885e4dec3524bac55a311a6226ca7609f8641b Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Mon, 9 Jan 2017 14:52:15 +0000 Subject: [PATCH] fixed some wrong code --- moo/lib/Makefile.am | 2 +- moo/lib/Makefile.in | 20 +++++++++---------- moo/lib/err.c | 15 +++++++++++++- moo/lib/exec.c | 17 ++++++++++------ moo/lib/main.c | 26 ++++++++++++------------ moo/lib/moo-cmn.h | 4 ++-- moo/lib/moo-utl.h | 12 +++--------- moo/mod/console.c | 48 +++++++++++++++++++++++++++++++++------------ moo/mod/stdio.c | 4 ++++ 9 files changed, 94 insertions(+), 54 deletions(-) diff --git a/moo/lib/Makefile.am b/moo/lib/Makefile.am index e95df6b..3ae3c90 100644 --- a/moo/lib/Makefile.am +++ b/moo/lib/Makefile.am @@ -47,10 +47,10 @@ libmoo_la_SOURCES = \ logfmt.c \ gc.c \ heap.c \ + moo.c \ obj.c \ proc.c \ rbt.c \ - moo.c \ sym.c \ utf8.c \ utl.c diff --git a/moo/lib/Makefile.in b/moo/lib/Makefile.in index b633007..6298421 100644 --- a/moo/lib/Makefile.in +++ b/moo/lib/Makefile.in @@ -139,8 +139,8 @@ libmoo_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) am_libmoo_la_OBJECTS = libmoo_la-bigint.lo libmoo_la-comp.lo \ libmoo_la-debug.lo libmoo_la-decode.lo libmoo_la-dic.lo \ libmoo_la-err.lo libmoo_la-exec.lo libmoo_la-logfmt.lo \ - libmoo_la-gc.lo libmoo_la-heap.lo libmoo_la-obj.lo \ - libmoo_la-proc.lo libmoo_la-rbt.lo libmoo_la-moo.lo \ + libmoo_la-gc.lo libmoo_la-heap.lo libmoo_la-moo.lo \ + libmoo_la-obj.lo libmoo_la-proc.lo libmoo_la-rbt.lo \ libmoo_la-sym.lo libmoo_la-utf8.lo libmoo_la-utl.lo libmoo_la_OBJECTS = $(am_libmoo_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) @@ -416,10 +416,10 @@ libmoo_la_SOURCES = \ logfmt.c \ gc.c \ heap.c \ + moo.c \ obj.c \ proc.c \ rbt.c \ - moo.c \ sym.c \ utf8.c \ utl.c @@ -692,6 +692,13 @@ libmoo_la-heap.lo: heap.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-heap.lo `test -f 'heap.c' || echo '$(srcdir)/'`heap.c +libmoo_la-moo.lo: moo.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-moo.lo -MD -MP -MF $(DEPDIR)/libmoo_la-moo.Tpo -c -o libmoo_la-moo.lo `test -f 'moo.c' || echo '$(srcdir)/'`moo.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-moo.Tpo $(DEPDIR)/libmoo_la-moo.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='moo.c' object='libmoo_la-moo.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-moo.lo `test -f 'moo.c' || echo '$(srcdir)/'`moo.c + libmoo_la-obj.lo: obj.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-obj.lo -MD -MP -MF $(DEPDIR)/libmoo_la-obj.Tpo -c -o libmoo_la-obj.lo `test -f 'obj.c' || echo '$(srcdir)/'`obj.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-obj.Tpo $(DEPDIR)/libmoo_la-obj.Plo @@ -713,13 +720,6 @@ libmoo_la-rbt.lo: rbt.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-rbt.lo `test -f 'rbt.c' || echo '$(srcdir)/'`rbt.c -libmoo_la-moo.lo: moo.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-moo.lo -MD -MP -MF $(DEPDIR)/libmoo_la-moo.Tpo -c -o libmoo_la-moo.lo `test -f 'moo.c' || echo '$(srcdir)/'`moo.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-moo.Tpo $(DEPDIR)/libmoo_la-moo.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='moo.c' object='libmoo_la-moo.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-moo.lo `test -f 'moo.c' || echo '$(srcdir)/'`moo.c - libmoo_la-sym.lo: sym.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-sym.lo -MD -MP -MF $(DEPDIR)/libmoo_la-sym.Tpo -c -o libmoo_la-sym.lo `test -f 'sym.c' || echo '$(srcdir)/'`sym.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-sym.Tpo $(DEPDIR)/libmoo_la-sym.Plo diff --git a/moo/lib/err.c b/moo/lib/err.c index 2e908a3..0356437 100644 --- a/moo/lib/err.c +++ b/moo/lib/err.c @@ -166,7 +166,12 @@ const moo_ooch_t* moo_synerrnumtoerrstr (moo_synerrnum_t errnum) # include #elif defined(__DOS__) # include -# include +# if defined(_INTELC32_) +# define DOS_EXIT 0x4C +# else +# include +# endif +# include #elif defined(vms) || defined(__vms) # define __NEW_STARLET 1 # include /* (SYS$...) */ @@ -194,9 +199,17 @@ moo_errnum_t moo_syserrtoerrnum (int e) case EPERM: return MOO_EPERM; case ENOTDIR: return MOO_ENOTDIR; case ENOENT: return MOO_ENOENT; + #if defined(EEXIST) case EEXIST: return MOO_EEXIST; + #endif + #if defined(EINTR) case EINTR: return MOO_EINTR; + #endif + + #if defined(EPIPE) case EPIPE: return MOO_EPIPE; + #endif + #if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN != EWOULDBLOCK) case EAGAIN: case EWOULDBLOCK: return MOO_EAGAIN; diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 31807ec..b165937 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -35,7 +35,7 @@ # define INCL_DOSERRORS # include # include -#elif defined(__MSDOS__) +#elif defined(__DOS__) # include #elif defined(macintosh) # include @@ -122,7 +122,12 @@ # define LOG_INST_3(moo,fmt,a1,a2,a3) #endif -#define __PRIMITIVE_NAME__ (&__FUNCTION__[4]) +#if defined(__DOS__) && defined(_INTELC32_) + /* the old intel c code builder doesn't support __FUNCTION__ */ +# define __PRIMITIVE_NAME__ "<>" +#else +# define __PRIMITIVE_NAME__ (&__FUNCTION__[4]) +#endif /* ------------------------------------------------------------------------- */ static MOO_INLINE void vm_gettime (moo_t* moo, moo_ntime_t* now) @@ -140,7 +145,7 @@ static MOO_INLINE void vm_gettime (moo_t* moo, moo_ntime_t* now) /* it must return NO_ERROR */ MOO_INITNTIME (now, MOO_MSEC_TO_SEC(out), MOO_MSEC_TO_NSEC(out)); -#elif defined(__MSDOS__) && defined(_INTELC32_) +#elif defined(__DOS__) && defined(_INTELC32_) clock_t c; /* TODO: handle overflow?? */ @@ -213,7 +218,7 @@ static MOO_INLINE void vm_sleep (moo_t* moo, const moo_ntime_t* dur) /* TODO: ... */ -#elif defined(__MSDOS__) && defined(_INTELC32_) +#elif defined(__DOS__) && defined(_INTELC32_) clock_t c; @@ -1763,8 +1768,8 @@ static moo_pfrc_t pf_exceptionize_error (moo_t* moo, moo_ooi_t nargs) return MOO_PF_FAILURE; } -// TODO: ....... -// MOO_OBJ_SET_FLAGS_EXTRA (rcv, xxx); +/* TODO: ....... + MOO_OBJ_SET_FLAGS_EXTRA (rcv, xxx); */ MOO_STACK_SETRETTORCV (moo, nargs); return MOO_PF_SUCCESS; } diff --git a/moo/lib/main.c b/moo/lib/main.c index faa71cf..f975948 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -45,8 +45,9 @@ # define INCL_DOSPROCESS # define INCL_DOSERRORS # include -#elif defined(__MSDOS__) +#elif defined(__DOS__) # include +# include #elif defined(macintosh) # include #else @@ -69,9 +70,9 @@ # if defined(_WIN32) # define MOO_DEFAULT_MODPREFIX "moo-" # elif defined(__OS2__) -# define MOO_DEFAULT_MODPREFIX "st-" -# elif defined(__MSDOS__) -# define MOO_DEFAULT_MODPREFIX "st-" +# define MOO_DEFAULT_MODPREFIX "moo" +# elif defined(__DOS__) +# define MOO_DEFAULT_MODPREFIX "moo" # else # define MOO_DEFAULT_MODPREFIX "libmoo-" # endif @@ -82,7 +83,7 @@ # define MOO_DEFAULT_MODPOSTFIX "" # elif defined(__OS2__) # define MOO_DEFAULT_MODPOSTFIX "" -# elif defined(__MSDOS__) +# elif defined(__DOS__) # define MOO_DEFAULT_MODPOSTFIX "" # else # define MOO_DEFAULT_MODPOSTFIX "" @@ -172,7 +173,7 @@ static MOO_INLINE moo_ooi_t open_input (moo_t* moo, moo_ioarg_t* arg) /* TODO: make bcs relative to the includer */ -#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) +#if defined(__DOS__) || defined(_WIN32) || defined(__OS2__) fp = fopen (bcs, "rb"); #else fp = fopen (bcs, "r"); @@ -181,7 +182,7 @@ static MOO_INLINE moo_ooi_t open_input (moo_t* moo, moo_ioarg_t* arg) else { /* main stream */ -#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) +#if defined(__DOS__) || defined(_WIN32) || defined(__OS2__) fp = fopen (xtn->source_path, "rb"); #else fp = fopen (xtn->source_path, "r"); @@ -341,7 +342,7 @@ static void dl_close (moo_t* moo, void* handle) FreeLibrary ((HMODULE)handle); #elif defined(__OS2__) DosFreeModule ((HMODULE)handle); -#elif defined(__MSDOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE) +#elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE) FreeModule (handle); #else /* nothing to do */ @@ -438,13 +439,14 @@ static void log_write (moo_t* moo, moo_oow_t mask, const moo_ooch_t* msg, moo_oo struct tm tm, *tmp; time_t now; + if (mask & MOO_LOG_GC) return; /* don't show gc logs */ /* TODO: beautify the log message. * do classification based on mask. */ now = time(NULL); -#if defined(__MSDOS__) +#if defined(__DOS__) tmp = localtime (&now); #else tmp = localtime_r (&now, &tm); @@ -502,7 +504,7 @@ static moo_t* g_moo = MOO_NULL; /* ========================================================================= */ -#if defined(__MSDOS__) && defined(_INTELC32_) +#if defined(__DOS__) && defined(_INTELC32_) static void (*prev_timer_intr_handler) (void); #pragma interrupt(timer_intr_handler) @@ -543,7 +545,7 @@ static void arrange_process_switching (int sig) static void setup_tick (void) { -#if defined(__MSDOS__) && defined(_INTELC32_) +#if defined(__DOS__) && defined(_INTELC32_) prev_timer_intr_handler = _dos_getvect (0x1C); _dos_setvect (0x1C, timer_intr_handler); @@ -579,7 +581,7 @@ static void setup_tick (void) static void cancel_tick (void) { -#if defined(__MSDOS__) && defined(_INTELC32_) +#if defined(__DOS__) && defined(_INTELC32_) _dos_setvect (0x1C, prev_timer_intr_handler); diff --git a/moo/lib/moo-cmn.h b/moo/lib/moo-cmn.h index 9e88787..b4ae7ad 100644 --- a/moo/lib/moo-cmn.h +++ b/moo/lib/moo-cmn.h @@ -37,7 +37,7 @@ # include "moo-msw.h" #elif defined(__OS2__) # include "moo-os2.h" -#elif defined(__MSDOS__) +#elif defined(__DOS__) # include "moo-dos.h" #elif defined(macintosh) # include "moo-mac.h" /* class mac os */ @@ -131,7 +131,7 @@ # define MOO_HAVE_INT32_T typedef unsigned __int32_t moo_uint32_t; typedef signed __int32_t moo_int32_t; -#elif defined(__MSDOS__) +#elif defined(__DOS__) # define MOO_HAVE_UINT32_T # define MOO_HAVE_INT32_T typedef unsigned long int moo_uint32_t; diff --git a/moo/lib/moo-utl.h b/moo/lib/moo-utl.h index fe26890..a0169bb 100644 --- a/moo/lib/moo-utl.h +++ b/moo/lib/moo-utl.h @@ -59,9 +59,9 @@ MOO_EXPORT moo_oow_t moo_hashbytes ( return moo_hashbytes((const moo_oob_t*)ptr, len * MOO_SIZEOF(moo_oohw_t)); } #else -# define moo_hashbchars(ptr,len) moo_hashbytes((const moo_oob_t*)ptr,len * MOO_SIZEOF(moo_bch_t)) -# define moo_hashuchars(ptr,len) moo_hashbytes((const moo_oob_t*)ptr,len * MOO_SIZEOF(moo_uch_t)) -# define moo_hashwords(ptr,len) moo_hashbytes((const moo_oob_t*)ptr, len * MOO_SIZEOF(moo_oow_t)) +# define moo_hashbchars(ptr,len) moo_hashbytes((const moo_oob_t*)ptr,len * MOO_SIZEOF(moo_bch_t)) +# define moo_hashuchars(ptr,len) moo_hashbytes((const moo_oob_t*)ptr,len * MOO_SIZEOF(moo_uch_t)) +# define moo_hashwords(ptr,len) moo_hashbytes((const moo_oob_t*)ptr, len * MOO_SIZEOF(moo_oow_t)) # define moo_hashhalfwords(ptr,len) moo_hashbytes((const moo_oob_t*)ptr, len * MOO_SIZEOF(moo_oohw_t)) #endif @@ -71,12 +71,6 @@ MOO_EXPORT moo_oow_t moo_hashbytes ( # define moo_hashoochars(ptr,len) moo_hashbchars(ptr,len) #endif - -MOO_EXPORT moo_oow_t moo_hashwords ( - const moo_oow_t* ptr, - moo_oow_t len -); - /** * The moo_equaluchars() function determines equality of two strings * of the same length \a len. diff --git a/moo/mod/console.c b/moo/mod/console.c index b0c4a34..621f467 100644 --- a/moo/mod/console.c +++ b/moo/mod/console.c @@ -28,15 +28,18 @@ #include "console.h" #include -#include -#include +#if defined(_WIN32) -#include /* getenv */ +#elif defined(__DOS__) -#include -#include - -#include +#else +# include +# include +# include /* getenv */ +# include +# include +# include +#endif typedef struct console_t console_t; struct console_t @@ -66,7 +69,9 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs) /* error */ } - +#elif defined(__DOS__) + moo->errnum = MOO_ENOIMPL; + return -1; #else console_t* con; @@ -114,11 +119,10 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs) /*write (fd, tparm (cup, wsz.ws_row - 1, 0), strlen(tparm (cup, wsz.ws_row - 1, 0)));*/ write (fd, tiparm (cup, 0, 0), strlen(tiparm (cup, 0, 0))); } -#endif - #endif MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP((moo_oow_t)con)); +#endif return MOO_PF_SUCCESS; } @@ -128,11 +132,14 @@ static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs) HANDLE h; h = MOO_STACK_GETARG (moo, nargs, 0); +#elif defined(__DOS__) + + /* TODO */ + #else -#endif console_t* con; - con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG (moo, nargs, 0)); + con = (console_t*)MOO_OOP_TO_SMOOI(MOO_STACK_GETARG (moo, nargs, 0)); /* TODO: sanity check */ if (con->fd_opened) close (con->fd); @@ -140,10 +147,15 @@ static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs) moo_freemem (moo, con); MOO_STACK_SETRETTORCV (moo, nargs); return MOO_PF_SUCCESS; +#endif } static moo_pfrc_t pf_write (moo_t* moo, moo_ooi_t nargs) { +#if defined(_WIN32) +#elif defined(__DOS__) + +#else console_t* con; moo_oop_char_t oomsg; @@ -183,10 +195,15 @@ static moo_pfrc_t pf_write (moo_t* moo, moo_ooi_t nargs) MOO_STACK_SETRETTORCV (moo, nargs); /* TODO: change return code */ return MOO_PF_SUCCESS; +#endif } static moo_pfrc_t pf_clear (moo_t* moo, moo_ooi_t nargs) { +#if defined(_WIN32) +#elif defined(__DOS__) + +#else console_t* con; con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG(moo, nargs, 0)); @@ -195,10 +212,15 @@ static moo_pfrc_t pf_clear (moo_t* moo, moo_ooi_t nargs) MOO_STACK_SETRETTORCV (moo, nargs); return MOO_PF_SUCCESS; +#endif } static moo_pfrc_t pf_setcursor (moo_t* moo, moo_ooi_t nargs) { +#if defined(_WIN32) +#elif defined(__DOS__) + +#else console_t* con; moo_oop_oop_t point; char* cup; @@ -217,6 +239,7 @@ static moo_pfrc_t pf_setcursor (moo_t* moo, moo_ooi_t nargs) MOO_STACK_SETRETTORCV (moo, nargs); return MOO_PF_SUCCESS; +#endif } /* ------------------------------------------------------------------------ */ @@ -268,7 +291,6 @@ static void unload (moo_t* moo, moo_mod_t* mod) /* TODO: close all open handle?? */ } - int moo_mod_console (moo_t* moo, moo_mod_t* mod) { mod->query = query; diff --git a/moo/mod/stdio.c b/moo/mod/stdio.c index 8b5cf7d..ce71c4b 100644 --- a/moo/mod/stdio.c +++ b/moo/mod/stdio.c @@ -32,6 +32,10 @@ #include #include +#if !defined(PATH_MAX) +# define PATH_MAX 256 +#endif + typedef struct stdio_t stdio_t; struct stdio_t {