diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-04-04 14:50:05 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-04-04 14:50:05 (GMT) |
commit | 1cbe41a90cc155259e98e2e4ed1cfdae770d19a6 (patch) | |
tree | 09a887b9d2dbdf1d0aadc016d311022eeea7008b | |
parent | 5cc8272056a2950e552b579f4717b123a9578bdc (diff) | |
download | tcl-1cbe41a90cc155259e98e2e4ed1cfdae770d19a6.zip tcl-1cbe41a90cc155259e98e2e4ed1cfdae770d19a6.tar.gz tcl-1cbe41a90cc155259e98e2e4ed1cfdae770d19a6.tar.bz2 |
implement TclpGetPid for Cygwin
-rw-r--r-- | generic/tclInt.decls | 28 | ||||
-rw-r--r-- | generic/tclIntPlatDecls.h | 74 | ||||
-rw-r--r-- | generic/tclStubInit.c | 18 | ||||
-rw-r--r-- | mac/tclMacPort.h | 1 | ||||
-rw-r--r-- | unix/tclUnixFile.c | 38 | ||||
-rw-r--r-- | unix/tclUnixPort.h | 1 | ||||
-rw-r--r-- | win/tcl.m4 | 3 |
7 files changed, 136 insertions, 27 deletions
diff --git a/generic/tclInt.decls b/generic/tclInt.decls index d380270..b7c7ee4 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -978,8 +978,9 @@ declare 7 unix { int TclWinSetSockOpt(void *s, int level, int optname, const char *optval, int optlen) } +# On non-cygwin, this is actually a reference to TclUnixWaitForFile declare 8 unix { - int TclUnixWaitForFile(int fd, int mask, int timeout) + unsigned long TclpGetPid(Tcl_Pid pid) } # Added in 8.1: @@ -1049,7 +1050,30 @@ declare 30 unix { declare 31 unix { int TclpCloseFile(TclFile file) } - +#declare 32 unix { +# Tcl_Channel TclpCreateCommandChannel(TclFile readFile, +# TclFile writeFile, TclFile errorFile, int numPids, Tcl_Pid *pidPtr) +#} +#declare 33 unix { +# int TclpCreatePipe(TclFile *readPipe, TclFile *writePipe) +#} +declare 34 unix { + int TclpCreateProcess (Tcl_Interp *interp, + int argc, const char **argv, TclFile inputFile, + TclFile outputFile, TclFile errorFile, Tcl_Pid *pidPtr) +} +#declare 35 unix { +# char *TclpInetNtoa(struct in_addr addr) +#} +declare 36 unix { + TclFile TclpMakeFile (Tcl_Channel channel, int direction) +} +declare 37 unix { + TclFile TclpOpenFile (const char *fname, int mode) +} +declare 38 unix { + int TclUnixWaitForFile(int fd, int mask, int timeout) +} # Local Variables: # mode: tcl diff --git a/generic/tclIntPlatDecls.h b/generic/tclIntPlatDecls.h index 7ce711d..50c546c 100644 --- a/generic/tclIntPlatDecls.h +++ b/generic/tclIntPlatDecls.h @@ -13,16 +13,6 @@ #ifndef _TCLINTPLATDECLS #define _TCLINTPLATDECLS -#if !defined(__WIN32__) && !defined(MAC_TCL) /* UNIX */ -EXTERN int TclpCreateProcess _ANSI_ARGS_((Tcl_Interp *interp, - int argc, CONST char **argv, TclFile inputFile, - TclFile outputFile, TclFile errorFile, Tcl_Pid *pidPtr)); -EXTERN TclFile TclpMakeFile _ANSI_ARGS_((Tcl_Channel channel, - int direction)); -EXTERN TclFile TclpOpenFile _ANSI_ARGS_((CONST char *fname, - int mode)); -#endif - /* * WARNING: This file is automatically generated by the tools/genStubs.tcl * script. Any modifications to the function declarations below should be made @@ -58,8 +48,7 @@ EXTERN unsigned short TclWinNToHS _ANSI_ARGS_((unsigned short ns)); EXTERN int TclWinSetSockOpt _ANSI_ARGS_((VOID *s, int level, int optname, CONST char *optval, int optlen)); /* 8 */ -EXTERN int TclUnixWaitForFile _ANSI_ARGS_((int fd, int mask, - int timeout)); +EXTERN unsigned long TclpGetPid _ANSI_ARGS_((Tcl_Pid pid)); /* 9 */ EXTERN int TclWinGetPlatformId _ANSI_ARGS_((void)); /* 10 */ @@ -110,6 +99,23 @@ EXTERN void TclGetAndDetachPids _ANSI_ARGS_((Tcl_Interp *interp, Tcl_Channel chan)); /* 31 */ EXTERN int TclpCloseFile _ANSI_ARGS_((TclFile file)); +/* Slot 32 is reserved */ +/* Slot 33 is reserved */ +/* 34 */ +EXTERN int TclpCreateProcess _ANSI_ARGS_((Tcl_Interp *interp, + int argc, CONST char **argv, + TclFile inputFile, TclFile outputFile, + TclFile errorFile, Tcl_Pid *pidPtr)); +/* Slot 35 is reserved */ +/* 36 */ +EXTERN TclFile TclpMakeFile _ANSI_ARGS_((Tcl_Channel channel, + int direction)); +/* 37 */ +EXTERN TclFile TclpOpenFile _ANSI_ARGS_((CONST char *fname, + int mode)); +/* 38 */ +EXTERN int TclUnixWaitForFile _ANSI_ARGS_((int fd, int mask, + int timeout)); #endif /* UNIX */ #ifdef __WIN32__ /* 0 */ @@ -267,7 +273,7 @@ typedef struct TclIntPlatStubs { VOID *reserved5; unsigned short (*tclWinNToHS) _ANSI_ARGS_((unsigned short ns)); /* 6 */ int (*tclWinSetSockOpt) _ANSI_ARGS_((VOID *s, int level, int optname, CONST char *optval, int optlen)); /* 7 */ - int (*tclUnixWaitForFile) _ANSI_ARGS_((int fd, int mask, int timeout)); /* 8 */ + unsigned long (*tclpGetPid) _ANSI_ARGS_((Tcl_Pid pid)); /* 8 */ int (*tclWinGetPlatformId) _ANSI_ARGS_((void)); /* 9 */ Tcl_DirEntry * (*tclpReaddir) _ANSI_ARGS_((DIR *dir)); /* 10 */ struct tm * (*tclpLocaltime_unix) _ANSI_ARGS_((TclpTime_t_CONST clock)); /* 11 */ @@ -291,6 +297,13 @@ typedef struct TclIntPlatStubs { int (*tclWinCPUID) _ANSI_ARGS_((unsigned int index, unsigned int *regs)); /* 29 */ void (*tclGetAndDetachPids) _ANSI_ARGS_((Tcl_Interp *interp, Tcl_Channel chan)); /* 30 */ int (*tclpCloseFile) _ANSI_ARGS_((TclFile file)); /* 31 */ + VOID *reserved32; + VOID *reserved33; + int (*tclpCreateProcess) _ANSI_ARGS_((Tcl_Interp *interp, int argc, CONST char **argv, TclFile inputFile, TclFile outputFile, TclFile errorFile, Tcl_Pid *pidPtr)); /* 34 */ + VOID *reserved35; + TclFile (*tclpMakeFile) _ANSI_ARGS_((Tcl_Channel channel, int direction)); /* 36 */ + TclFile (*tclpOpenFile) _ANSI_ARGS_((CONST char *fname, int mode)); /* 37 */ + int (*tclUnixWaitForFile) _ANSI_ARGS_((int fd, int mask, int timeout)); /* 38 */ #endif /* UNIX */ #ifdef __WIN32__ void (*tclWinConvertError) _ANSI_ARGS_((DWORD errCode)); /* 0 */ @@ -399,9 +412,9 @@ extern TclIntPlatStubs *tclIntPlatStubsPtr; #define TclWinSetSockOpt \ (tclIntPlatStubsPtr->tclWinSetSockOpt) /* 7 */ #endif -#ifndef TclUnixWaitForFile -#define TclUnixWaitForFile \ - (tclIntPlatStubsPtr->tclUnixWaitForFile) /* 8 */ +#ifndef TclpGetPid +#define TclpGetPid \ + (tclIntPlatStubsPtr->tclpGetPid) /* 8 */ #endif #ifndef TclWinGetPlatformId #define TclWinGetPlatformId \ @@ -477,6 +490,25 @@ extern TclIntPlatStubs *tclIntPlatStubsPtr; #define TclpCloseFile \ (tclIntPlatStubsPtr->tclpCloseFile) /* 31 */ #endif +/* Slot 32 is reserved */ +/* Slot 33 is reserved */ +#ifndef TclpCreateProcess +#define TclpCreateProcess \ + (tclIntPlatStubsPtr->tclpCreateProcess) /* 34 */ +#endif +/* Slot 35 is reserved */ +#ifndef TclpMakeFile +#define TclpMakeFile \ + (tclIntPlatStubsPtr->tclpMakeFile) /* 36 */ +#endif +#ifndef TclpOpenFile +#define TclpOpenFile \ + (tclIntPlatStubsPtr->tclpOpenFile) /* 37 */ +#endif +#ifndef TclUnixWaitForFile +#define TclUnixWaitForFile \ + (tclIntPlatStubsPtr->tclUnixWaitForFile) /* 38 */ +#endif #endif /* UNIX */ #ifdef __WIN32__ #ifndef TclWinConvertError @@ -703,7 +735,14 @@ extern TclIntPlatStubs *tclIntPlatStubsPtr; #undef TclpLocaltime_unix #undef TclpGmtime_unix -#if !defined(__WIN32__) && !defined(MAC_TCL) && defined(USE_TCL_STUBS) +#if !defined(__WIN32__) && !defined(MAC_TCL) +# undef TclpGetPid +# define TclpGetPid(pid) ((unsigned long) (pid)) + +# if defined(USE_TCL_STUBS) +# undef TclpCreateProcess +# undef TclpMakeFile +# undef TclpOpenFile # ifdef __CYGWIN__ # define TclpCreateProcess ((int (*) _ANSI_ARGS_((Tcl_Interp *, int, \ CONST char **, TclFile, TclFile, TclFile, Tcl_Pid *))) \ @@ -732,6 +771,7 @@ extern TclIntPlatStubs *tclIntPlatStubsPtr; # define TclpCloseFile ((int (*) _ANSI_ARGS_((TclFile))) \ tclIntPlatStubsPtr->tclWinConvertWSAError) # endif +# endif #endif #endif /* _TCLINTPLATDECLS */ diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index cbb89a2..50fc9eb 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -31,6 +31,7 @@ #undef Tcl_ValidateAllMemory #undef Tcl_FindHashEntry #undef Tcl_CreateHashEntry +#undef TclpGetPid /* * Keep a record of the original Notifier procedures, created in the @@ -85,6 +86,7 @@ int __stdcall GetModuleHandleExW(unsigned int, const char *, void *); #define TclWinAddProcess (void (*) (void *, unsigned int)) doNothing #define TclWinFlushDirtyChannels doNothing #define TclWinResetInterfaces doNothing +#define TclpGetPid getPid static Tcl_Encoding winTCharEncoding; @@ -130,6 +132,12 @@ TclWinNoBackslash(char *path) return path; } +static unsigned long +TclpGetPid(Tcl_Pid pid) +{ + return (unsigned long) (size_t) pid; +} + static void doNothing(void) { @@ -186,6 +194,7 @@ Tcl_WinTCharToUtf( # define TclWinSetInterfaces 0 # define TclWinFlushDirtyChannels 0 # define TclWinResetInterfaces 0 +# define TclpGetPid 0 # define TclMacOSXGetFileAttribute 0 /* Only implemented in Tcl >= 8.5 */ # define TclMacOSXMatchType 0 /* Only implemented in Tcl >= 8.5 */ # define TclMacOSXNotifierAddRunLoopMode 0 /* Only implemented in Tcl >= 8.5 */ @@ -454,7 +463,7 @@ TclIntPlatStubs tclIntPlatStubs = { NULL, /* 5 */ TclWinNToHS, /* 6 */ TclWinSetSockOpt, /* 7 */ - TclUnixWaitForFile, /* 8 */ + TclpGetPid, /* 8 */ TclWinGetPlatformId, /* 9 */ TclpReaddir, /* 10 */ TclpLocaltime_unix, /* 11 */ @@ -478,6 +487,13 @@ TclIntPlatStubs tclIntPlatStubs = { TclWinCPUID, /* 29 */ TclGetAndDetachPids, /* 30 */ TclpCloseFile, /* 31 */ + NULL, /* 32 */ + NULL, /* 33 */ + TclpCreateProcess, /* 34 */ + NULL, /* 35 */ + TclpMakeFile, /* 36 */ + TclpOpenFile, /* 37 */ + TclUnixWaitForFile, /* 38 */ #endif /* UNIX */ #ifdef __WIN32__ TclWinConvertError, /* 0 */ diff --git a/mac/tclMacPort.h b/mac/tclMacPort.h index f427899..c5c1743 100644 --- a/mac/tclMacPort.h +++ b/mac/tclMacPort.h @@ -215,7 +215,6 @@ extern char **environ; * address platform-specific issues. */ -#define TclpGetPid(pid) ((unsigned long) (pid)) #define TclSetSystemEnv(a,b) #define tzset() diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index 5eac978..4ba2e47 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -22,7 +22,8 @@ static int NativeMatchType(CONST char* nativeName, Tcl_GlobTypeData *types); * TclpFindExecutable -- * * This procedure computes the absolute path name of the current - * application, given its argv[0] value. + * application, given its argv[0] value. For Cygwin, argv[0] is + * ignored and the path is determined the same as under win32. * * Results: * A dirty UTF string that is the path to the executable. At this @@ -45,18 +46,44 @@ TclpFindExecutable(argv0) CONST char *argv0; /* The value of the application's argv[0] * (native). */ { + int length; +#ifdef __CYGWIN__ + char buf[PATH_MAX * TCL_UTF_MAX + 1]; + char name[PATH_MAX * TCL_UTF_MAX + 1]; +#else CONST char *name, *p; Tcl_StatBuf statBuf; - int length; Tcl_DString buffer, nameString; +#endif - if (argv0 == NULL) { - return NULL; - } if (tclNativeExecutableName != NULL) { return tclNativeExecutableName; } +#ifdef __CYGWIN__ + + /* Make some symbols available without including <windows.h> */ +# define CP_UTF8 65001 + extern int cygwin_conv_to_full_posix_path(const char *, char *); + extern __stdcall int GetModuleFileNameW(void *, const char *, int); + extern __stdcall int WideCharToMultiByte(int, int, const char *, int, + const char *, int, const char *, const char *); + + GetModuleFileNameW(NULL, name, PATH_MAX); + WideCharToMultiByte(CP_UTF8, 0, name, -1, buf, PATH_MAX, NULL, NULL); + cygwin_conv_to_full_posix_path(buf, name); + length = strlen(name); + if ((length > 4) && !strcasecmp(name + length - 4, ".exe")) { + /* Strip '.exe' part. */ + length -= 4; + } + tclNativeExecutableName = (char *) ckalloc(length + 1); + memcpy(tclNativeExecutableName, name, length); + buf[length] = '\0'; +#else + if (argv0 == NULL) { + return NULL; + } Tcl_DStringInit(&buffer); name = argv0; @@ -174,6 +201,7 @@ gotName: done: Tcl_DStringFree(&buffer); +#endif return tclNativeExecutableName; } diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h index c0bf77d8..a26922c 100644 --- a/unix/tclUnixPort.h +++ b/unix/tclUnixPort.h @@ -658,7 +658,6 @@ extern int copyfile(const char *from, const char *to, void *state, * address platform-specific issues. */ -#define TclpGetPid(pid) ((unsigned long) (pid)) #define TclpReleaseFile(file) /* Nothing. */ /* @@ -27,6 +27,9 @@ AC_DEFUN([SC_PATH_TCLCONFIG], [ else TCL_BIN_DIR_DEFAULT=../../tcl/win fi + if test ! -f $TCL_BIN_DIR_DEFAULT/tclConfig.sh; then + TCL_BIN_DIR_DEFAULT="${TCL_BIN_DIR_DEFAULT}/../unix" + fi AC_ARG_WITH(tcl, [ --with-tcl=DIR use Tcl 8.4 binaries from DIR], TCL_BIN_DIR=$withval, TCL_BIN_DIR=`cd $TCL_BIN_DIR_DEFAULT; pwd`) |