aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatthoyts <patthoyts>2007-01-31 00:49:05 +0000
committerpatthoyts <patthoyts>2007-01-31 00:49:05 +0000
commit57b3c20128045e01dabc18fe8bf063006b1fe7b1 (patch)
tree0374318428e7dda5e0d3ee043fad45bcb1a9316c
parente5ba64de6c1cc81beb43eb3ad302f649017af045 (diff)
downloadjimtcl-57b3c20128045e01dabc18fe8bf063006b1fe7b1.zip
jimtcl-57b3c20128045e01dabc18fe8bf063006b1fe7b1.tar.gz
jimtcl-57b3c20128045e01dabc18fe8bf063006b1fe7b1.tar.bz2
Fixed the stdio declarations to work on Windows and likely on Solaris.
A number of MSVC related fixes including support for creating a jim dll
-rw-r--r--Makefile.vc112
-rw-r--r--jim-aio.c7
-rw-r--r--jim-win32.c60
-rw-r--r--jim-win32com.c395
-rw-r--r--jim.c81
-rw-r--r--jim.h22
6 files changed, 530 insertions, 147 deletions
diff --git a/Makefile.vc b/Makefile.vc
index 395381c..67b3f46 100644
--- a/Makefile.vc
+++ b/Makefile.vc
@@ -14,7 +14,7 @@
# Copyright (C) 2005 Pat Thoyts <patthoyts@users.sourceforge.net>
#
#-------------------------------------------------------------------------
-# $Id: Makefile.vc,v 1.12 2005/04/06 14:16:56 patthoyts Exp $
+# $Id: Makefile.vc,v 1.13 2007/01/31 00:49:05 patthoyts Exp $
#-------------------------------------------------------------------------
SRCDIR =.
@@ -25,7 +25,30 @@ DEBUG =0
!ifndef PROFILE
PROFILE =0
!endif
+!ifndef SYMBOLS
+SYMBOLS = 0
+!endif
+!ifndef CC
+CC=cl
+!endif
+!ifndef LINK
+LINK=link
+!endif
+# If you have sqlite3 installed and want to build the extension add
+# SQLITE3DIR=c:\path\to\sqlite3
+#
+!ifndef SQLITE3DIR
+SQLITE3 =0
+!else
+SQLITE3 =1
+SQLITE_INC=-I$(SQLITE3DIR)
+SQLITE_LIB=-libpath:$(SQLITE3DIR) libsqlite3.lib
+!endif
+
+#-------------------------------------------------------------------------
+# There should be no need to edit below this point.
+#-------------------------------------------------------------------------
!if $(DEBUG)
OUTDIR =Debug
@@ -33,9 +56,14 @@ CFLAGS =-Od -Zi -GZ -MDd -D_DEBUG
LDFLAGS=-debug:full -debugtype:cv
!else
OUTDIR =Release
-CFLAGS =-O2 -Op -Gs -MD -DNDEBUG
+!if $(SYMBOLS)
+CFLAGS =-Od -Zi -Op -Gs -MD -DNDEBUG
+LDFLAGS=-debug -opt:ref -opt:icf,3
+!else
+CFLAGS =-O2 -Otip -Gs -MD -DNDEBUG
LDFLAGS=-release -opt:ref -opt:icf,3
!endif
+!endif
!if $(PROFILE)
CFLAGS =$(CFLAGS) -Zi
@@ -43,78 +71,114 @@ LDFLAGS=$(LDFLAGS) -profile -map
!endif
!if "$(OS)" == "Windows_NT"
-RMDIR = rmdir /s /q
+RMDIR = rmdir /s /q >NUL
!else
RMDIR = deltree /y
!endif
+DEL = del /f /q
TMPDIR =$(OUTDIR)\Objects
-CC =cl -nologo
-LD =link -nologo
+CC =$(CC) -nologo
+LD =$(LINK) -nologo
-# -Fd$(TMPDIR)^\
-CFLAGS =$(CFLAGS) -W3 -GX -YX -Fp$(TMPDIR)^\
+CFLAGS =$(CFLAGS) -W3 -YX -Fp$(TMPDIR)^\
INC =
DEFS =-DWIN32
LIBS =
-
-all: jim win32 win32com win32api
-jim: setup $(OUTDIR)\jim.exe
-jimwish: setup $(OUTDIR)\jimwish.exe
-dll: setup $(OUTDIR)\jim.dll
-win32: setup $(OUTDIR)\jim-win32-1.0.dll
+all: jim aio win32 win32com win32api dll #sqlite3 eventloop
+jim: setup $(OUTDIR)\jim.exe
+jimwish: setup $(OUTDIR)\jimwish.exe
+dll: setup $(OUTDIR)\jim.dll
+aio: setup $(OUTDIR)\jim-aio-1.0.dll
+sqlite3: setup $(OUTDIR)\jim-sqlite3-1.0.dll
+eventloop: setup $(OUTDIR)\jim-eventloop-1.0.dll
+win32: setup $(OUTDIR)\jim-win32-1.0.dll
win32api: setup $(OUTDIR)\jim-win32api-1.0.dll
win32com: setup $(OUTDIR)\jim-win32com-1.0.dll
$(OUTDIR)\jim.exe: $(TMPDIR)\jim.obj $(TMPDIR)\jimsh.obj
@$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)
-$(OUTDIR)\jim.dll: $(TMPDIR)\jim.obj
+$(OUTDIR)\jim.dll: $(TMPDIR)\jim.dll.obj
@$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS)
+ @if exist $(@:.dll=.exp) $(DEL) $(@:.dll=.exp)
$(OUTDIR)\jim-win32-1.0.dll: $(TMPDIR)\jim-win32.obj
- @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS)
+ @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS) >NUL
+ @if exist $(@:.dll=.exp) $(DEL) $(@:.dll=.exp)
$(OUTDIR)\jim-win32api-1.0.dll: $(TMPDIR)\jim-win32api.obj
- @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS)
+ @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS) >NUL
+ @if exist $(@:.dll=.exp) $(DEL) $(@:.dll=.exp)
$(OUTDIR)\jim-win32com-1.0.dll: $(TMPDIR)\jim-win32com.obj
- @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS)
+ @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS) >NUL
+ @if exist $(@:.dll=.exp) $(DEL) $(@:.dll=.exp)
+
+$(OUTDIR)\jim-aio-1.0.dll: $(TMPDIR)\jim-aio.obj
+ @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS) >NUL
+ @if exist $(@:.dll=.exp) $(DEL) $(@:.dll=.exp)
+
+$(OUTDIR)\jim-eventloop-1.0.dll: $(TMPDIR)\jim-eventloop.obj
+ @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS) >NUL
+ @if exist $(@:.dll=.exp) $(DEL) $(@:.dll=.exp)
+
+$(OUTDIR)\jim-sqlite3-1.0.dll: $(TMPDIR)\jim-sqlite3.obj
+!if $(SQLITE3)
+ @$(LD) $(LDFLAGS) -dll -out:$@ $** $(LIBS) $(SQLITE_LIB) >NUL
+ @if exist $(@:.dll=.exp) $(DEL) $(@:.dll=.exp)
+!else
+ @echo cannot build sqlite3 extension - SQLITE3DIR not defined
+!endif
$(OUTDIR)\jimwish.exe: $(TMPDIR)\jim.obj $(TMPDIR)\jimwish.obj
- @$(LD) $(LDFLAGS) -out:$@ $** $(LIBS) user32.lib
+ @$(LD) $(LDFLAGS) -out:$@ $** $(LIBS) user32.lib
-.PHONY: all jim dll win32 win32api win32com
+.PHONY: all jim dll win32 win32api win32com jim jimwish aio sqlite3
#-------------------------------------------------------------------------
setup:
@if not exist $(OUTDIR) mkdir $(OUTDIR)
@if not exist $(TMPDIR) mkdir $(TMPDIR)
-
test: jim
$(OUTDIR)\jim.exe test.tcl
clean:
- @if exist $(TMPDIR)\NUL $(RMDIR) $(TMPDIR) >NUL
+ @if exist $(TMPDIR)\NUL $(RMDIR) $(TMPDIR) >NUL
realclean: clean
- @if exist $(OUTDIR)\NUL $(RMDIR) $(OUTDIR) >NUL
+ @if exist $(OUTDIR)\NUL $(RMDIR) $(OUTDIR) >NUL
#-------------------------------------------------------------------------
.SUFFIXES:.c .cpp
{$(SRCDIR)}.c{$(TMPDIR)}.obj::
- @$(CC) $(CFLAGS) $(DEFS) $(INC) -Fa$(TMPDIR)\ -Fo$(TMPDIR)\ -c @<<
+ @$(CC) $(CFLAGS) $(DEFS) $(INC) -Fo$(TMPDIR)\ -c @<<
$<
<<
{$(SRCDIR)}.cpp{$(TMPDIR)}.obj::
- @$(CC) $(CFLAGS) $(DEFS) $(INC) -Fo$(TMPDIR)\ -c @<<
+ @$(CC) $(CFLAGS) $(DEFS) $(INC) -Fo$(TMPDIR)\ -c @<<
$<
<<
+$(TMPDIR)\jim.obj: $(SRCDIR)\jim.c $(SRCDIR)\jim.h
+$(TMPDIR)\jim-aio.obj: $(SRCDIR)\jim-aio.c $(SRCDIR)\jim.h
+$(TMPDIR)\jim-eventloop.obj: $(SRCDIR)\jim-eventloop.c $(SRCDIR)\jim.h
+$(TMPDIR)\jim-win32.obj: $(SRCDIR)\jim-win32.c $(SRCDIR)\jim.h
+$(TMPDIR)\jim-win32api.obj: $(SRCDIR)\jim-win32api.c $(SRCDIR)\jim.h
+$(TMPDIR)\jim-win32com.obj: $(SRCDIR)\jim-win32com.c $(SRCDIR)\jim.h
+$(TMPDIR)\jim.dll.obj: $(SRCDIR)\jim.c $(SRCDIR)\jim.h
+ @$(CC) -DBUILD_Jim $(CFLAGS) $(DEFS) $(INC) -Fo$@ -c $(SRCDIR)\jim.c
+$(TMPDIR)\jim-sqlite3.obj: $(SRCDIR)\jim-sqlite3.c $(SRCDIR)\jim.h
+!if $(SQLITE3)
+ @$(CC) $(CFLAGS) $(DEFS) $(INC) $(SQLITE_INC) -Fo$(TMPDIR)\ -c $(SRCDIR)\jim-sqlite3.c
+!else
+ @echo cannot build sqlite3 extension - SQLITE3DIR not defined
+!endif
+
#-------------------------------------------------------------------------
diff --git a/jim-aio.c b/jim-aio.c
index 7c3a4d7..74bf8ae 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -1,7 +1,7 @@
/* Jim - ANSI I/O extension
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
*
- * $Id: jim-aio.c,v 1.10 2006/11/06 16:54:48 antirez Exp $
+ * $Id: jim-aio.c,v 1.11 2007/01/31 00:49:05 patthoyts Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -340,10 +340,11 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
return JIM_OK;
}
+DLLEXPORT int
#ifndef JIM_STATICEXT
-int Jim_OnLoad(Jim_Interp *interp)
+Jim_OnLoad(Jim_Interp *interp)
#else
-int Jim_AioInit(Jim_Interp *interp)
+Jim_AioInit(Jim_Interp *interp)
#endif
{
#ifndef JIM_STATICEXT
diff --git a/jim-win32.c b/jim-win32.c
index c046561..0f075aa 100644
--- a/jim-win32.c
+++ b/jim-win32.c
@@ -2,7 +2,7 @@
*
* Copyright (C) 2005 Pat Thoyts <patthoyts@users.sourceforge.net>
*
- * $Id: jim-win32.c,v 1.30 2005/04/26 13:31:46 patthoyts Exp $
+ * $Id: jim-win32.c,v 1.31 2007/01/31 00:49:05 patthoyts Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,8 +38,6 @@
#pragma comment(lib, "psapi")
#endif /* _MSC_VER >= 1000 */
-__declspec(dllexport) int Jim_OnLoad(Jim_Interp *interp);
-
static HINSTANCE g_hInstance = 0;
BOOL APIENTRY
@@ -558,6 +556,59 @@ Win32_GetSystemTime(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
return JIM_OK;
}
+static int
+Win32_GetSystemInfo(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
+{
+ Jim_Obj *a[20];
+ SYSTEM_INFO si;
+ int n = 0;
+ struct pa_map { int arch; const char *name; };
+ struct pa_map *p, map[] = {
+ { PROCESSOR_ARCHITECTURE_INTEL, "intel" },
+ { PROCESSOR_ARCHITECTURE_MIPS, "mips" },
+ { PROCESSOR_ARCHITECTURE_ALPHA, "alpha" },
+ { PROCESSOR_ARCHITECTURE_PPC, "ppc" },
+ { PROCESSOR_ARCHITECTURE_SHX, "shx" },
+ { PROCESSOR_ARCHITECTURE_ARM, "arm" },
+ { PROCESSOR_ARCHITECTURE_IA64, "ia64" },
+ { PROCESSOR_ARCHITECTURE_ALPHA64,"alpha64" },
+ { PROCESSOR_ARCHITECTURE_MSIL, "msil" },
+ { PROCESSOR_ARCHITECTURE_AMD64, "amd64"},
+ { PROCESSOR_ARCHITECTURE_IA32_ON_WIN64, "ia32onwin64" },
+ { PROCESSOR_ARCHITECTURE_UNKNOWN,"unknown" }
+ };
+ JIM_NOTUSED(objc);
+ JIM_NOTUSED(objv);
+
+ GetSystemInfo(&si);
+
+ a[n++] = Jim_NewStringObj(interp, "ProcessorArchitecture", -1);
+ for (p = map; p->arch != PROCESSOR_ARCHITECTURE_UNKNOWN; ++p) {
+ if (p->arch == si.wProcessorArchitecture) {
+ break;
+ }
+ }
+ a[n++] = Jim_NewStringObj(interp, p->name, -1);
+
+#define JIMADD(name,element) \
+ a[n++] = Jim_NewStringObj(interp, #name, -1); \
+ a[n++] = Jim_NewIntObj(interp, (jim_wide)si. ## element )
+
+ JIMADD(PageSize, dwPageSize);
+ JIMADD(MinimumApplicationAddress, lpMinimumApplicationAddress);
+ JIMADD(MaximumApplicationAddress, lpMaximumApplicationAddress);
+ JIMADD(ActiveProcessorMask, dwActiveProcessorMask);
+ JIMADD(NumberOfProcessors, dwNumberOfProcessors);
+ JIMADD(ProcessorType, dwProcessorType);
+ JIMADD(AllocationGranularity, dwAllocationGranularity);
+ JIMADD(ProcessorLevel, wProcessorLevel);
+ JIMADD(ProcessorRevision, wProcessorRevision);
+#undef JIMADD
+
+ Jim_SetResult(interp, Jim_NewListObj(interp, a, n));
+ return JIM_OK;
+}
+
// Declared here because its not available without recent versions of the
// Platform SDK. mingw32 doesn't declare it all either.
typedef struct _PERFORMANCE_INFORMATION {
@@ -1022,7 +1073,7 @@ Win32_ReleasePrivLib(Jim_Interp *interp, void *clientData)
* package load function.
*/
-int
+DLLEXPORT int
Jim_OnLoad(Jim_Interp *interp)
{
HMODULE hLib;
@@ -1059,6 +1110,7 @@ Jim_OnLoad(Jim_Interp *interp)
CMD(GetVersion);
CMD(GetTickCount);
CMD(GetSystemTime);
+ CMD(GetSystemInfo);
CMD(GetModuleHandle);
CMD(LoadLibrary);
CMD(FreeLibrary);
diff --git a/jim-win32com.c b/jim-win32com.c
index c1ff2ca..fde762b 100644
--- a/jim-win32com.c
+++ b/jim-win32com.c
@@ -2,7 +2,7 @@
*
* Windows COM extension.
*
- * $Id: jim-win32com.c,v 1.17 2005/03/31 12:20:21 antirez Exp $
+ * $Id: jim-win32com.c,v 1.18 2007/01/31 00:49:05 patthoyts Exp $
*
* Example:
* load jim-win32com
@@ -30,6 +30,10 @@
#define JIM_EXTENSION
#include "jim.h"
+#ifndef JIM_INTEGER_SPACE
+#define JIM_INTEGER_SPACE 24
+#endif
+
#if _MSC_VER >= 1000
#pragma comment(lib, "shell32")
#pragma comment(lib, "user32")
@@ -39,6 +43,13 @@
#pragma comment(lib, "uuid")
#endif /* _MSC_VER >= 1000 */
+static int Ole32_Create(Jim_Interp *interp, int objc, Jim_Obj *const objv[]);
+static int Ole32_Foreach(Jim_Interp *interp, int objc, Jim_Obj *const objv[]);
+static int Ole32_Finalizer(Jim_Interp *interp, int objc, Jim_Obj *const objv[]);
+static int Ole32_GetObject(Jim_Interp *interp, int objc, Jim_Obj *const objv[]);
+static int Ole32_GetActiveObject(Jim_Interp *interp, int objc, Jim_Obj *const objv[]);
+static int Ole32_Invoke(Jim_Interp *interp, int objc, Jim_Obj *const objv[]);
+
/* ----------------------------------------------------------------------
* Debugging bits
*/
@@ -158,18 +169,22 @@ UnicodeFreeInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
objPtr->typePtr = NULL;
}
-// string rep is copied and internal dep is duplicated.
+/*
+ * string rep is copied and internal rep is duplicated.
+ */
void
UnicodeDupInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
int len = srcPtr->internalRep.binaryValue.len;
- JIM_TRACE("UnicodeDupInternalRep 0x%08x duped into 0x%08x\n", (DWORD)srcPtr, (DWORD)dupPtr);
+ JIM_TRACE("UnicodeDupInternalRep 0x%08x duped into 0x%08x\n",
+ (DWORD)srcPtr, (DWORD)dupPtr);
interp = interp;
dupPtr->internalRep.binaryValue.len = len;
- if (srcPtr->internalRep.binaryValue.data != NULL) {
- dupPtr->internalRep.binaryValue.data = Jim_Alloc(sizeof(WCHAR) * (len + 1));
- wcsncpy((LPWSTR)dupPtr->internalRep.binaryValue.data,
- (LPWSTR)srcPtr->internalRep.binaryValue.data, len);
+ if (srcPtr->internalRep.binaryValue.data != NULL) {
+ dupPtr->internalRep.binaryValue.data =
+ Jim_Alloc(sizeof(WCHAR) * (len + 1));
+ wcsncpy((LPWSTR)dupPtr->internalRep.binaryValue.data,
+ (LPWSTR)srcPtr->internalRep.binaryValue.data, len);
}
}
@@ -224,57 +239,226 @@ Jim_GetUnicode(Jim_Obj *objPtr, int *lenPtr)
if (objPtr->typePtr != &unicodeObjType) {
if (UnicodeSetFromAny(NULL, objPtr) != JIM_OK) {
JIM_ASSERT("Jim_GetUnicode cannot convert item to unicode rep");
- Jim_Panic("Jim_GetUnicode cannot convert item to unicode rep",
- objPtr->typePtr->name);
+ Jim_Panic(NULL, "Jim_GetUnicode cannot convert item to unicode rep",
+ objPtr->typePtr->name);
}
}
- if (lenPtr != NULL)
- *lenPtr = objPtr->internalRep.binaryValue.len;
+ if (lenPtr != NULL)
+ *lenPtr = objPtr->internalRep.binaryValue.len;
return (LPWSTR)objPtr->internalRep.binaryValue.data;
}
-/* ---------------------------------------------------------------------- */
+/* ----------------------------------------------------------------------
+ * Package interp associated data
+ */
+
+ typedef struct Ole32PackageData {
+ Jim_HashTable table;
+ jim_wide uid;
+} Ole32PackageData;
+
+static void Ole32PackageDataDelete(Jim_Interp *interp, void *data)
+{
+ Ole32PackageData *pkgPtr = (Ole32PackageData *)data;
+ Jim_FreeHashTable(&pkgPtr->table);
+ Jim_Free(data);
+}
+
+/* ----------------------------------------------------------------------
+ * Ole32 object hash table
+ */
+
+typedef struct Ole32ObjectData {
+ DWORD refcount;
+ LPDISPATCH pdispatch;
+ LPTYPEINFO ptypeinfo;
+} Ole32ObjectData;
+
+static unsigned int Ole32HashTableHash(const void *key)
+{
+ /*return Jim_DjbHashFunction(key, strlen(key));*/
+ unsigned int h = 5381;
+ size_t len = strlen(key);
+ while(len--)
+ h = (h + (h << 5)) ^ *((const char *)key)++;
+ return h;
+}
-#define Ole32_DispatchPtr(o) (LPDISPATCH)((o)->internalRep.twoPtrValue.ptr1)
-#define Ole32_TypeInfoPtr(o) (LPTYPEINFO)((o)->internalRep.twoPtrValue.ptr2)
+static const void *Ole32HashTableCopyKey(void *privdata, const void *key)
+{
+ int len = strlen(key);
+ char *copy = Jim_Alloc(len + 1);
+ JIM_NOTUSED(privdata);
+ memcpy(copy, key, len);
+ copy[len] = '\0';
+ return copy;
+}
+
+static int Ole32HashTableCompare(void *privdata, const void *key1, const void *key2)
+{
+ JIM_NOTUSED(privdata);
+ return strcmp(key1, key2) == 0;
+}
+
+static void Ole32HashTableDestroyKey(void *privdata, const void *key)
+{
+ JIM_NOTUSED(privdata);
+ Jim_Free((void*)key); /* ATTENTION: const cast */
+}
+
+static void Ole32HashTableDestroyValue(void *interp, void *val)
+{
+ Ole32ObjectData *entryPtr = (Ole32ObjectData *)val;
+ JIM_NOTUSED(interp);
+ entryPtr->pdispatch->lpVtbl->Release(entryPtr->pdispatch);
+ if (entryPtr->ptypeinfo != NULL)
+ entryPtr->ptypeinfo->lpVtbl->Release(entryPtr->ptypeinfo);
+ Jim_Free((void*)entryPtr);
+}
+
+static Jim_HashTableType Ole32HashTableType = {
+ Ole32HashTableHash, /* hash function */
+ Ole32HashTableCopyKey, /* key dup */
+ NULL, /* val dup */
+ Ole32HashTableCompare, /* key compare */
+ Ole32HashTableDestroyKey, /* key destructor */
+ Ole32HashTableDestroyValue /* val destructor */
+};
+
+/* ---------------------------------------------------------------------- */
static void Ole32FreeInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void Ole32DupInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
+static int Ole32SetFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
Jim_Obj *Jim_NewOle32Obj(Jim_Interp *interp, LPDISPATCH pdispatch);
+#define Ole32_DispatchPtr(o) (((Ole32ObjectData *)((o)->internalRep.ptr))->pdispatch)
+#define Ole32_TypeInfoPtr(o) (((Ole32ObjectData *)((o)->internalRep.ptr))->ptypeinfo)
+
Jim_ObjType ole32ObjType = {
"ole32",
Ole32FreeInternalRep,
Ole32DupInternalRep,
- NULL, /*UpdateUnicodeStringProc*/
+ NULL,
JIM_TYPE_REFERENCES,
};
void
Ole32FreeInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
- IDispatch *p = Ole32_DispatchPtr(objPtr);
- ITypeInfo *t = Ole32_TypeInfoPtr(objPtr);
- JIM_NOTUSED(interp);
-
- JIM_TRACE("free ole32 object 0x%08x\n", (unsigned long)p);
- p->lpVtbl->Release(p), p = NULL;
- if (t != NULL)
- t->lpVtbl->Release(t), t = NULL;
- objPtr->typePtr = NULL;
+ Ole32ObjectData *entryPtr;
+ entryPtr = objPtr->internalRep.ptr;
+ --entryPtr->refcount;
+ if (entryPtr->refcount == 0) {
+ //Ole32PackageData *pkgPtr = Jim_GetAssocData(interp, "ole32:package");
+ //Jim_DeleteHashEntry(&pkgPtr->table, objPtr->bytes);
+ JIM_TRACE("free ole32 object 0x%08x\n", entryPtr->pdispatch);
+ }
+ objPtr->internalRep.ptr = NULL;
}
void
Ole32DupInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
- IDispatch *p = Ole32_DispatchPtr(srcPtr);
- JIM_NOTUSED(interp);
+ Ole32ObjectData *entryPtr;
+ JIM_NOTUSED(interp);
+
+ entryPtr = srcPtr->internalRep.ptr;
+ ++entryPtr->refcount;
+ dupPtr->internalRep.ptr = entryPtr;
+ JIM_TRACE("dup ole32 object 0x%08x from 0x%08x to 0x%08x\n", entryPtr->pdispatch, srcPtr, dupPtr);
+}
+
+int
+Ole32SetFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
+{
+ Ole32PackageData *pkgPtr;
+ Ole32ObjectData *entryPtr;
+
+ JIM_TRACE("Ole32SetFromAny from 0x%08x\n", objPtr);
+ if (objPtr->typePtr != &ole32ObjType) {
+ pkgPtr = Jim_GetAssocData(interp, "ole32:package");
+
+ Jim_GetString(objPtr, NULL);
+ entryPtr = (Ole32ObjectData *)Jim_FindHashEntry(&pkgPtr->table, objPtr->bytes);
+ if (entryPtr == NULL) {
+ Jim_SetResultString(interp, "not a ole32 object", -1);
+ return JIM_ERR;
+ }
+
+ Jim_FreeIntRep(interp, objPtr);
+ objPtr->internalRep.ptr = entryPtr;
+ ++entryPtr->refcount;
+ objPtr->typePtr = &ole32ObjType;
+ }
+ return JIM_OK;
+}
+
+static int
+Ole32_Finalizer(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
+{
+ //objv[1] == referencesobj.
+ JIM_TRACE("Ole32_Finalizer for %s\n", Jim_GetString(objv[1], NULL));
+ Jim_DeleteCommand(interp, Jim_GetString(objv[1], NULL));
+ return JIM_OK;
+}
+
+/*
+ * Jim_NewOle32Obj --
+ *
+ * This is the only way to create Ole32 objects in Jim. These
+ * hold a reference to the IDispatch interface of the COM
+ * object. We also attempt to acquire the typelibrary information
+ * if this is available. Objects with typeinfo know how many
+ * arguments are required for a method/property call and can
+ * manage without programmer hints.
+ *
+ * The string rep never changes and when this object is destroyed
+ * we release our COM references.
+ */
+Jim_Obj *
+Jim_NewOle32Obj(Jim_Interp *interp, LPDISPATCH pdispatch)
+{
+ unsigned int n = 0;
+ jim_wide id;
+ char *name;
+ Jim_Obj *objPtr, *refPtr;
+ Ole32PackageData *pkgPtr;
+ Ole32ObjectData *entryPtr;
+
+ pkgPtr = Jim_GetAssocData(interp, "ole32:package");
+ id = pkgPtr->uid++;
+ name = Jim_Alloc(23);
+ sprintf(name, "ole32:%" JIM_WIDE_MODIFIER, id);
+ entryPtr = (Ole32ObjectData *)Jim_Alloc(sizeof(Ole32ObjectData));
+ entryPtr->pdispatch = pdispatch;
+ entryPtr->ptypeinfo = NULL;
+ entryPtr->refcount = 1;
+ pdispatch->lpVtbl->AddRef(pdispatch);
+
+ pdispatch->lpVtbl->GetTypeInfoCount(pdispatch, &n);
+ if (n != 0)
+ pdispatch->lpVtbl->GetTypeInfo(pdispatch, 0, LOCALE_SYSTEM_DEFAULT,
+ &entryPtr->ptypeinfo);
+
+ //Jim_AddHashEntry(&pkgPtr->table, name, entryPtr);
+ objPtr = Jim_NewStringObj(interp, name, -1);
+ objPtr->internalRep.ptr = entryPtr;
+ objPtr->typePtr = &ole32ObjType;
+
+ refPtr = Jim_NewReference(interp, objPtr, Jim_NewStringObj(interp, "ole32", -1),
+ Jim_NewStringObj(interp, "ole32.finalizer", -1));
+ if (Jim_CreateCommand(interp, Jim_GetString(refPtr, NULL), Ole32_Invoke,
+ objPtr->internalRep.ptr, NULL /*Ole32CmdDeleteProc*/) != JIM_OK) {
+ JIM_ASSERT(FALSE && "Its all going wrong");
+ }
- JIM_TRACE("dup ole32 object 0x%08x from 0x%08x to 0x%08x\n", p, srcPtr, dupPtr);
- Ole32_DispatchPtr(dupPtr) = p;
- p->lpVtbl->AddRef(p);
+ JIM_TRACE("created ole32 object 0x%08x in Jim obj 0x%08x\n", pdispatch, objPtr);
+ return refPtr;
}
+/* ---------------------------------------------------------------------- */
+
static DISPPARAMS*
Ole32_GetDispParams(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
{
@@ -408,17 +592,18 @@ Ole32_Invoke(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
DISPID dispid;
LPDISPATCH pdisp;
Jim_Obj *resultObj = NULL;
+ Ole32ObjectData *ole32Ptr = (Ole32ObjectData*)Jim_CmdPrivData(interp);
int optind, argc = 1;
WORD mode = DISPATCH_PROPERTYGET | DISPATCH_METHOD;
static const char *options[] = {"-get", "-put", "-putref", "-call", NULL };
enum { OPT_GET, OPT_PUT, OPT_PUTREF, OPT_CALL };
- if (objc < 3) {
- Jim_WrongNumArgs(interp, 1, objv, "?options? object method|property ?args ...?");
+ if (objc < 2) {
+ Jim_WrongNumArgs(interp, 1, objv, "?options? method|property ?args ...?");
return JIM_ERR;
}
- if (Jim_GetIndexFromObj(interp, objv[1], options, "", 0, &optind) == JIM_OK) {
+ if (Jim_GetEnum(interp, objv[1], options, &optind, NULL, 0) == JIM_OK) {
argc++;
switch (optind) {
case OPT_GET: mode = DISPATCH_PROPERTYGET; break;
@@ -428,13 +613,17 @@ Ole32_Invoke(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
}
}
- if (objv[argc]->typePtr != &ole32ObjType) {
- Jim_SetResultString(interp, "first argument must be a ole32 created object", -1);
- return JIM_ERR;
+ /*
+ if (objv[argc]->typePtr != &ole32ObjType) {
+ if (Ole32SetFromAny(interp, objv[argc]) != JIM_OK) {
+ Jim_SetResultString(interp, "first argument must be a ole32 created object", -1);
+ return JIM_ERR;
+ }
}
+ */
- pdisp = Ole32_DispatchPtr(objv[argc]);
- name = Jim_GetUnicode(objv[argc+1], NULL);
+ pdisp = ole32Ptr->pdispatch; // Ole32_DispatchPtr(objv[argc]);
+ name = Jim_GetUnicode(objv[argc], NULL);
hr = pdisp->lpVtbl->GetIDsOfNames(pdisp, &IID_NULL, &name, 1,
LOCALE_SYSTEM_DEFAULT, &dispid);
@@ -445,7 +634,7 @@ Ole32_Invoke(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
UINT uierr;
VariantInit(&v);
- dp = Ole32_GetDispParams(interp, objc-(argc+2), objv+argc+2);
+ dp = Ole32_GetDispParams(interp, objc-(argc+1), objv+argc+1);
if (mode & DISPATCH_PROPERTYPUT || mode & DISPATCH_PROPERTYPUTREF) {
static DISPID putid = DISPID_PROPERTYPUT;
@@ -468,39 +657,14 @@ Ole32_Invoke(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
return SUCCEEDED(hr) ? JIM_OK : JIM_ERR;
}
-/*
- * Jim_NewOle32Obj --
- *
- * This is the only way to create Ole32 objects in Jim. These hold a reference to the
- * IDispatch interface of the COM object. We also attempt to acquire the typelibrary
- * information if this is available. Objects with typeinfo know how many arguments are
- * required for a method/property call and can manage without programmer hints.
- *
- * The string rep never changes and when this object is destroyed we release our COM
- * references.
- */
-Jim_Obj *
-Jim_NewOle32Obj(Jim_Interp *interp, LPDISPATCH pdispatch)
-{
- unsigned int n = 0;
- Jim_Obj *objPtr = Jim_NewObj(interp);
-
- objPtr->bytes = Jim_Alloc(23);
- sprintf(objPtr->bytes, "ole32:%08lx", (unsigned long)pdispatch);
- objPtr->length = strlen(objPtr->bytes);
- Ole32_DispatchPtr(objPtr) = pdispatch;
- Ole32_TypeInfoPtr(objPtr) = NULL;
- pdispatch->lpVtbl->AddRef(pdispatch);
-
- pdispatch->lpVtbl->GetTypeInfoCount(pdispatch, &n);
- if (n != 0)
- pdispatch->lpVtbl->GetTypeInfo(pdispatch, 0, LOCALE_SYSTEM_DEFAULT,
- (LPTYPEINFO*)&objPtr->internalRep.twoPtrValue.ptr2);
-
- objPtr->typePtr = &ole32ObjType;
+/* ---------------------------------------------------------------------- */
- JIM_TRACE("created ole32 object 0x%08x in Jim obj 0x%08x\n", pdispatch, objPtr);
- return objPtr;
+static void
+Ole32CmdDeleteProc(void *privData)
+{
+ Ole32ObjectData *ole32Ptr = (Ole32ObjectData *)privData;
+ ole32Ptr->pdispatch->lpVtbl->Release(ole32Ptr->pdispatch);
+ Jim_Free(privData);
}
/* ---------------------------------------------------------------------- */
@@ -519,7 +683,8 @@ Ole32_Create(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
hr = CLSIDFromProgID(Jim_GetUnicode(objv[1], NULL), &clsid);
if (SUCCEEDED(hr))
- hr = CoCreateInstance(&clsid, NULL, CLSCTX_SERVER, &IID_IDispatch, (LPVOID*)&pdisp);
+ hr = CoCreateInstance(&clsid, NULL, CLSCTX_SERVER,
+ &IID_IDispatch, (LPVOID*)&pdisp);
if (SUCCEEDED(hr)) {
Jim_SetResult(interp, Jim_NewOle32Obj(interp, pdisp));
pdisp->lpVtbl->Release(pdisp);
@@ -529,6 +694,58 @@ Ole32_Create(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
return SUCCEEDED(hr) ? JIM_OK : JIM_ERR;
}
+static int
+Ole32_GetActiveObject(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
+{
+ HRESULT hr = S_OK;
+ LPUNKNOWN punk = NULL;
+ CLSID clsid;
+
+ if (objc != 2) {
+ Jim_WrongNumArgs(interp, 1, objv, "progid");
+ return JIM_ERR;
+ }
+
+ hr = CLSIDFromProgID(Jim_GetUnicode(objv[1], NULL), &clsid);
+ if (SUCCEEDED(hr))
+ hr = GetActiveObject(&clsid, NULL, &punk);
+ if (SUCCEEDED(hr)) {
+ LPDISPATCH pdisp;
+ hr = punk->lpVtbl->QueryInterface(punk, &IID_IDispatch, (LPVOID*)&pdisp);
+ if (SUCCEEDED(hr)) {
+ Jim_SetResult(interp, Jim_NewOle32Obj(interp, pdisp));
+ pdisp->lpVtbl->Release(pdisp);
+ }
+ punk->lpVtbl->Release(punk);
+ }
+ if (FAILED(hr))
+ Jim_SetResult(interp, Win32ErrorObj(interp, "GetActiveObject", hr));
+ return SUCCEEDED(hr) ? JIM_OK : JIM_ERR;
+}
+
+static int
+Ole32_GetObject(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
+{
+ HRESULT hr = S_OK;
+ LPDISPATCH pdisp = NULL;
+ LPCOLESTR name;
+
+ if (objc != 2) {
+ Jim_WrongNumArgs(interp, 1, objv, "progid");
+ return JIM_ERR;
+ }
+
+ name = Jim_GetUnicode(objv[1], NULL);
+ hr = CoGetObject(name, NULL, &IID_IDispatch, (LPVOID*)&pdisp);
+ if (SUCCEEDED(hr)) {
+ Jim_SetResult(interp, Jim_NewOle32Obj(interp, pdisp));
+ pdisp->lpVtbl->Release(pdisp);
+ }
+ if (FAILED(hr))
+ Jim_SetResult(interp, Win32ErrorObj(interp, "GetObject", hr));
+ return SUCCEEDED(hr) ? JIM_OK : JIM_ERR;
+}
+
/* ole32.foreach varname $object body */
static int
Ole32_Foreach(Jim_Interp *interp, int objc, Jim_Obj *const objv[])
@@ -590,23 +807,51 @@ break_for:
}
/* ---------------------------------------------------------------------- */
+static Jim_ObjType origCommandObjType;
+static Jim_ObjType ole32CommandObjType;
+
+void Ole32CommandFreeIntRep(Jim_Interp *interp, Jim_Obj *objPtr)
+{
+ if (origCommandObjType.freeIntRepProc != NULL)
+ origCommandObjType.freeIntRepProc(interp, objPtr);
+}
-__declspec(dllexport) int
+
+DLLEXPORT int
Jim_OnLoad(Jim_Interp *interp)
{
HRESULT hr;
+ Ole32PackageData *pkgPtr;
+ //Jim_ObjType *commandObjType;
+
Jim_InitExtension(interp);
if (Jim_PackageProvide(interp, "win32com", "1.0", JIM_ERRMSG) != JIM_OK)
return JIM_ERR;
+
hr = CoInitialize(0);
if (FAILED(hr)) {
Jim_SetResult(interp,
Win32ErrorObj(interp, "CoInitialize", (DWORD)hr));
return JIM_ERR;
}
- Jim_CreateCommand(interp, "ole32.create", Ole32_Create, NULL, NULL);
- Jim_CreateCommand(interp, "ole32.invoke", Ole32_Invoke, NULL, NULL);
- Jim_CreateCommand(interp, "ole32.foreach", Ole32_Foreach, NULL, NULL);
+
+ pkgPtr = (Ole32PackageData *)Jim_Alloc(sizeof(Ole32PackageData));
+ pkgPtr->uid = 0;
+ Jim_InitHashTable(&pkgPtr->table, &Ole32HashTableType, interp);
+ Jim_SetAssocData(interp, "ole32:package", Ole32PackageDataDelete, pkgPtr);
+
+ /*
+ commandObjType = Jim_GetObjType(interp, "command");
+ memcpy(&origCommandObjType, commandObjType, sizeof(Jim_ObjType));
+ memcpy(&ole32CommandObjType, commandObjType, sizeof(Jim_ObjType));
+ ole32CommandObjType.freeIntRepProc = Ole32CommandFreeIntRep;
+ memcpy(commandObjType, &ole32CommandObjType, sizeof(Jim_ObjType));
+ */
+
+ Jim_CreateCommand(interp, "ole32.create", Ole32_Create, NULL, NULL);
+ Jim_CreateCommand(interp, "ole32.invoke", Ole32_Invoke, NULL, NULL);
+ Jim_CreateCommand(interp, "ole32.foreach", Ole32_Foreach, NULL, NULL);
+ Jim_CreateCommand(interp, "ole32.finalizer", Ole32_Finalizer, NULL, NULL);
return JIM_OK;
}
diff --git a/jim.c b/jim.c
index be987c9..8572a64 100644
--- a/jim.c
+++ b/jim.c
@@ -2,7 +2,7 @@
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
* Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
*
- * $Id: jim.c,v 1.170 2006/11/06 21:48:57 antirez Exp $
+ * $Id: jim.c,v 1.171 2007/01/31 00:49:05 patthoyts Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -455,7 +455,7 @@ static jim_wide JimPowWide(jim_wide b, jim_wide e)
void Jim_Panic(Jim_Interp *interp, const char *fmt, ...)
{
va_list ap;
- FILE *fp = interp ? interp->stderr : stderr;
+ FILE *fp = interp ? interp->stderr_ : stderr;
va_start(ap, fmt);
fprintf(fp, JIM_NL "JIM INTERPRETER PANIC: ");
@@ -2171,6 +2171,13 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
c = (char) wideValue;
Jim_AppendString(interp, resObjPtr, &c, 1);
break;
+ case 'd':
+ if (Jim_GetWide(interp, objv[0], &wideValue) == JIM_ERR) {
+ Jim_FreeNewObj(interp, resObjPtr);
+ return NULL;
+ }
+ Jim_AppendObj(interp, resObjPtr, objv[0]);
+ break;
case '%':
Jim_AppendString(interp, resObjPtr, "%" , 1);
break;
@@ -3892,7 +3899,7 @@ int Jim_Collect(Jim_Interp *interp)
Jim_AddHashEntry(&marks,
&objPtr->internalRep.refValue.id, NULL);
#ifdef JIM_DEBUG_GC
- fprintf(interp->stdout,
+ fprintf(interp->stdout_,
"MARK (reference): %d refcount: %d" JIM_NL,
(int) objPtr->internalRep.refValue.id,
objPtr->refCount);
@@ -3931,7 +3938,7 @@ int Jim_Collect(Jim_Interp *interp)
* was found. Mark it. */
Jim_AddHashEntry(&marks, &id, NULL);
#ifdef JIM_DEBUG_GC
- fprintf(interp->stdout,"MARK: %d" JIM_NL, (int)id);
+ fprintf(interp->stdout_,"MARK: %d" JIM_NL, (int)id);
#endif
p += JIM_REFERENCE_SPACE;
}
@@ -3951,7 +3958,7 @@ int Jim_Collect(Jim_Interp *interp)
* this reference. */
if (Jim_FindHashEntry(&marks, refId) == NULL) {
#ifdef JIM_DEBUG_GC
- fprintf(interp->stdout,"COLLECTING %d" JIM_NL, (int)*refId);
+ fprintf(interp->stdout_,"COLLECTING %d" JIM_NL, (int)*refId);
#endif
collected++;
/* Drop the reference, but call the
@@ -4039,9 +4046,9 @@ Jim_Interp *Jim_CreateInterp(void)
i->freeFramesList = NULL;
i->prngState = NULL;
i->evalRetcodeLevel = -1;
- i->stdin = stdin;
- i->stdout = stdout;
- i->stderr = stderr;
+ i->stdin_ = stdin;
+ i->stdout_ = stdout;
+ i->stderr_ = stderr;
/* Note that we can create objects only after the
* interpreter liveList and freeList pointers are
@@ -4110,17 +4117,17 @@ void Jim_FreeInterp(Jim_Interp *i)
if (i->liveList != NULL) {
Jim_Obj *objPtr = i->liveList;
- fprintf(i->stdout,JIM_NL "-------------------------------------" JIM_NL);
- fprintf(i->stdout,"Objects still in the free list:" JIM_NL);
+ fprintf(i->stdout_,JIM_NL "-------------------------------------" JIM_NL);
+ fprintf(i->stdout_,"Objects still in the free list:" JIM_NL);
while(objPtr) {
const char *type = objPtr->typePtr ?
objPtr->typePtr->name : "";
- fprintf(i->stdout,"%p \"%-10s\": '%.20s' (refCount: %d)" JIM_NL,
+ fprintf(i->stdout_,"%p \"%-10s\": '%.20s' (refCount: %d)" JIM_NL,
objPtr, type,
objPtr->bytes ? objPtr->bytes
: "(null)", objPtr->refCount);
if (objPtr->typePtr == &sourceObjType) {
- fprintf(i->stdout, "FILE %s LINE %d" JIM_NL,
+ fprintf(i->stdout_, "FILE %s LINE %d" JIM_NL,
objPtr->internalRep.sourceValue.fileName,
objPtr->internalRep.sourceValue.lineNumber);
}
@@ -4314,20 +4321,20 @@ int Jim_GetExitCode(Jim_Interp *interp) {
FILE *Jim_SetStdin(Jim_Interp *interp, FILE *fp)
{
- if (fp != NULL) interp->stdin = fp;
- return interp->stdin;
+ if (fp != NULL) interp->stdin_ = fp;
+ return interp->stdin_;
}
FILE *Jim_SetStdout(Jim_Interp *interp, FILE *fp)
{
- if (fp != NULL) interp->stdout = fp;
- return interp->stdout;
+ if (fp != NULL) interp->stdout_ = fp;
+ return interp->stdout_;
}
FILE *Jim_SetStderr(Jim_Interp *interp, FILE *fp)
{
- if (fp != NULL) interp->stderr = fp;
- return interp->stderr;
+ if (fp != NULL) interp->stderr_ = fp;
+ return interp->stderr_;
}
/* -----------------------------------------------------------------------------
@@ -7139,7 +7146,7 @@ JimScanAString(Jim_Interp *interp, const char *sdescr, const char *str)
/* Handle range definitions */
int i;
for (i=sdescr[0]; i <= sdescr[2]; ++i)
- JimSetBit(charset, i);
+ JimSetBit(charset, (char)i);
sdescr += 3;
} else {
/* Handle verbatim character definitions */
@@ -7525,11 +7532,13 @@ int Jim_LoadLibrary(Jim_Interp *interp, const char *pathName)
sprintf(buf, "%s%s", prefix, pathName);
else
sprintf(buf, "%s/%s", prefix, pathName);
+ printf("opening '%s'\n", buf);
fp = fopen(buf, "r");
if (fp == NULL)
continue;
fclose(fp);
handle = dlopen(buf, RTLD_LAZY);
+ printf("got handle %p\n", handle);
}
if (handle == NULL) {
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
@@ -8450,7 +8459,7 @@ int Jim_EvalObjBackground(Jim_Interp *interp, Jim_Obj *scriptObjPtr)
Jim_IncrRefCount(objv[1]);
if (Jim_EvalObjVector(interp, 2, objv) != JIM_OK) {
/* Report the error to stderr. */
- fprintf(interp->stderr, "Background error:" JIM_NL);
+ fprintf(interp->stderr_, "Background error:" JIM_NL);
Jim_PrintErrorMessage(interp);
}
Jim_DecrRefCount(interp, objv[0]);
@@ -8983,8 +8992,8 @@ static int Jim_PutsCoreCommand(Jim_Interp *interp, int argc,
}
}
str = Jim_GetString(argv[1], &len);
- fwrite(str, 1, len, interp->stdout);
- if (!nonewline) fprintf(interp->stdout, JIM_NL);
+ fwrite(str, 1, len, interp->stdout_);
+ if (!nonewline) fprintf(interp->stdout_, JIM_NL);
return JIM_OK;
}
@@ -11716,9 +11725,9 @@ void Jim_PrintErrorMessage(Jim_Interp *interp)
{
int len, i;
- fprintf(interp->stderr, "Runtime error, file \"%s\", line %d:" JIM_NL,
+ fprintf(interp->stderr_, "Runtime error, file \"%s\", line %d:" JIM_NL,
interp->errorFileName, interp->errorLine);
- fprintf(interp->stderr, " %s" JIM_NL,
+ fprintf(interp->stderr_, " %s" JIM_NL,
Jim_GetString(interp->result, NULL));
Jim_ListLength(interp, interp->stackTrace, &len);
for (i = 0; i < len; i+= 3) {
@@ -11733,7 +11742,7 @@ void Jim_PrintErrorMessage(Jim_Interp *interp)
Jim_ListIndex(interp, interp->stackTrace, i+2, &objPtr,
JIM_NONE);
line = Jim_GetString(objPtr, NULL);
- fprintf(interp->stderr,
+ fprintf(interp->stderr_,
"In procedure '%s' called at file \"%s\", line %s" JIM_NL,
proc, file, line);
}
@@ -11744,11 +11753,11 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
int retcode = JIM_OK;
Jim_Obj *scriptObjPtr;
- fprintf(interp->stdout, "Welcome to Jim version %d.%d, "
+ fprintf(interp->stdout_, "Welcome to Jim version %d.%d, "
"Copyright (c) 2005 Salvatore Sanfilippo" JIM_NL,
JIM_VERSION / 100, JIM_VERSION % 100);
- fprintf(interp->stdout,
- "CVS ID: $Id: jim.c,v 1.170 2006/11/06 21:48:57 antirez Exp $"
+ fprintf(interp->stdout_,
+ "CVS ID: $Id: jim.c,v 1.171 2007/01/31 00:49:05 patthoyts Exp $"
JIM_NL);
Jim_SetVariableStrWithStr(interp, "jim_interactive", "1");
while (1) {
@@ -11761,12 +11770,12 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
if (retcode != 0) {
if (retcode >= 2 && retcode <= 6)
- fprintf(interp->stdout, "[%s] . ", retcodestr[retcode]);
+ fprintf(interp->stdout_, "[%s] . ", retcodestr[retcode]);
else
- fprintf(interp->stdout, "[%d] . ", retcode);
+ fprintf(interp->stdout_, "[%d] . ", retcode);
} else
- fprintf(interp->stdout, ". ");
- fflush(interp->stdout);
+ fprintf(interp->stdout_, ". ");
+ fflush(interp->stdout_);
scriptObjPtr = Jim_NewStringObj(interp, "", 0);
Jim_IncrRefCount(scriptObjPtr);
while(1) {
@@ -11774,7 +11783,7 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
char state;
int len;
- if (fgets(buf, 1024, interp->stdin) == NULL) {
+ if (fgets(buf, 1024, interp->stdin_) == NULL) {
Jim_DecrRefCount(interp, scriptObjPtr);
goto out;
}
@@ -11782,7 +11791,7 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
str = Jim_GetString(scriptObjPtr, &len);
if (Jim_ScriptIsComplete(str, len, &state))
break;
- fprintf(interp->stdout, "%c> ", state);
+ fprintf(interp->stdout_, "%c> ", state);
fflush(stdout);
}
retcode = Jim_EvalObj(interp, scriptObjPtr);
@@ -11794,8 +11803,8 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
exit(Jim_GetExitCode(interp));
} else {
if (reslen) {
- fwrite(result, 1, reslen, interp->stdout);
- fprintf(interp->stdout, JIM_NL);
+ fwrite(result, 1, reslen, interp->stdout_);
+ fprintf(interp->stdout_, JIM_NL);
}
}
}
diff --git a/jim.h b/jim.h
index 01d8fc8..98850a8 100644
--- a/jim.h
+++ b/jim.h
@@ -2,7 +2,7 @@
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
* Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
*
- * $Id: jim.h,v 1.76 2006/11/06 20:29:15 antirez Exp $
+ * $Id: jim.h,v 1.77 2007/01/31 00:49:05 patthoyts Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -148,6 +148,14 @@ extern "C" {
#define JIM_NL "\n"
#endif
+#if defined(__WIN32__) || defined(_WIN32)
+#define DLLEXPORT __declspec(dllexport)
+#define DLLIMPORT __declspec(dllimport)
+#else
+#define DLLEXPORT
+#define DLLIMPORT
+#endif
+
/* -----------------------------------------------------------------------------
* Stack
* ---------------------------------------------------------------------------*/
@@ -491,9 +499,9 @@ typedef struct Jim_Interp {
struct Jim_HashTable assocData; /* per-interp storage for use by packages */
Jim_PrngState *prngState; /* per interpreter Random Number Gen. state. */
struct Jim_HashTable packages; /* Provided packages hash table */
- FILE *stdin; /* input file pointer, 'stdin' by default */
- FILE *stdout; /* output file pointer, 'stdout' by default */
- FILE *stderr; /* errors file pointer, 'stderr' by default */
+ FILE *stdin_; /* input file pointer, 'stdin' by default */
+ FILE *stdout_; /* output file pointer, 'stdout' by default */
+ FILE *stderr_; /* errors file pointer, 'stderr' by default */
} Jim_Interp;
/* Currently provided as macro that performs the increment.
@@ -554,7 +562,11 @@ typedef struct Jim_Reference {
# endif
#else
# define JIM_API(x) x
-# define JIM_STATIC static
+# if defined(BUILD_Jim)
+# define JIM_STATIC DLLEXPORT
+# else
+# define JIM_STATIC static
+# endif
#endif /* __JIM_CORE__ */
/* Memory allocation */