Update of /cvsroot/simspark/simspark/spark/zeitgeist/scriptserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv7790/spark/zeitgeist/scriptserver Modified Files: gcvalue.cpp gcvalue.h rubywrapper.cpp rubywrapper.h scriptserver.cpp scriptserver.h scriptserver_c.cpp Log Message: Merged WIN32 branch back to main trunk (access previous version with tag pre_merge_WIN32) Index: scriptserver.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/scriptserver/scriptserver.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** scriptserver.cpp 16 May 2006 10:17:32 -0000 1.2 --- scriptserver.cpp 15 Mar 2007 07:26:31 -0000 1.3 *************** *** 23,27 **** --- 23,29 ---- #include <boost/scoped_array.hpp> #include <sstream> + #include <salt/fileclasses.h> #include "scriptserver.h" + #include "rubywrapper.h" #include <zeitgeist/corecontext.h> #include <zeitgeist/core.h> *************** *** 30,33 **** --- 32,49 ---- #include <sys/stat.h> + #undef PREFIX + #undef PACKAGE_NAME + + #ifdef HAVE_CONFIG_H + /* The include search path includes config.h of ruby as well. My system shows a strange behavior + when resolving the search paths: + using - include <config.h> - *before* the rubywrapper includes the correct file (our config.h) + using - include <config.h> - *after* the rubywrapper includes the ruby - config.h + using the same line before *and* after the rubywrapper includes the correct file before the rubywrapper, + and the wrong one after.... :-( + */ + #include "../config.h" + #endif + using namespace boost; using namespace std; *************** *** 118,122 **** Class::TCmdProc cmd = ! gMyPrivateContext->GetObject()->GetClass()->GetCmdProc (STR2CSTR(functionName)); --- 134,138 ---- Class::TCmdProc cmd = ! gMyPrivateContext->GetSelection()->GetClass()->GetCmdProc (STR2CSTR(functionName)); *************** *** 125,129 **** if (cmd != 0) { ! out = cmd(static_cast<Object*>(gMyPrivateContext->GetObject().get()), in); } else { --- 141,145 ---- if (cmd != 0) { ! out = cmd(static_cast<Object*>(gMyPrivateContext->GetSelection().get()), in); } else { *************** *** 243,247 **** rb_define_global_function("dirs", RUBY_METHOD_FUNC(dirs), 0); ! mRelPathPrefix = "../../"; } --- 259,263 ---- rb_define_global_function("dirs", RUBY_METHOD_FUNC(dirs), 0); ! mRelPathPrefix = string("..") + salt::PathSeparator + ".." + salt::PathSeparator; } *************** *** 264,274 **** return false; } ! boost::scoped_array<char> buffer(new char[file->Size() + 1]); file->Read(buffer.get(), file->Size()); buffer[file->Size()] = 0; bool ok = Eval(buffer.get()); UpdateCachedAllNodes(); return ok; } --- 280,293 ---- return false; } ! std::cerr << "Running the script\n"; boost::scoped_array<char> buffer(new char[file->Size() + 1]); file->Read(buffer.get(), file->Size()); buffer[file->Size()] = 0; + std::cerr << "Created buffer\n"; bool ok = Eval(buffer.get()); + std::cerr << "Eval'd buffer\n"; UpdateCachedAllNodes(); + std::cerr << "Updated cached nodes\n"; return ok; } *************** *** 471,476 **** { // run the init script in the sourceDir ! string sourcePath = sourceDir + "/" + name; GetLog()->Debug() << "(ScriptServer) Running " << sourcePath << "... "; shared_ptr<salt::StdFile> file(new(salt::StdFile)); --- 490,496 ---- { // run the init script in the sourceDir ! string sourcePath = sourceDir + salt::PathSeparator + name; GetLog()->Debug() << "(ScriptServer) Running " << sourcePath << "... "; + std::cerr << "(ScriptServer) Running " << sourcePath << "... "; shared_ptr<salt::StdFile> file(new(salt::StdFile)); *************** *** 478,485 **** { GetLog()->Debug() << "failed (script not found)" << endl; return eNotFound; } else if (! Run(file)) { ! GetLog()->Debug() << "failed (error in script" << endl; return eError; } else --- 498,507 ---- { GetLog()->Debug() << "failed (script not found)" << endl; + std::cerr << "failed (script not found)" << endl; return eNotFound; } else if (! Run(file)) { ! GetLog()->Debug() << "failed (error in script)" << endl; ! std::cerr << "failed (error in script)" << endl; return eError; } else *************** *** 494,498 **** } ! string destPath = destDir + "/" + name; GetLog()->Normal() << "Copying " << sourcePath --- 516,520 ---- } ! string destPath = destDir + salt::PathSeparator + name; GetLog()->Normal() << "Copying " << sourcePath *************** *** 515,519 **** } ! char* home = getenv("HOME"); if (!home) { --- 537,548 ---- } ! const char* envName = ! #ifdef WIN32 ! "USERPROFILE"; ! #else ! "HOME"; ! #endif ! ! char* home = getenv(envName); if (!home) { *************** *** 522,527 **** } ! dotDir = string(home) + "/" + mDotName; ! return true; } --- 551,555 ---- } ! dotDir = string(home) + salt::PathSeparator + mDotName; return true; } *************** *** 531,535 **** --- 559,567 ---- { char cwd[PATH_MAX+1]; + #if WIN32 + if (GetCurrentDirectory(PATH_MAX, cwd) == 0) + #else if (getcwd(cwd,sizeof(cwd)) == NULL) + #endif { GetLog()->Error() *************** *** 538,542 **** --- 570,578 ---- } + #if WIN32 + if (! SetCurrentDirectory(dotDir.c_str())) + #else if (chdir(dotDir.c_str()) == 0) + #endif { // dot dir exists; change back to original directory *************** *** 546,550 **** --- 582,590 ---- // dot dir is not existent, try to create it + #if WIN32 + if (! CreateDirectory(dotDir.c_str(), 0)) + #else if (mkdir(dotDir.c_str(),0777) != 0) + #endif { GetLog()->Error() << "(ScriptServer) ERROR: Cannot create directory '" *************** *** 569,580 **** CreateDotDir(dotDir); // some macro magic (not at all) string pkgdatadir = PREFIX "/share/" PACKAGE_NAME; ! //std::cout << "dotDir = " << dotDir << std::endl; ! //std::cout << "pkgdatadir = " << pkgdatadir << std::endl; ! //std::cout << "filename = " << fileName << std::endl; ! ERunScriptErrorType result; if (validDotDir) --- 609,624 ---- CreateDotDir(dotDir); + #ifdef WIN32 + string pkgdatadir = ".\\"; + #else // some macro magic (not at all) string pkgdatadir = PREFIX "/share/" PACKAGE_NAME; ! std::cerr << "dotDir = " << dotDir << "::"; ! std::cerr << "pkgdatadir = " << pkgdatadir << "::"; ! std::cerr << "filename = " << fileName << '\n'; ! #endif ! ERunScriptErrorType result = eNotFound; if (validDotDir) *************** *** 586,613 **** { GetLog()->Debug() << "(ScriptServer) : Ran init script '" ! << dotDir << "/" << fileName << "'\n"; return true; } ! if (result == eNotFound) { GetLog()->Debug() << "(ScriptServer) : Did not find init script '" ! << dotDir << "/" << fileName << "'\n"; } else if (result == eError) { GetLog()->Error() << "(ScriptServer) ERROR: Found error in init script '" ! << dotDir << "/" << fileName << "'\n"; return false; } - ! // result = RunInitScriptInternal(pkgdatadir, fileName, validDotDir, dotDir); ! if (result == eOK) { GetLog()->Debug() << "(ScriptServer) : Ran init script '" ! << pkgdatadir << "/" << fileName << "'\n"; return true; } --- 630,665 ---- { GetLog()->Debug() << "(ScriptServer) : Ran init script '" ! << dotDir << salt::PathSeparator << fileName << "'\n"; ! std::cerr << "leaving runinitscript (OK)\n"; return true; } ! if (result == eNotFound) { + std::cerr << "init script not found " << dotDir << salt::PathSeparator << fileName << "\n"; GetLog()->Debug() << "(ScriptServer) : Did not find init script '" ! << dotDir << salt::PathSeparator << fileName << "'\n"; } else if (result == eError) { + std::cerr << "error in init script\n"; GetLog()->Error() << "(ScriptServer) ERROR: Found error in init script '" ! << dotDir << salt::PathSeparator << fileName << "'\n"; ! std::cerr << "leaving runinitscript (ERROR 1)\n"; return false; } ! ! // ! std::cerr << "RunInitScriptInternal(" << pkgdatadir << ", " << fileName << ", " ! << validDotDir << ", " << dotDir << ") (1)\n"; result = RunInitScriptInternal(pkgdatadir, fileName, validDotDir, dotDir); ! if (result == eOK) { + std::cerr << "Ran init script from pkgdatadir: " << pkgdatadir << salt::PathSeparator << fileName << "\n"; GetLog()->Debug() << "(ScriptServer) : Ran init script '" ! << pkgdatadir << salt::PathSeparator << fileName << "'\n"; ! std::cerr << "leaving runinitscript (OK 2)\n"; return true; } *************** *** 616,632 **** { GetLog()->Debug() << "(ScriptServer) : Did not find init script '" ! << pkgdatadir << "/" << fileName << "'\n"; } else if (result == eError) { GetLog()->Error() << "(ScriptServer) ERROR: Found error in init script '" ! << pkgdatadir << "/" << fileName << "'\n"; ! } ! - result = RunInitScriptInternal(mRelPathPrefix+relPath, fileName, validDotDir, dotDir); ! if (result == eNotFound) { GetLog()->Error() << "(ScriptServer) ERROR: Cannot locate init script '" << fileName << "'\n"; --- 668,689 ---- { GetLog()->Debug() << "(ScriptServer) : Did not find init script '" ! << pkgdatadir << salt::PathSeparator << fileName << "'\n"; } else if (result == eError) { GetLog()->Error() << "(ScriptServer) ERROR: Found error in init script '" ! << pkgdatadir << salt::PathSeparator << fileName << "'\n"; ! } ! std::cerr << "RunInitScriptInternal(" << mRelPathPrefix+relPath << ", " << fileName << ", " ! << validDotDir << ", " << dotDir << ") (2)\n"; ! ! result = RunInitScriptInternal(mRelPathPrefix+relPath, fileName, validDotDir, dotDir); ! if (result == eOK) ! std::cerr << "Ran init script OK from : " << mRelPathPrefix+relPath << "\n"; ! else if (result == eNotFound) { + std::cerr << "init script not found at " << mRelPathPrefix+relPath << "\n"; GetLog()->Error() << "(ScriptServer) ERROR: Cannot locate init script '" << fileName << "'\n"; *************** *** 634,641 **** else if (result == eError) { GetLog()->Error() << "(ScriptServer) ERROR: Found error in init script '" ! << mRelPathPrefix+relPath << "/" << fileName << "'\n"; } ! return (result == eOK); } --- 691,699 ---- else if (result == eError) { + std::cerr << "error in init script found at " << mRelPathPrefix+relPath << "\n"; GetLog()->Error() << "(ScriptServer) ERROR: Found error in init script '" ! << mRelPathPrefix+relPath << salt::PathSeparator << fileName << "'\n"; } ! std::cerr << "leaving runinitscript (FINAL)\n"; return (result == eOK); } Index: rubywrapper.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/scriptserver/rubywrapper.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** rubywrapper.h 5 Dec 2005 21:05:01 -0000 1.1 --- rubywrapper.h 15 Mar 2007 07:26:31 -0000 1.2 *************** *** 38,42 **** --- 38,65 ---- #define EXTERN extern __declspec(dllimport) #endif + + #ifdef WIN32 + #include <winsock2.h> + + // disable compiler warning about type cast from VALUE to RBasic* + #pragma warning (disable : 4312) + #endif + #include <ruby.h> + + #ifdef WIN32 + #undef bind + #undef listen + #undef accept + #undef connect + #undef close + #undef recv + #undef socket + #undef send + + // reenable compiler warning + #pragma warning (default : 4312) + #endif + #undef EXTERN *************** *** 53,57 **** /** RbArguments is a structure that describes a ruby function call. ! \param recv is the ruby object that receives the function call \param id is the ruby id of the receiver member function \param n is the number of parameters passed --- 76,80 ---- /** RbArguments is a structure that describes a ruby function call. ! \param receiver is the ruby object that receives the function call \param id is the ruby id of the receiver member function \param n is the number of parameters passed *************** *** 61,71 **** struct RbArguments { ! VALUE recv; ID id; int n; VALUE *argv; ! RbArguments(VALUE recv, ID id, int n, VALUE *argv) : ! recv(recv), id(id), n(n), argv(argv) {}; }; --- 84,94 ---- struct RbArguments { ! VALUE receiver; ID id; int n; VALUE *argv; ! RbArguments(VALUE r, ID id, int n, VALUE *argv) : ! receiver(r), id(id), n(n), argv(argv) {}; }; Index: scriptserver_c.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/scriptserver/scriptserver_c.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** scriptserver_c.cpp 5 Dec 2005 21:05:01 -0000 1.1 --- scriptserver_c.cpp 15 Mar 2007 07:26:31 -0000 1.2 *************** *** 25,30 **** --- 25,37 ---- using namespace zeitgeist; + FUNCTION(ScriptServer,updateCachedAllNodes) + { + obj->UpdateCachedAllNodes(); + return true; + } + void CLASS(ScriptServer)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); + DEFINE_FUNCTION(updateCachedAllNodes); } Index: gcvalue.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/scriptserver/gcvalue.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gcvalue.cpp 5 Dec 2005 21:05:01 -0000 1.1 --- gcvalue.cpp 15 Mar 2007 07:26:31 -0000 1.2 *************** *** 21,24 **** --- 21,25 ---- */ #include "gcvalue.h" + #include "rubywrapper.h" #include <sstream> Index: rubywrapper.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/scriptserver/rubywrapper.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** rubywrapper.cpp 5 Dec 2005 21:05:01 -0000 1.1 --- rubywrapper.cpp 15 Mar 2007 07:26:31 -0000 1.2 *************** *** 25,29 **** { RbArguments &a = *reinterpret_cast<RbArguments*>(arg); ! return rb_funcall2(a.recv, a.id, a.n, a.argv); } --- 25,29 ---- { RbArguments &a = *reinterpret_cast<RbArguments*>(arg); ! return rb_funcall2(a.receiver, a.id, a.n, a.argv); } *************** *** 56,60 **** void zeitgeist::RbPrintError() { ! std::cout << RbGetError() << std::endl; rb_backtrace(); } --- 56,60 ---- void zeitgeist::RbPrintError() { ! std::cout << RbGetError().c_str() << std::endl; rb_backtrace(); } Index: scriptserver.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/scriptserver/scriptserver.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** scriptserver.h 16 May 2006 10:17:32 -0000 1.2 --- scriptserver.h 15 Mar 2007 07:26:31 -0000 1.3 *************** *** 112,115 **** --- 112,116 ---- bool Eval(const std::string &command, GCValue& value); + /** notify all notes to update their cached references */ void UpdateCachedAllNodes(); Index: gcvalue.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/scriptserver/gcvalue.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gcvalue.h 5 Dec 2005 21:05:01 -0000 1.1 --- gcvalue.h 15 Mar 2007 07:26:31 -0000 1.2 *************** *** 24,28 **** #define ZEITGEIST_GCVALUE_H ! #include <zeitgeist/scriptserver/rubywrapper.h> namespace zeitgeist --- 24,31 ---- #define ZEITGEIST_GCVALUE_H ! typedef unsigned long VALUE; ! typedef unsigned long ID; ! ! #include <string> namespace zeitgeist |