diff options
-rw-r--r-- | auto.def | 6 | ||||
-rw-r--r-- | jim-aio.c | 9 | ||||
-rw-r--r-- | jim-array.c | 1 | ||||
-rw-r--r-- | jim-clock.c | 5 | ||||
-rw-r--r-- | jim-exec.c | 9 | ||||
-rw-r--r-- | jim-file.c | 43 | ||||
-rw-r--r-- | jim-package.c | 7 | ||||
-rw-r--r-- | jim-readdir.c | 5 | ||||
-rw-r--r-- | jim-win32compat.c | 11 | ||||
-rw-r--r-- | jim-win32compat.h | 12 | ||||
-rw-r--r-- | jim.c | 10 | ||||
-rwxr-xr-x | make-bootstrap-jim | 21 | ||||
-rw-r--r-- | stdlib.tcl | 2 |
13 files changed, 98 insertions, 43 deletions
@@ -62,8 +62,8 @@ options { cc-check-types "long long" -cc-check-includes sys/socket.h netinet/in.h arpa/inet.h netdb.h -cc-check-includes sys/un.h dlfcn.h unistd.h crt_externs.h +cc-check-includes sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h +cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h define LDLIBS "" @@ -79,7 +79,7 @@ if {[cc-check-function-in-lib socket socket]} { } cc-check-functions ualarm lstat fork vfork system select -cc-check-functions backtrace geteuid mkstemp realpath strptime gettimeofday +cc-check-functions backtrace geteuid mkstemp realpath strptime cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes if {[cc-check-functions sysinfo]} { @@ -38,7 +38,6 @@ * official policies, either expressed or implied, of the Jim Tcl Project. **/ -#include <unistd.h> #include <stdio.h> #include <string.h> #include <errno.h> @@ -52,6 +51,7 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> +#include <unistd.h> #ifdef HAVE_SYS_UN_H #include <sys/un.h> #endif @@ -973,6 +973,7 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { const char *mode; + const char *filename; if (argc != 2 && argc != 3) { Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?"); @@ -980,7 +981,7 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc, } mode = (argc == 3) ? Jim_String(argv[2]) : "r"; - const char *filename = Jim_String(argv[1]); + filename = Jim_String(argv[1]); #ifdef jim_ext_tclcompat /* If the filename starts with '|', use popen instead */ @@ -1036,7 +1037,9 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam if (fh == NULL) { JimAioSetError(interp, filename); - close(fd); + if (fd >= 0) { + close(fd); + } Jim_DecrRefCount(interp, filename); return JIM_ERR; } diff --git a/jim-array.c b/jim-array.c index 76c6bc6..e798863 100644 --- a/jim-array.c +++ b/jim-array.c @@ -48,7 +48,6 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> -#include <unistd.h> #include <errno.h> #include "jim.h" diff --git a/jim-clock.c b/jim-clock.c index 3d95aa3..fe957b2 100644 --- a/jim-clock.c +++ b/jim-clock.c @@ -14,12 +14,15 @@ #include <string.h> #include <stdio.h> #include <time.h> -#include <sys/time.h> #include "jim.h" #include "jimautoconf.h" #include "jim-subcmd.h" +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif + static int clock_cmd_format(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { /* How big is big enough? */ @@ -90,10 +90,13 @@ int Jim_execInit(Jim_Interp *interp) #include <errno.h> #include <signal.h> -#define XXX printf("@%s:%d\n", __FILE__, __LINE__); fflush(stdout); - #if defined(__MINGW32__) - /* XXX: Should we use this implementation for cygwin too? */ + /* XXX: Should we use this implementation for cygwin too? msvc? */ + #ifndef STRICT + #define STRICT + #endif + #define WIN32_LEAN_AND_MEAN + #include <windows.h> #include <fcntl.h> typedef HANDLE fdtype; @@ -47,16 +47,27 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> -#include <unistd.h> #include <errno.h> #include <sys/stat.h> -#include <sys/param.h> -#include <sys/time.h> #include "jim.h" #include "jimautoconf.h" #include "jim-subcmd.h" +#ifdef HAVE_UTIMES +#include <sys/time.h> +#endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#elif defined(_MSC_VER) +#include <direct.h> +#define F_OK 0 +#define W_OK 2 +#define R_OK 4 +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#endif + # ifndef MAXPATHLEN # define MAXPATHLEN JIM_PATH_LEN # endif @@ -86,25 +97,31 @@ static const char *JimGetFileType(int mode) else if (S_ISDIR(mode)) { return "directory"; } +#ifdef S_ISCHR else if (S_ISCHR(mode)) { return "characterSpecial"; } +#endif +#ifdef S_ISBLK else if (S_ISBLK(mode)) { return "blockSpecial"; } +#endif +#ifdef S_ISFIFO else if (S_ISFIFO(mode)) { return "fifo"; -#ifdef S_ISLNK } +#endif +#ifdef S_ISLNK else if (S_ISLNK(mode)) { return "link"; + } #endif #ifdef S_ISSOCK - } else if (S_ISSOCK(mode)) { return "socket"; -#endif } +#endif return "unknown"; } @@ -189,7 +206,7 @@ static int file_cmd_dirname(Jim_Interp *interp, int argc, Jim_Obj *const *argv) else if (p == path) { Jim_SetResultString(interp, "/", -1); } -#if defined(__MINGW32__) +#if defined(__MINGW32__) || defined(_MSC_VER) else if (p[-1] == ':') { /* z:/dir => z:/ */ Jim_SetResultString(interp, path, p - path + 1); @@ -280,7 +297,7 @@ static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv) /* Absolute component, so go back to the start */ last = newname; } -#if defined(__MINGW32__) +#if defined(__MINGW32__) || defined(_MSC_VER) else if (strchr(part, ':')) { /* Absolute compontent on mingw, so go back to the start */ last = newname; @@ -349,7 +366,15 @@ static int file_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv) static int file_cmd_executable(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { +#ifdef X_OK return file_access(interp, argv[0], X_OK); +#else + /* XXX: X_OK doesn't work under Windows. + * In any case, may need to add .exe, etc. so just lie! + */ + Jim_SetResultBool(interp, 1); + return JIM_OK; +#endif } static int file_cmd_exists(Jim_Interp *interp, int argc, Jim_Obj *const *argv) @@ -901,7 +926,7 @@ static int Jim_PwdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_SetResultString(interp, "Failed to get pwd", -1); return JIM_ERR; } -#if defined(__MINGW32__) +#if defined(__MINGW32__) || defined(_MSC_VER) { /* Try to keep backlashes out of paths */ char *p = cwd; diff --git a/jim-package.c b/jim-package.c index 83582ea..51c5c69 100644 --- a/jim-package.c +++ b/jim-package.c @@ -1,10 +1,15 @@ -#include <unistd.h> #include <string.h> #include "jim.h" #include "jimautoconf.h" #include "jim-subcmd.h" +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#else +#define R_OK 4 +#endif + /* ----------------------------------------------------------------------------- * Packages handling * ---------------------------------------------------------------------------*/ diff --git a/jim-readdir.c b/jim-readdir.c index 67fc956..c5a65ae 100644 --- a/jim-readdir.c +++ b/jim-readdir.c @@ -48,11 +48,14 @@ #include <errno.h> #include <stdio.h> #include <string.h> -#include <dirent.h> #include "jim.h" #include "jimautoconf.h" +#ifdef HAVE_DIRENT_H +#include <dirent.h> +#endif + /* *----------------------------------------------------------------------------- * diff --git a/jim-win32compat.c b/jim-win32compat.c index 9eb8e7f..94bd831 100644 --- a/jim-win32compat.c +++ b/jim-win32compat.c @@ -1,6 +1,13 @@ #include "jim.h" #include "jimautoconf.h" +#if defined(_WIN32) || defined(WIN32) +#ifndef STRICT +#define STRICT +#endif +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + #if defined(HAVE_DLOPEN_COMPAT) void *dlopen(const char *path, int mode) { @@ -30,6 +37,9 @@ char *dlerror(void) #endif #ifdef _MSC_VER + +#include <sys/timeb.h> + /* POSIX gettimeofday() compatibility for WIN32 */ int gettimeofday(struct timeval *tv, void *unused) { @@ -119,3 +129,4 @@ struct dirent *readdir(DIR * dir) return result; } #endif +#endif diff --git a/jim-win32compat.h b/jim-win32compat.h index 89e01f5..8dc0bde 100644 --- a/jim-win32compat.h +++ b/jim-win32compat.h @@ -5,11 +5,6 @@ /* Note that at this point we don't yet have access to jimautoconf.h */ #if defined(_WIN32) || defined(WIN32) -#ifndef STRICT - #define STRICT -#endif -#define WIN32_LEAN_AND_MEAN -#include <windows.h> #define HAVE_DLOPEN void *dlopen(const char *path, int mode); @@ -24,8 +19,7 @@ char *dlerror(void); #pragma warning(disable:4146) #endif -#define strcasecmp _stricmp - +#include <limits.h> #define jim_wide _int64 #ifndef LLONG_MAX #define LLONG_MAX 9223372036854775807I64 @@ -36,10 +30,12 @@ char *dlerror(void); #define JIM_WIDE_MIN LLONG_MIN #define JIM_WIDE_MAX LLONG_MAX #define JIM_WIDE_MODIFIER "I64d" +#define strcasecmp _stricmp +#define strtoull _strtoui64 +#define snprintf _snprintf #include <io.h> -#define HAVE_GETTIMEOFDAY struct timeval { long tv_sec; long tv_usec; @@ -55,13 +55,13 @@ #include <time.h> #include <setjmp.h> -#include <unistd.h> -#include <sys/time.h> - #include "jim.h" #include "jimautoconf.h" #include "utf8.h" +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif #ifdef HAVE_BACKTRACE #include <execinfo.h> #endif @@ -13406,10 +13406,8 @@ static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2); Jim_SetResult(interp, objPtr); return JIM_OK; - - default: - abort(); } + return JIM_ERR; } /* [subst] */ diff --git a/make-bootstrap-jim b/make-bootstrap-jim index ac84367..5af4acf 100755 --- a/make-bootstrap-jim +++ b/make-bootstrap-jim @@ -58,22 +58,31 @@ for i in $allexts; do echo "#define jim_ext_$i" done -# Can we make a bootstrap jimsh work even on mingw32? cat <<EOF -#if defined(__MINGW32__) +#if defined(_MSC_VER) +#define TCL_PLATFORM_OS "windows" +#define TCL_PLATFORM_PLATFORM "windows" +#define TCL_PLATFORM_PATH_SEPARATOR ";" +#define HAVE_MKDIR_ONE_ARG +#define HAVE_SYSTEM +#elif defined(__MINGW32__) #define TCL_PLATFORM_OS "mingw" #define TCL_PLATFORM_PLATFORM "windows" #define TCL_PLATFORM_PATH_SEPARATOR ";" #define HAVE_MKDIR_ONE_ARG #define HAVE_SYSTEM -#define WIN32_LEAN_AND_MEAN -#include <windows.h> +#define HAVE_SYS_TIME_H +#define HAVE_DIRENT_H +#define HAVE_UNISTD_H #else #define TCL_PLATFORM_OS "unknown" #define TCL_PLATFORM_PLATFORM "unix" #define TCL_PLATFORM_PATH_SEPARATOR ":" #define HAVE_VFORK #define HAVE_WAITPID +#define HAVE_SYS_TIME_H +#define HAVE_DIRENT_H +#define HAVE_UNISTD_H #endif EOF @@ -85,7 +94,7 @@ outputsource() } # Now output header files, removing references to jim header files -for i in utf8.h jim.h jim-subcmd.h jimregexp.h ; do +for i in jim-win32compat.h utf8.h jim.h jim-subcmd.h jimregexp.h ; do outputsource $i done @@ -99,7 +108,7 @@ done makeloadexts $allexts # And finally the core source code -for i in jim.c jim-subcmd.c utf8.c jim-format.c jimregexp.c; do +for i in jim.c jim-subcmd.c utf8.c jim-format.c jimregexp.c jim-win32compat.c; do outputsource $i done echo "#ifndef JIM_BOOTSTRAP_LIB_ONLY" @@ -105,7 +105,7 @@ proc {info nameofexecutable} {} { return [file join [pwd] $::jim_argv0] } foreach path [split [env PATH ""] $::tcl_platform(pathSeparator)] { - set exec [file join [pwd] $path $::jim_argv0] + set exec [file join [pwd] [string map {\\ /} $path] $::jim_argv0] if {[file executable $exec]} { return $exec } |