Example #1
0
	void TryAddModInfo(const CString& sPath, const CString& sName, set<CModInfo>& ssMods, set<CString>& ssAlready, CModInfo::EModuleType eType) {
		if (ssAlready.count(sName)) {
			return;
		}
		PyObject* pyFunc = PyObject_GetAttrString(m_PyZNCModule, "get_mod_info_path");
		if (!pyFunc) {
			CString sRetMsg = GetPyExceptionStr();
			DEBUG("modpython tried to get info about [" << sPath << "] (1) but: " << sRetMsg);
			return;
		}
		CModInfo ModInfo;
		PyObject* pyRes = PyObject_CallFunction(pyFunc, const_cast<char*>("ssN"),
				sPath.c_str(),
				sName.c_str(),
				SWIG_NewInstanceObj(&ModInfo, SWIG_TypeQuery("CModInfo*"), 0));
		if (!pyRes) {
			CString sRetMsg = GetPyExceptionStr();
			DEBUG("modpython tried to get info about [" << sPath << "] (2) but: " << sRetMsg);
			Py_CLEAR(pyFunc);
			return;
		}
		Py_CLEAR(pyFunc);
		long int x = PyLong_AsLong(pyRes);
		if (PyErr_Occurred()) {
			CString sRetMsg = GetPyExceptionStr();
			DEBUG("modpython tried to get info about [" << sPath << "] (3) but: " << sRetMsg);
			Py_CLEAR(pyRes);
			return;
		}
		Py_CLEAR(pyRes);
		if (x && ModInfo.SupportsType(eType)) {
			ssMods.insert(ModInfo);
			ssAlready.insert(sName);
		}
	}
CString
CMSWindowsClipboardAnyTextConverter::convertLinefeedToWin32(
				const CString& src) const
{
	// note -- we assume src is a valid UTF-8 string

	// count newlines in string
	UInt32 numNewlines = 0;
	UInt32 n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (*scan == '\n') {
			++numNewlines;
		}
	}
	if (numNewlines == 0) {
		return src;
	}

	// allocate new string
	CString dst;
	dst.reserve(src.size() + numNewlines);

	// copy string, converting newlines
	n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] == '\n') {
			dst += '\r';
		}
		dst += scan[0];
	}

	return dst;
}
Example #3
0
bool
CServerApp::loadConfig(const CString& pathname)
{
	try {
		// load configuration
		LOG((CLOG_DEBUG "opening configuration \"%s\"", pathname.c_str()));
		std::ifstream configStream(pathname.c_str());
		if (!configStream.is_open()) {
			// report failure to open configuration as a debug message
			// since we try several paths and we expect some to be
			// missing.
			LOG((CLOG_DEBUG "cannot open configuration \"%s\"",
				pathname.c_str()));
			return false;
		}
		configStream >> *args().m_config;
		LOG((CLOG_DEBUG "configuration read successfully"));
		return true;
	}
	catch (XConfigRead& e) {
		// report error in configuration file
		LOG((CLOG_ERR "cannot read configuration \"%s\": %s",
			pathname.c_str(), e.what()));
	}
	return false;
}
Example #4
0
// for gettin file types, using fstat instead
bool CFile::FType(const CString& sFileName, EFileTypes eType, bool bUseLstat) {
	struct stat st;

	if (!bUseLstat) {
		if (stat(sFileName.c_str(), &st) != 0) {
			return false;
		}
	} else {
		if (lstat(sFileName.c_str(), &st) != 0) {
			return false;
		}
	}

	switch (eType) {
		case FT_REGULAR:
			return S_ISREG(st.st_mode);
		case FT_DIRECTORY:
			return S_ISDIR(st.st_mode);
		case FT_CHARACTER:
			return S_ISCHR(st.st_mode);
		case FT_BLOCK:
			return S_ISBLK(st.st_mode);
		case FT_FIFO:
			return S_ISFIFO(st.st_mode);
		case FT_LINK:
			return S_ISLNK(st.st_mode);
		case FT_SOCK:
			return S_ISSOCK(st.st_mode);
		default:
			break;
	}
	return false;
}
CString
CMSWindowsClipboardAnyTextConverter::convertLinefeedToUnix(
				const CString& src) const
{
	// count newlines in string
	UInt32 numNewlines = 0;
	UInt32 n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] == '\r' && scan[1] == '\n') {
			++numNewlines;
		}
	}
	if (numNewlines == 0) {
		return src;
	}

	// allocate new string
	CString dst;
	dst.reserve(src.size());

	// copy string, converting newlines
	n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] != '\r' || scan[1] != '\n') {
			dst += scan[0];
		}
	}

	return dst;
}
Example #6
0
bool RageSound::Load( CString sSoundFilePath, bool bPrecache )
{
	LOG->Trace( "RageSound::LoadSound( '%s', %d )", sSoundFilePath.c_str(), bPrecache );

	CString error;
	SoundReader *pSound = SoundReader_FileReader::OpenFile( sSoundFilePath, error );
	if( pSound == NULL )
	{
		LOG->Warn( "RageSound::Load: error opening sound \"%s\": %s",
			sSoundFilePath.c_str(), error.c_str() );

		pSound = new RageSoundReader_Silence;
	}

	LoadSoundReader( pSound );

	/* Try to precache.  Do this after calling LoadSoundReader() to put the
	 * sound in this->m_pSource, so we preload after resampling. */
	if( bPrecache )
		RageSoundReader_Preload::PreloadSound( m_pSource );

	m_sFilePath = sSoundFilePath;

	m_Mutex.SetName( ssprintf("RageSound (%s)", Basename(sSoundFilePath).c_str() ) );

	return true;
}
Example #7
0
bool CPetControl::checkNode(const CString &name) {
	CGameManager *gameManager = getGameManager();
	if (!gameManager)
		return true;
	if (name == "NULL")
		return false;

	CViewItem *view = gameManager->getView();
	if (!view)
		return true;

	CNodeItem *node = view->findNode();
	if (!node)
		return true;

	CString viewName = view->getName();
	CString nodeName = node->getName();
	CRoomItem *room = getGameManager()->getRoom();

	if (room) {
		CString roomName = room->getName();
		CString newNode;

		if (roomName == "1stClassRestaurant") {
		} else if (nodeName == "Lobby Node") {
			nodeName = "Node 1";
		} else if (nodeName == "Entrance Node") {
			nodeName = "Node 2";
		} else if (nodeName == "MaitreD Node") {
			nodeName = "Node 3";
		} else if (nodeName == "Scraliontis Table Standing Node") {
			nodeName = "Node 4";
		} else if (nodeName == "Pellerator Node") {
			nodeName = "Node 5";
		} else if (nodeName == "SUB Node") {
			nodeName = "Node 6";
		} else if (nodeName == "Phonograph Node") {
			nodeName = "Node 7";
		} else if (nodeName == "Scraliontis Table Seated Node") {
			nodeName = "Node 8";
		}

		if (roomName == "MusicRoom") {
			if (nodeName == "Musical Instruments")
				nodeName = "Node 1";
			if (nodeName == "Phonograph Node")
				nodeName = "Node 2";
		}
	}

	CString str = CString::format("%s.%s", nodeName.c_str(), viewName.c_str());
	str = str.right(5);
	str.toLowercase();

	CString nameLower = name;
	nameLower.toLowercase();

	return nameLower.contains(str);
}
Example #8
0
 EModRet OnModuleLoading(const CString& sModName, const CString& sArgs,
                         CModInfo::EModuleType eType, bool& bSuccess,
                         CString& sRetMsg) override {
     PyObject* pyFunc = PyObject_GetAttrString(m_PyZNCModule, "load_module");
     if (!pyFunc) {
         sRetMsg = GetPyExceptionStr();
         DEBUG("modpython: " << sRetMsg);
         bSuccess = false;
         return HALT;
     }
     PyObject* pyRes = PyObject_CallFunction(
         pyFunc, const_cast<char*>("ssiNNNN"), sModName.c_str(),
         sArgs.c_str(), (int)eType,
         (eType == CModInfo::GlobalModule
              ? Py_None
              : SWIG_NewInstanceObj(GetUser(), SWIG_TypeQuery("CUser*"), 0)),
         (eType == CModInfo::NetworkModule
              ? SWIG_NewInstanceObj(GetNetwork(),
                                    SWIG_TypeQuery("CIRCNetwork*"), 0)
              : Py_None),
         CPyRetString::wrap(sRetMsg),
         SWIG_NewInstanceObj(reinterpret_cast<CModule*>(this),
                             SWIG_TypeQuery("CModPython*"), 0));
     if (!pyRes) {
         sRetMsg = GetPyExceptionStr();
         DEBUG("modpython: " << sRetMsg);
         bSuccess = false;
         Py_CLEAR(pyFunc);
         return HALT;
     }
     Py_CLEAR(pyFunc);
     long int ret = PyLong_AsLong(pyRes);
     if (PyErr_Occurred()) {
         sRetMsg = GetPyExceptionStr();
         DEBUG("modpython: " << sRetMsg);
         Py_CLEAR(pyRes);
         return HALT;
     }
     Py_CLEAR(pyRes);
     switch (ret) {
         case 0:
             // Not found
             return CONTINUE;
         case 1:
             // Error
             bSuccess = false;
             return HALT;
         case 2:
             // Success
             bSuccess = true;
             return HALT;
     }
     bSuccess = false;
     sRetMsg += " unknown value returned by modpython.load_module";
     return HALT;
 }
Example #9
0
	void CFileHandleDataStream::Open(CString filename)
	{
		m_pFile = fopen(filename.c_str(), "rb");
		if (m_pFile == NULL)
		{
			OGRE_EXCEPT(CException::ERR_FILE_NOT_FOUND,
				"Cannot open file: " + filename,
				"CFileHandleDataStream::Open");
		}

		struct stat tagStat;
		int ret = stat(filename.c_str(), &tagStat);
		m_nSize = tagStat.st_size;
	}
Example #10
0
bool CDir::MakeDir(const CString& sPath, mode_t iMode) {
#ifdef _WIN32
	if (sPath.empty())
		return false;

	CString sFixedPath = sPath;
	sFixedPath.Replace("/", "\\");

	int iResult = SHCreateDirectoryEx(0, sFixedPath.c_str(), NULL);

	return (iResult == ERROR_SUCCESS || iResult == ERROR_FILE_EXISTS || iResult == ERROR_ALREADY_EXISTS);
#else
	CString sDir;
	VCString dirs;
	VCString::iterator it;

	// Just in case someone tries this...
	if (sPath.empty())
		return false;

	// If this is an absolute path, we need to handle this now!
	if (sPath.Left(1) == "/")
		sDir = "/";

	// For every single subpath, do...
	sPath.Split("/", dirs, false);
	for (it = dirs.begin(); it != dirs.end(); ++it) {
		// Add this to the path we already created
		sDir += *it;

		int i = mkdir(sDir.c_str(), iMode);

		if (i != 0) {
			// All errors except EEXIST are fatal
			if (errno != EEXIST)
				return false;

			// If it's EEXIST we have to make sure it's a dir
			if (!CFile::IsDir(sDir))
				return false;
		}

		sDir += "/";
	}

	// All went well
	return true;
#endif
}
Example #11
0
bool CFile::Move(const CString& sOldFileName, const CString& sNewFileName, bool bOverwrite) {
	if (CFile::Exists(sNewFileName)) {
		if (!bOverwrite) {
			errno = EEXIST;
			return false;
		}
#ifdef _WIN32
		// rename() never overwrites files on Windows.
		DWORD dFlags = MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING;
		return (::MoveFileExA(sOldFileName.c_str(), sNewFileName.c_str(), dFlags) != 0);
#endif
	}

	return (rename(sOldFileName.c_str(), sNewFileName.c_str()) == 0);
}
bool
CAdvancedOptions::save(HWND hwnd)
{
	HWND child = getItem(hwnd, IDC_ADVANCED_NAME_EDIT);
	CString name = getWindowText(child);
	if (!m_config->isValidScreenName(name)) {
		showError(hwnd, CStringUtil::format(
								getString(IDS_INVALID_SCREEN_NAME).c_str(),
								name.c_str()));
		SetFocus(child);
		return false;
	}
	if (!m_isClient && !m_config->isScreen(name)) {
		showError(hwnd, CStringUtil::format(
								getString(IDS_UNKNOWN_SCREEN_NAME).c_str(),
								name.c_str()));
		SetFocus(child);
		return false;
	}

	// get and verify port
	child = getItem(hwnd, IDC_ADVANCED_PORT_EDIT);
	CString portString = getWindowText(child);
	int port = atoi(portString.c_str());
	if (port < 1 || port > 65535) {
		CString defaultPortString = CStringUtil::print("%d", kDefaultPort);
		showError(hwnd, CStringUtil::format(
								getString(IDS_INVALID_PORT).c_str(),
								portString.c_str(),
								defaultPortString.c_str()));
		SetFocus(child);
		return false;
	}

	// save state
	m_screenName = name;
	m_port       = port;

	// save values to registry
	HKEY key = CArchMiscWindows::openKey(HKEY_CURRENT_USER, getSettingsPath());
	if (key != NULL) {
		CArchMiscWindows::setValue(key, "port", m_port);
		CArchMiscWindows::setValue(key, "name", m_screenName);
		CArchMiscWindows::closeKey(key);
	}

	return true;
}
Example #13
0
void PlayerAI::InitFromDisk()
{
	IniFile ini;
	ini.ReadFile( AI_PATH );

	for( int i=0; i<NUM_SKILL_LEVELS; i++ )
	{
		CString sKey = ssprintf("Skill%d", i);
		XNode* pNode = ini.GetChild(sKey);
		if( pNode == NULL )
			RageException::Throw( "AI.ini: '%s' doesn't exist.", sKey.c_str() );

		TapScoreDistribution& dist = g_Distributions[i];
		dist.fPercent[TNS_NONE] = 0;
		pNode->GetAttrValue( "MissWeight", dist.fPercent[TNS_MISS] );
		pNode->GetAttrValue( "BooWeight", dist.fPercent[TNS_BOO] );
		pNode->GetAttrValue( "GoodWeight", dist.fPercent[TNS_GOOD] );
		pNode->GetAttrValue( "GreatWeight", dist.fPercent[TNS_GREAT] );
		pNode->GetAttrValue( "PerfectWeight", dist.fPercent[TNS_PERFECT] );
		pNode->GetAttrValue( "MarvelousWeight", dist.fPercent[TNS_MARVELOUS] );
		
		float fSum = 0;
		for( int j=0; j<NUM_TAP_NOTE_SCORES; j++ )
			fSum += dist.fPercent[j];
		for( int j=0; j<NUM_TAP_NOTE_SCORES; j++ )
			dist.fPercent[j] /= fSum;
	}
}
Example #14
0
bool
CKeyMap::parseKey(const CString& x, KeyID& key)
{
	// initialize tables
	initKeyNameMaps();

	// parse the key
	key = kKeyNone;
	if (s_nameToKeyMap->count(x) > 0) {
		key = s_nameToKeyMap->find(x)->second;
	}
	// XXX -- we're assuming ASCII encoding here
	else if (x.size() == 1) {
		if (!isgraph(x[0])) {
			// unknown key
			return false;
		}
		key = (KeyID)x[0];
	}
	else if (x.size() == 6 && x[0] == '\\' && x[1] == 'u') {
		// escaped unicode (\uXXXX where XXXX is a hex number)
		char* end;
		key = (KeyID)strtol(x.c_str() + 2, &end, 16);
		if (*end != '\0') {
			return false;
		}
	}
	else if (!x.empty()) {
		// unknown key
		return false;
	}

	return true;
}
Example #15
0
bool CFile::Delete(const CString& sFileName) {
	if (!CFile::Exists(sFileName)) {
		return false;
	}

	return (unlink(sFileName.c_str()) == 0) ? true : false;
}
bool BackgroundLoader::IsCacheFileFinished( const CString &sFile, CString &sActualPath )
{
    if( !g_bEnableBackgroundLoading )
    {
        sActualPath = sFile;
        return true;
    }

    LockMut( m_Mutex );

    if( sFile == "" )
    {
        sActualPath = "";
        return true;
    }

    map<CString,int>::iterator it;
    it = m_FinishedRequests.find( sFile );
    if( it == m_FinishedRequests.end() )
        return false;

    LOG->Trace("XXX: %s finished (%i)", sFile.c_str(), it->second);
    if( g_bWriteToCache )
        sActualPath = GetCachePath( sFile );
    else
        sActualPath = sFile;

    return true;
}
// Variant value must be released with NPReleaseVariantValue()
void coerceValueToNPVariantStringType (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)
{
    UString ustring = value.toString(exec);
    CString cstring = ustring.UTF8String();
    NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() };
    NPN_InitializeVariantWithStringCopy (result, &string);
}
Example #18
0
File: kjs.cpp Project: KDE/kjs
static ExitCode evaluateString(Interpreter *interp, const char *fileName,
                               const UString &code,
                               bool printResult = false)
{
    ExecState *exec = interp->globalExec();

    Completion res = interp->evaluate(fileName, 0, code);

    if (res.complType() == Throw) {
        CString msg = res.value()->toString(exec).UTF8String();
        JSObject *resObj = res.value()->toObject(exec);
        CString message = resObj->toString(exec).UTF8String();
        int line = resObj->toObject(exec)->get(exec, "line")->toUInt32(exec);

        if (fileName) {
            fprintf(stderr, "%s (line %d): ", fileName, line);
        }
        fprintf(stderr, "%s\n", msg.c_str());
        return ErrorEval;
    } else if (printResult) {
        if (res.isValueCompletion() && !res.value()->isUndefined()) {
            CString s8 = res.value()->toString(exec).UTF8String();
            if (s8.size() != 0) {
                fprintf(stdout, "%s\n", s8.c_str());
            }
        }
    }

    return ErrorNone;
}
Example #19
0
// 16 variables may be a bit of over kill, but hey, it's only code.
unsigned CIniFile::GetValueV( const CString& keyname, const CString& valuename, char *format,
            void *v1, void *v2, void *v3, void *v4,
              void *v5, void *v6, void *v7, void *v8,
              void *v9, void *v10, void *v11, void *v12,
              void *v13, void *v14, void *v15, void *v16)
{
  CString   value;
  // va_list  args;
  unsigned nVals;


  value = GetValue( keyname, valuename);
  if ( !value.length())
    return false;
  // Why is there not vsscanf() function. Linux man pages say that there is
  // but no compiler I've seen has it defined. Bummer!
  //
  // va_start( args, format);
  // nVals = vsscanf( value.c_str(), format, args);
  // va_end( args);

  nVals = sscanf( value.c_str(), format,
      v1, v2, v3, v4, v5, v6, v7, v8,
      v9, v10, v11, v12, v13, v14, v15, v16);

  return nVals;
}
Example #20
0
void CJobObject::CreateNewJob() {
   CMutex::CEnter MutexEnter(m_Mutex);
   static const DWORD dwMaxBufferSize = 1024;
   WCHAR pszBuffer[dwMaxBufferSize];
   CString JobName;
   BOOL bError;
   HANDLE hJob;

   m_dwJobId = 0;
   bError = true;
   while (bError) {
      m_dwJobId++;
      if (m_dwJobId == 0) {
         m_dwJobId++;
      }
      wsprintf(pszBuffer, L"%ld", m_dwJobId);
      JobName = pszBuffer;

      hJob = CreateJobObject(0, const_cast<PWSTR>(JobName.c_str()));
      if(hJob == NULL) {
         bError = true;
      } else if (GetLastError() == ERROR_ALREADY_EXISTS) {
         bError = true;
      } else {
         bError = false;
         SetHandle(hJob);
      }
   }
}
Example #21
0
void AttackDisplay::Init( PlayerNumber pn )
{
	m_PlayerNumber = pn;

	if( GAMESTATE->m_PlayMode != PLAY_MODE_BATTLE &&
		GAMESTATE->m_PlayMode != PLAY_MODE_RAVE )
		return;

	set<CString> attacks;
	for( int al=0; al<NUM_ATTACK_LEVELS; al++ )
	{
		const Character *ch = GAMESTATE->m_pCurCharacters[pn];
		ASSERT( ch );
		const CString* asAttacks = ch->m_sAttacks[al];
		for( int att = 0; att < NUM_ATTACKS_PER_LEVEL; ++att )
			attacks.insert( asAttacks[att] );
	}

	for( set<CString>::const_iterator it = attacks.begin(); it != attacks.end(); ++it )
	{
		const CString ThemePath = GetAttackPath( *it );
		const CString path = THEME->GetPathToG( ThemePath, true );
		if( path == "" )
		{
			LOG->Trace( "Couldn't find \"%s\"", ThemePath.c_str() );
			continue;
		}

		TEXTUREMAN->CacheTexture( path );
	}
}
Example #22
0
bool CFile::Move(const CString& sOldFileName, const CString& sNewFileName, bool bOverwrite) {
#ifndef WIN_MSVC
	if ((!bOverwrite) && (CFile::Exists(sNewFileName))) {
		return false;
	}

	return (rename(sOldFileName.c_str(), sNewFileName.c_str()) == 0);
#else
	// msvc's rename() doesn't seem to overwrite files. d'oh.

	DWORD dFlags = MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED;
	if(bOverwrite) dFlags |= MOVEFILE_REPLACE_EXISTING;
	
	return (MoveFileEx(sOldFileName.c_str(), sNewFileName.c_str(), dFlags) != 0);
#endif
}
Example #23
0
off_t CFile::GetSize(const CString& sFile) {
	struct stat st;
	if (stat(sFile.c_str(), &st) != 0) {
		return 0;
	}

	return (S_ISREG(st.st_mode)) ? st.st_size : 0;
}
Example #24
0
Url WindowsEnvFun::GetUserData(cstring org, cstring app)
{
    if(!org && !app)
    {
        org = ApplicationData().organization_name.c_str();
        app = ApplicationData().application_name.c_str();
    }

    CString out;
    out = GetUserHome().internUrl;
    out = ConcatPath(out.c_str(), "AppData");
    out = ConcatPath(out.c_str(), "Local");
    out = ConcatPath(out.c_str(), org);
    out = ConcatPath(out.c_str(), app);
    out = str::replace::str(out, "\\", "/");
    return MkUrl(out, RSCA::SystemFile);
}
Example #25
0
    int Directory::GetFilesCount(const CString& path, const bool& recursive) {

        std::string path_utf8 = stringWstingToUtf8String(path.c_str());

        std::vector<std::string> files;
        listdir (path_utf8.c_str(), recursive, files);

        return files.size()+1;
    }
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)
{
    Type type = value.type();

    if (type == StringType) {
        UString ustring = value.toString(exec);
        CString cstring = ustring.UTF8String();
        NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() };
        NPN_InitializeVariantWithStringCopy (result, &string );
    }
    else if (type == NumberType) {
        NPN_InitializeVariantWithDouble (result, value.toNumber(exec));
    }
    else if (type == BooleanType) {
        NPN_InitializeVariantWithBool (result, value.toBoolean(exec));
    }
    else if (type == UnspecifiedType) {
        NPN_InitializeVariantAsUndefined(result);
    }
    else if (type == NullType) {
        NPN_InitializeVariantAsNull(result);
    }
    else if (type == ObjectType) {
        KJS::ObjectImp *objectImp = static_cast<KJS::ObjectImp*>(value.imp());
        if (objectImp->classInfo() == &KJS::RuntimeObjectImp::info) {
            KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp *>(value.imp());
            CInstance *instance = static_cast<CInstance*>(imp->getInternalInstance());
            NPN_InitializeVariantWithObject (result, instance->getObject());
        }
        else {

            KJS::Interpreter *originInterpreter = exec->interpreter();
            const Bindings::RootObject *originExecutionContext = rootForInterpreter(originInterpreter);

            KJS::Interpreter *interpreter = 0;
            if (originInterpreter->isGlobalObject(value)) {
                interpreter = originInterpreter->interpreterForGlobalObject (value.imp());
            }

            if (!interpreter)
                interpreter = originInterpreter;

            const Bindings::RootObject *executionContext = rootForInterpreter(interpreter);
            if (!executionContext) {
                Bindings::RootObject *newExecutionContext = new KJS::Bindings::RootObject(0);
                newExecutionContext->setInterpreter (interpreter);
                executionContext = newExecutionContext;
            }

            NPObject *obj = (NPObject *)exec->interpreter()->createLanguageInstanceForValue (exec, Instance::CLanguage, value.toObject(exec), originExecutionContext, executionContext);
            NPN_InitializeVariantWithObject (result, obj);
            _NPN_ReleaseObject (obj);
        }
    }
    else
        NPN_InitializeVariantAsUndefined(result);
}
Example #27
0
bool XNode::LoadFromFile( const CString &sFile )
{
	RageFile f;
	if( !f.Open(sFile, RageFile::READ) )
	{
		LOG->Warn("Couldn't open %s for reading: %s", sFile.c_str(), f.GetError().c_str() );
		return false;
	}

	bool bSuccess = LoadFromFile( f );
	if( !bSuccess )
	{
		CString sWarning = ssprintf( "XML: LoadFromFile failed for file: %s", sFile.c_str() );
		LOG->Warn( sWarning );
		Dialog::OK( sWarning, "XML_PARSE_ERROR" );
	}
	return bSuccess;
}
Example #28
0
    void Start() {
        CString sMyArgs = GetArgs();

        interp = Tcl_CreateInterp();
        Tcl_Init(interp);
        Tcl_CreateCommand(interp, "Binds::ProcessPubm", tcl_Bind, this,
                          nullptr);
        Tcl_CreateCommand(interp, "Binds::ProcessMsgm", tcl_Bind, this,
                          nullptr);
        Tcl_CreateCommand(interp, "Binds::ProcessTime", tcl_Bind, this,
                          nullptr);
        Tcl_CreateCommand(interp, "Binds::ProcessEvnt", tcl_Bind, this,
                          nullptr);
        Tcl_CreateCommand(interp, "Binds::ProcessNick", tcl_Bind, this,
                          nullptr);
        Tcl_CreateCommand(interp, "Binds::ProcessKick", tcl_Bind, this,
                          nullptr);
        Tcl_CreateCommand(interp, "PutIRC", tcl_PutIRC, this, nullptr);
        Tcl_CreateCommand(interp, "PutModule", tcl_PutModule, this, nullptr);
        Tcl_CreateCommand(interp, "PutStatus", tcl_PutStatus, this, nullptr);
        Tcl_CreateCommand(interp, "PutStatusNotice", tcl_PutStatusNotice, this,
                          nullptr);
        Tcl_CreateCommand(interp, "PutUser", tcl_PutUser, this, nullptr);

        Tcl_CreateCommand(interp, "GetCurNick", tcl_GetCurNick, this, nullptr);
        Tcl_CreateCommand(interp, "GetUsername", tcl_GetUsername, this,
                          nullptr);
        Tcl_CreateCommand(interp, "GetRealName", tcl_GetRealName, this,
                          nullptr);
        Tcl_CreateCommand(interp, "GetVHost", tcl_GetBindHost, this, nullptr);
        Tcl_CreateCommand(interp, "GetBindHost", tcl_GetBindHost, this,
                          nullptr);
        Tcl_CreateCommand(interp, "GetChans", tcl_GetChans, this, nullptr);
        Tcl_CreateCommand(interp, "GetChannelUsers", tcl_GetChannelUsers, this,
                          nullptr);
        Tcl_CreateCommand(interp, "GetChannelModes", tcl_GetChannelModes, this,
                          nullptr);
        Tcl_CreateCommand(interp, "GetServer", tcl_GetServer, this, nullptr);
        Tcl_CreateCommand(interp, "GetServerOnline", tcl_GetServerOnline, this,
                          nullptr);
        Tcl_CreateCommand(interp, "GetModules", tcl_GetModules, this, nullptr);
        Tcl_CreateCommand(interp, "GetClientCount", tcl_GetClientCount, this,
                          nullptr);

        Tcl_CreateCommand(interp, "exit", tcl_exit, this, nullptr);

        if (!sMyArgs.empty()) {
            i = Tcl_EvalFile(interp, sMyArgs.c_str());
            if (i != TCL_OK) {
                PutModule(Tcl_GetStringResult(interp));
            }
        }

        AddTimer(new CModTclTimer(
            this, 1, 0, "ModTclUpdate",
            "Timer for modtcl to process pending events and idle callbacks."));
    }
Example #29
0
void DumpPixelFormat( const PIXELFORMATDESCRIPTOR &pfd )
{
    CString str = ssprintf( "Mode: " );
    bool bInvalidFormat = false;

    if( pfd.dwFlags & PFD_GENERIC_FORMAT )
    {
        if( pfd.dwFlags & PFD_GENERIC_ACCELERATED ) str += "MCD ";
        else {
            str += "software ";
            bInvalidFormat = true;
        }
    }
    else
        str += "ICD ";

    if( pfd.iPixelType != PFD_TYPE_RGBA ) {
        str += "indexed ";
        bInvalidFormat = true;
    }
    if( !(pfd.dwFlags & PFD_SUPPORT_OPENGL) ) {
        str += "!OPENGL ";
        bInvalidFormat = true;
    }
    if( !(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ) {
        str += "!window ";
        bInvalidFormat = true;
    }
    if( !(pfd.dwFlags & PFD_DOUBLEBUFFER) ) {
        str += "!dbuff ";
        bInvalidFormat = true;
    }

    str += ssprintf( "%i (%i%i%i) ", pfd.cColorBits, pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits );
    if( pfd.cAlphaBits ) str += ssprintf( "%i alpha ", pfd.cAlphaBits );
    if( pfd.cDepthBits ) str += ssprintf( "%i depth ", pfd.cDepthBits );
    if( pfd.cStencilBits ) str += ssprintf( "%i stencil ", pfd.cStencilBits );
    if( pfd.cAccumBits ) str += ssprintf( "%i accum ", pfd.cAccumBits );

    if( bInvalidFormat )
        LOG->Warn( "Invalid format: %s", str.c_str() );
    else
        LOG->Info( "%s", str.c_str() );
}
Example #30
0
CString GetAttackPath( const CString &sAttack )
{
	CString ret = ssprintf( "AttackDisplay attack %s", sAttack.c_str() );

	/* 1.5x -> 1_5x.  If we pass a period to THEME->GetPathTo, it'll think
	 * we're looking for a specific file and not search. */
	ret.Replace( ".", "_" );

	return ret;
}