void NemoThumbnailProvider::setupCache()
{
    // the syscalls make baby jesus cry; but this protects us against sins like users
    QDir d(cachePath());
    if (!d.exists())
        d.mkpath(cachePath());
    d.mkdir("raw");

    // in the future, we might store a nicer UI version which can blend in with our UI better, but
    // we'll always want the raw version.
}
Ejemplo n.º 2
0
//--------------------------------------------------------------------------------
// Make sure our data folder exist, if not establish it
SFBool establishFolders(CConfig& config, const SFString& vers)
{
	SFString configFilename = configPath("ethslurp.conf");

	config.setFilename(configFilename);
	if (SFos::folderExists(cachePath()) && SFos::fileExists(configFilename))
	{
		config.loadFile(configFilename);
		return TRUE;
	}

	// create the main folder
	SFos::mkdir(configPath());
	if (!SFos::folderExists(configPath()))
		return FALSE;

	// create the folder for the slurps
	SFos::mkdir(cachePath());
	if (!SFos::folderExists(cachePath()))
		return FALSE;

	config.SetProfileString("SETTINGS",     "cachePath",         cachePath());
	config.SetProfileString("SETTINGS",     "api_key",           EMPTY);

	config.SetProfileString("DISPLAY_STR",  "fmt_fieldList",     EMPTY);

	config.SetProfileString("DISPLAY_STR",  "fmt_txt_file",      "[{HEADER}]\\n[{RECORDS}]");
	config.SetProfileString("DISPLAY_STR",  "fmt_txt_record",    "[{FIELDS}]\\n");
	config.SetProfileString("DISPLAY_STR",  "fmt_txt_field",     "\\t[{FIELD}]");

	config.SetProfileString("DISPLAY_STR",  "fmt_csv_file",      "[{HEADER}]\\n[{RECORDS}]");
	config.SetProfileString("DISPLAY_STR",  "fmt_csv_record",    "[{FIELDS}]\\n");
	config.SetProfileString("DISPLAY_STR",  "fmt_csv_field",     "[\"{FIELD}\"],");

	config.SetProfileString("DISPLAY_STR",  "fmt_html_file",     "<table>\\n[{HEADER}]\\n[{RECORDS}]</table>\\n");
	config.SetProfileString("DISPLAY_STR",  "fmt_html_record",   "\\t<tr>\\n[{FIELDS}]</tr>\\n");
	config.SetProfileString("DISPLAY_STR",  "fmt_html_field",    "\\t\\t<td>[{FIELD}]</td>\\n");

	config.SetProfileString("DISPLAY_STR",  "fmt_json_file",     "[{RECORDS}]\\n");
	config.SetProfileString("DISPLAY_STR",  "fmt_json_record",   "\\n        {\\n[{FIELDS}]        },");
	config.SetProfileString("DISPLAY_STR",  "fmt_json_field",    "\"[{p:FIELD}]\":\"[{FIELD}]\",");

	config.SetProfileString("DISPLAY_STR",  "fmt_custom_file",	 "file:custom_format_file.html");
	config.SetProfileString("DISPLAY_STR",  "fmt_custom_record", "fmt_html_record");
	config.SetProfileString("DISPLAY_STR",  "fmt_custom_field",	 "fmt_html_field");

	config.writeFile(vers);
	return SFos::fileExists(config.getFilename());
}
Ejemplo n.º 3
0
void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::ArgumentDecoder*)
{
    setShouldPaintNativeControls(parameters.shouldPaintNativeControls);

#if USE(CFNETWORK)
    CFURLStorageSessionRef defaultStorageSession = wkDeserializeStorageSession(parameters.serializedDefaultStorageSession.get());
    ResourceHandle::setDefaultStorageSession(defaultStorageSession);

    WebCookieManager::shared().setHTTPCookieAcceptPolicy(parameters.initialHTTPCookieAcceptPolicy);

    // By using the default storage session that came from the ui process, the web process
    // automatically uses the same the URL Cache as ui process.
    if (defaultStorageSession)
        return;

    RetainPtr<CFStringRef> cachePath(AdoptCF, parameters.cfURLCachePath.createCFString());
    if (!cachePath)
        return;

    CFIndex cacheDiskCapacity = parameters.cfURLCacheDiskCapacity;
    CFIndex cacheMemoryCapacity = parameters.cfURLCacheMemoryCapacity;
    RetainPtr<CFURLCacheRef> uiProcessCache(AdoptCF, CFURLCacheCreate(kCFAllocatorDefault, cacheMemoryCapacity, cacheDiskCapacity, cachePath.get()));
    CFURLCacheSetSharedURLCache(uiProcessCache.get());
#endif // USE(CFNETWORK)
}
static void writeCacheFile(const QByteArray &hashKey, const QImage &img)
{
    QFile fi(cachePath() + QDir::separator() + "raw" + QDir::separator() + hashKey);
    if (!fi.open(QIODevice::WriteOnly)) {
        qWarning() << "Couldn't cache to " << fi.fileName();
        return;
    }
    img.save(&fi, "JPG");
    fi.flush();
    fi.close();
}
static QImage attemptCachedServe(const QByteArray &hashKey)
{
    QFile fi(cachePath() + QDir::separator() + "raw" + QDir::separator() + hashKey);
    if (fi.open(QIODevice::ReadOnly)) {
        // cached file exists! hooray.
        QImage img;
        img.load(&fi, "JPG");
        return img;
    }

    return QImage();
}
Ejemplo n.º 6
0
void SecretManager::saveCache()
{
    QFile file(cachePath());
    if (!file.open(QIODevice::WriteOnly))
    {
        qDebug() << "Couldn't write samba file!";
        return;
    }
    QJsonDocument jsonDoc(m_smbLoginObjs);
    file.write(jsonDoc.toJson());
    file.close();
}
Ejemplo n.º 7
0
void MarkdownPlugin::changeCssToInline(QWebFrame* frame)
{
    if (frame)
    {
        QString strHtml = frame->toHtml();
        QRegExp regHeadContant("<head[^>]*>[\\s\\S]*</head>");
        QString strPath = cachePath() + "plugins/markdown/";
        QString strNewHead = QString("<head><link rel=\"stylesheet\" href=\"file://" + strPath + "markdown/github2.css\">"
                                     "<script src=\"file://" + strPath +"markdown/jquery.min.js\"></script>"
                                     "<script src=\"file://" + strPath + "inlinecss/jquery.inlineStyler.min.js\"></script>"
                                     "<script src=\"file://" + strPath + "inlinecss/csstoinline.js\"></script></head>");
        strHtml.replace(regHeadContant, strNewHead);
        frame->setHtml(strHtml);
    }
}
Ejemplo n.º 8
0
QString SFtpFileEngine::getCachePath(const QString &path, bool key) const
{
    QString cachePath(_url.scheme());

    cachePath.append("://").append(_userName).append("@")
             .append(_url.host()).append(":").append(QString::number(_port))
             .append(path);

    if (path.isEmpty())
        cachePath.append("/");

    if (key && !cachePath.endsWith("/"))
        cachePath.append("/");

    return cachePath;
}
Ejemplo n.º 9
0
void SecretManager::loadCache()
{
    //Migration for old config files, and rmove that codes for further
    FileUtils::migrateConfigFileFromCache("samba");

    QFile file(cachePath());
    if (!file.open(QIODevice::ReadOnly))
    {
        qDebug() << "Couldn't write samba file!";
        return;
    }
    QByteArray data = file.readAll();
    QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
    m_smbLoginObjs = jsonDoc.object();
    file.close();
    qDebug() << m_smbLoginObjs;
}
Ejemplo n.º 10
0
void MarkdownPlugin::render(QWebFrame* frame)
{
    Q_ASSERT(frame);

    QFile f(":/res/WizNote-Markdown.js");
    if (!f.open(QIODevice::ReadOnly)) {
        qDebug() << "[Markdown]Failed to get render execute code";
        return;
    }

    QTextStream ts(&f);
    QString strExec = ts.readAll();
    f.close();

    Q_ASSERT(strExec.indexOf("${CACHE_PATH}") != -1);
    QString strPath = cachePath() + "plugins/markdown/";
    QDir dir;
    dir.mkpath(strPath);
    strExec.replace("${CACHE_PATH}", strPath);

    frame->evaluateJavaScript(strExec);
}
Ejemplo n.º 11
0
QAbstractFileEngine::Iterator*
SFtpFileEngine::beginEntryList(QDir::Filters filters,
                              const QStringList &filterNames)
{
    qDebug() << "beginEntryList() : " << _fileName << _fileFlags;

    QString cachePath(getCachePath(_path, true));
    FtpFileInfoCache::QUrlInfoList list =
            _fileInfoCache->findDirInfo(cachePath);

    if (list.size() == 0
            && (_fileFlags & QAbstractFileEngine::DirectoryType)
            && sftpConnect())
    {
        readDir(_path);

        sftpDisconnect();
    }

    QMap<QString, QUrlInfo> entriesMap;

    list = _fileInfoCache->findDirInfo(cachePath);
    if (list.size() > 0)
    {
        FtpFileInfoCache::QUrlInfoListIterator it(list);
        while (it.hasNext())
        {
            QUrlInfo urlInfo = it.next();

            // exclude an empty entry inserted by us and a non-existent entry
            if (urlInfo.isValid() && urlInfo.permissions())
                entriesMap.insert(urlInfo.name(), urlInfo);
        }
    }

    return new FtpFileEngineIterator(filters, filterNames,
                                     filterEntries(filters, filterNames,
                                                   entriesMap));
}
Ejemplo n.º 12
0
void DesktopMainWindow::editSettings()
{
  AppSettingsDialog settingsDialog(_app.get());
	if (settingsDialog.exec() == QDialog::Accepted)
	{
    _app->setSunMode(settingsDialog.getSunMode());

    double sunLat, sunLon;
    settingsDialog.getSunPosition(sunLat, sunLon);
    _app->setSunPosition(sunLat, sunLon);


    QDir cachePath(QString(settingsDialog.getCachePath().c_str()));

    osgEarth::Drivers::Sqlite3CacheOptions newOpt;
    newOpt.path() = cachePath.absolutePath().toUtf8().data();
    newOpt.maxSize() = settingsDialog.getCacheMax();

    _app->setCache(newOpt);

		_app->setCacheEnabled(settingsDialog.getCacheEnabled());
	}
}
static inline QString rawCachePath()
{
    return cachePath() + QDir::separator() + "raw";
}
Ejemplo n.º 14
0
bool MarkdownPlugin::copyRes2Cache()
{
    QString strPath = cachePath() + "plugins/markdown/";
    QDir cacheDir(strPath);
    cacheDir.mkpath(strPath);


    QStringList lsRes;
    lsRes << ":/res/WizNote-Markdown.js" << ":/res/wiznote-markdown-inject.js";

    QString strMarkdownPath = strPath + "markdown/";
    cacheDir.mkpath(strMarkdownPath);
    QString strGoogleCodePath = strPath + "google-code-prettify/";
    cacheDir.mkpath(strGoogleCodePath);

    lsRes <<":/res/google-code-prettify/lang-yaml.js"
            <<":/res/google-code-prettify/lang-xq.js"
            <<":/res/google-code-prettify/lang-wiki.js"
            <<":/res/google-code-prettify/lang-vhdl.js"
            <<":/res/google-code-prettify/lang-vb.js"
            <<":/res/google-code-prettify/lang-tex.js"
            <<":/res/google-code-prettify/lang-tcl.js"
            <<":/res/google-code-prettify/lang-sql.js"
            <<":/res/google-code-prettify/lang-scala.js"
            <<":/res/google-code-prettify/lang-rd.js"
            <<":/res/google-code-prettify/lang-r.js"
            <<":/res/google-code-prettify/lang-proto.js"
            <<":/res/google-code-prettify/lang-pascal.js"
            <<":/res/google-code-prettify/lang-n.js"
            <<":/res/google-code-prettify/lang-mumps.js"
            <<":/res/google-code-prettify/lang-ml.js"
            <<":/res/google-code-prettify/lang-matlab.js"
            <<":/res/google-code-prettify/lang-lua.js"
            <<":/res/google-code-prettify/lang-llvm.js"
            <<":/res/google-code-prettify/lang-lisp.js"
            <<":/res/google-code-prettify/lang-hs.js"
            <<":/res/google-code-prettify/lang-go.js"
            <<":/res/google-code-prettify/lang-erlang.js"
            <<":/res/google-code-prettify/lang-dart.js"
            <<":/res/google-code-prettify/lang-css.js"
            <<":/res/google-code-prettify/lang-clj.js"
            <<":/res/google-code-prettify/lang-basic.js"
            <<":/res/google-code-prettify/lang-apollo.js"
            <<":/res/google-code-prettify/run_prettify.js"
            <<":/res/google-code-prettify/prettify.js"
            <<":/res/google-code-prettify/prettify.css"
            <<":/res/markdown/github2.css"
            <<":/res/markdown/marked.min.js"
            <<":/res/markdown/jquery.min.js";

    for (int i = 0; i < lsRes.size(); i++) {
        QString strInter = lsRes.at(i);
        QFile f(strInter);
        if (!f.open(QIODevice::ReadOnly)) {
            Q_ASSERT(0);
            return false;
        }

        QString strName = strInter.remove(0, 6);
        QFile f2(cacheDir.filePath(strName));
        if (!f2.open(QIODevice::Truncate|QIODevice::WriteOnly)) {
            qDebug() << "[Markdown]failed to write cache: " << f2.fileName();
            return false;
        }

        f2.write(f.readAll());
        f.close();
        f2.close();
    }


    return true;
}
Ejemplo n.º 15
0
//--------------------------------------------------------------------------------
SFBool CSlurperApp::Slurp(COptions& options, SFString& message)
{
	double start = vrNow();

	// Do we have the data for this address cached?
	SFString cacheFilename = cachePath(theAccount.addr+".bin");
	SFBool needToRead = SFos::fileExists(cacheFilename);
	if (options.rerun && theAccount.transactions.getCount())
		needToRead=FALSE;
	if (needToRead)
	{
		// Once a transaction is on the blockchain, it will never change
		// therefore, we can store them in a binary cache. Here we read
		// from a previously stored cache.
		SFArchive archive(TRUE, NO_SCHEMA);
		if (!archive.Lock(cacheFilename, binaryReadOnly, LOCK_NOWAIT))
		{
			message = "Could not open file: '" + cacheFilename + "'\n";
			return options.cmdFile;
		}
		theAccount.Serialize(archive);
		archive.Close();
	}

	SFTime now = Now();
	SFTime fileTime = SFos::fileLastModifyDate(cacheFilename);

	// If the user tells us he/she wants to update the cache, or the cache
	// hasn't been updated in five minutes, then update it
	SFInt32 nSeconds = MAX(60,config.GetProfileIntGH("SETTINGS", "update_freq", 300));
	if (options.slurp || (now - fileTime) > SFTimeSpan(0,0,0,nSeconds))
	{
		// This is how many records we currently have
		SFInt32 origCount  = theAccount.transactions.getCount();
		SFInt32 nNewBlocks = 0;
		SFInt32 nextRecord = origCount;

		outErr << "\tSlurping new transactions from blockchain...\n";
		SFInt32  nRequests = 0, nRead = 0;

		// We already have 'page' pages, so start there.
		SFInt32  page = MAX(theAccount.lastPage,1);

		// Keep reading until we get less than a full page
		SFString contents;
		SFBool done = FALSE;
		while (!done)
		{
			SFString url = SFString("https://api.etherscan.io/api?module=account&action=txlist&sort=asc") +
				"&address=" + theAccount.addr + "&page="    + asString(page) + "&offset="  + asString(options.pageSize) + "&apikey="  + api.getKey();
			// Grab a page of data from the web api
			SFString thisPage = urlToString(url);

			// See if it's good data, if not, bail
			message = nextTokenClear(thisPage, '[');
			if (!message.Contains("{\"status\":\"1\",\"message\":\"OK\""))
			{
				if (message.Contains("{\"status\":\"0\",\"message\":\"No transactions found\",\"result\":"))
					message = "No transactions were found for address '" + theAccount.addr + "'. Is it correct?";
				return options.cmdFile;
			}

			contents += thisPage;

			SFInt32 nRecords = countOf('}',thisPage)-1;
			nRead += nRecords;
			outErr << "\tDownloaded " << nRead << " potentially new transactions." << (isTesting?"\n":"\r");

			// If we got a full page, there are more to come
			done = (nRecords < options.pageSize);
			if (!done)
				page++;

			// Etherscan.io doesn't want more than five pages per second, so sleep for a second
			if (++nRequests==4)
			{
				SFos::sleep(1.0);
				nRequests=0;
			}

			// Make sure we don't spin forever
			if (nRead >= options.maxTransactions)
				done=TRUE;
		}

		SFInt32 minBlock=0,maxBlock=0;
		findBlockRange(contents, minBlock, maxBlock);
		outErr << "\n\tDownload contains blocks from " << minBlock << " to " << maxBlock << "\n";

		// Keep track of which last full page we've read
		theAccount.lastPage = page;
		theAccount.pageSize = options.pageSize;

		// pre allocate the array
		theAccount.transactions.Grow(nRead);

		SFInt32 lastBlock=0;
		char *p = cleanUpJson((char *)(const char*)contents);
		while (p && *p)
		{
			CTransaction trans;SFInt32 nFields=0;
			p = trans.parseJson(p,nFields);
			if (nFields)
			{
				SFInt32 transBlock = trans.blockNumber;
				if (transBlock > theAccount.lastBlock) // add the new transaction if it's in a new block
				{
					theAccount.transactions[nextRecord++] = trans;
					lastBlock = transBlock;
					if (!(++nNewBlocks%REP_FREQ))
					{
						outErr << "\tFound new transaction at block " << transBlock << ". Importing..." << (isTesting?"\n":"\r");
						outErr.Flush();
					}
				}
			}
		}
		if (!isTesting && nNewBlocks) { outErr << "\tFound new transaction at block " << lastBlock << ". Importing...\n"; outErr.Flush(); }
		theAccount.lastBlock = lastBlock;

		// Write the data if we got new data
		SFInt32 newRecords = (theAccount.transactions.getCount() - origCount);
		if (newRecords)
		{
			outErr << "\tWriting " << newRecords << " new records to cache\n";
			SFArchive archive(FALSE, NO_SCHEMA);
			if (archive.Lock(cacheFilename, binaryWriteCreate, LOCK_CREATE))
			{
				theAccount.transactions.Sort(sortTransactionsForWrite);
				theAccount.Serialize(archive);
				archive.Close();

			} else
			{
				message = "Could not open file: '" + cacheFilename + "'\n";
				return options.cmdFile;
			}
		}
	}

	if (!isTesting)
	{
		double stop = vrNow();
		double timeSpent = stop-start;
		fprintf(stderr, "\tLoaded %ld total records in %f seconds\n", theAccount.transactions.getCount(), timeSpent);
		fflush(stderr);
	}

	return (options.cmdFile || theAccount.transactions.getCount()>0);
}
Ejemplo n.º 16
0
//---------------------------------------------------------------------------------------------------
SFBool CSlurperApp::Initialize(COptions& options, SFString& message)
{
	// This allows us to spin through these classes' list of fields
	CFunction::registerClass();
	CParameter::registerClass();
	CSlurp::registerClass();
	CTransaction::registerClass();

	// If this is the first time we've ever run, build the config file
	if (!establishFolders(config, version.toString()))
	{
		message = "Unable to create data folders at " + cachePath();
		return FALSE;
	}

	// Note this may not return if user chooses to exit
	api.checkKey(config);

	// If we are told to get the address from the rerun address, and the
	// user hasn't supplied one, do so...
	SFString addr = options.addr;
	if (addr.IsEmpty() && options.rerun)
		addr = config.GetProfileStringGH("SETTINGS", "rerun", EMPTY);

	// Ethereum addresses are case insensitive. Force all address to lower case
	// to avoid mismatches with Mist browser for example
	addr.MakeLower();

	// We can't run without an address...
	if (addr.IsEmpty())
	{
		message = "You must supply an Ethereum account or contract address. ";
		if (!options.rerun)
			message += "Use -r flag to rerun the most recently slurped address.";
		return FALSE;
	}

	if (options.wantsArchive)
	{
		if (options.archiveFile.IsEmpty() && options.name.IsEmpty())
			return usage("-a and -n may not both be empty. Specify either an archive file or a name. Quitting...");

		SFString fn = (options.name.Contains("/") ? options.name : options.exportFormat + "/" + options.name) + (options.name.Contains(".")?"":"." + options.exportFormat);
		SFFile file(fn);
		if (options.archiveFile.IsEmpty())
			options.archiveFile = file.getFullPath();
		ASSERT(options.output==NULL);
		options.output = fopen((const char*)options.archiveFile, asciiWriteCreate);
		if (!options.output)
			return usage("file '" + options.archiveFile + "' could not be opened. Quitting.");
		outScreen.setOutput(options.output);
	}
	
	// Save the address and name for later
	config.SetProfileString("SETTINGS", "rerun", addr);
	config.writeFile(version.toString());

	// Load per address configurations if any
	SFString customConfig = configPath("configs/"+addr+".conf");
	if (SFos::fileExists(customConfig) || !options.name.IsEmpty())
	{
		CConfig perAddr(NULL);
		perAddr.setFilename(customConfig);
		if (SFos::fileExists(customConfig))
		{
			perAddr.loadFile(customConfig);
			config.mergeConfig(&perAddr);
		}
		if (!options.name.IsEmpty())
		{
			perAddr.SetProfileString("SETTINGS", "name", options.name);
			perAddr.writeFile(version.toString());
		}
	}

    // Rerun will not reload the cache if it's already in memory
	if (theAccount.addr == addr)
		options.rerun = TRUE;

	// If we're not re-running, we're slurping and we need an empty transaction list
	if (!options.rerun)
	{
		theAccount.transactions.Clear();
		theAccount = CSlurp();
		nFunctions=0;
	}

	// We are ready to slurp
	theAccount.addr = addr;
	theAccount.loadABI();

	outErr << "\t" << "Slurping " << theAccount.addr << "\n";

	// Finished
	return TRUE;
}
Ejemplo n.º 17
0
iShaderProgram::CacheLoadResult csShaderGLCGCommon::LoadFromCache (
  iHierarchicalCache* cache, iBase* previous, iDocumentNode* node,
  csRef<iString>* failReason, csRef<iString>* tag,
  ProfileLimitsPair* cacheLimits)
{
  if (!cache) return iShaderProgram::loadFail;

  csRef<iShaderProgramCG> prevCG (scfQueryInterfaceSafe<iShaderProgramCG> (
    previous));

  csRef<iStringArray> allCachedPrograms;
  if ((programType == progVP) && prevCG.IsValid())
  {
    csShaderGLCGFP* prevFP = static_cast<csShaderGLCGFP*> (
      (iShaderProgramCG*)prevCG);
    csString tagStr ("CG");
    tagStr += prevFP->cacheLimits.ToString();
    if (failReason) failReason->AttachNew (
      new scfString ("paired cached programs not found"));
    allCachedPrograms.AttachNew (new scfStringArray);
    allCachedPrograms->Push (tagStr);
  }
  else
    allCachedPrograms = cache->GetSubItems ("/");

  if (!allCachedPrograms.IsValid() || (allCachedPrograms->GetSize() == 0))
  {
    if (failReason) failReason->AttachNew (
      new scfString ("no cached programs found"));
    return iShaderProgram::loadFail;
  }
  
  if (!GetProgramNode (node)) return iShaderProgram::loadFail;
  csRef<iDataBuffer> programBuffer = GetProgramData();
  CS::Utility::Checksum::MD5::Digest progHash = CS::Utility::Checksum::MD5::Encode (
    programBuffer->GetData(), programBuffer->GetSize());
  
  csArray<CachedShaderWrapper> cachedProgWrappers;
  for (size_t i = 0; i < allCachedPrograms->GetSize(); i++)
  {
    const char* tag = allCachedPrograms->Get (i);
    if ((tag[0] != 'C') || (tag[1] != 'G')) continue;

    CachedShaderWrapper wrapper;
    if (!wrapper.limits.FromString (tag+2)) continue;
    wrapper.name = tag;

    csString cachePath ("/");
    cachePath.Append (tag);
    csRef<iDataBuffer> cacheBuf = cache->ReadCache (cachePath);
    if (!cacheBuf.IsValid()) continue;
    
    csRef<iFile> cacheFile;
    cacheFile.AttachNew (new csMemFile (cacheBuf, true));
    wrapper.cacheFile = cacheFile;
  
    uint32 diskMagic;
    if (cacheFile->Read ((char*)&diskMagic, sizeof (diskMagic))
	!= sizeof (diskMagic)) continue;
    if (csLittleEndian::UInt32 (diskMagic) != cacheFileMagic)
      continue;
      
    CS::Utility::Checksum::MD5::Digest diskHash;
    if (cacheFile->Read ((char*)&diskHash, sizeof (diskHash))
	!= sizeof (diskHash)) continue;
    if (diskHash != progHash) continue;
    
    cachedProgWrappers.Push (wrapper);
  }
  
  if (cachedProgWrappers.GetSize() == 0)
  {
    if (failReason && !*failReason) failReason->AttachNew (
      new scfString ("all cached programs failed to read"));
    return iShaderProgram::loadFail;
  }
  
  cachedProgWrappers.Sort ();

  ProfileLimits currentLimits (
    (programType == progVP) ? shaderPlug->currentLimits.vp 
      : shaderPlug->currentLimits.fp);
  bool strictMatch = (programType == progVP) ? shaderPlug->strictMatchVP 
      : shaderPlug->strictMatchFP;
  const char* progTypeNode = 0;
  switch (programType)
  {
    case progVP: progTypeNode = "cgvp"; break;
    case progFP: progTypeNode = "cgfp"; break;
  }
  
  csString allReasons;
  bool oneReadCorrectly = false;
  ProfileLimits bestLimits (
    CS::PluginCommon::ShaderProgramPluginGL::Other,
    CG_PROFILE_UNKNOWN);
  bool bestLimitsSet = false;
  for (size_t i = cachedProgWrappers.GetSize(); i-- > 0;)
  {
    const CachedShaderWrapper& wrapper = cachedProgWrappers[i];
    const ProfileLimits& limits =
      (programType == progVP) ? wrapper.limits.vp : wrapper.limits.fp;

    if (!bestLimitsSet)
    {
      bestLimits = limits;
      bestLimitsSet = true;
    }
      
    if (strictMatch && (limits != currentLimits))
    {
      allReasons += wrapper.name;
      allReasons += ": strict mismatch; ";
      continue;
    }
  
    bool profileSupported =
      (shaderPlug->ProfileNeedsRouting (limits.profile)
        && shaderPlug->IsRoutedProfileSupported (limits.profile))
      || cgGLIsProfileSupported (limits.profile);
    if (!profileSupported)
    {
      allReasons += wrapper.name;
      allReasons += ": Profile unsupported; ";
      continue;
    }
    
    if ((limits.vendor != currentLimits.vendor)
        && (limits.vendor != CS::PluginCommon::ShaderProgramPluginGL::Other))
    {
      allReasons += wrapper.name;
      allReasons += ": vendor mismatch; ";
      continue;
    }
    
    bool limitsSupported = currentLimits >= limits;
    if (!limitsSupported)
    {
      allReasons += wrapper.name;
      allReasons += ": Limits exceeded; ";
      continue;
    }
    
    iFile* cacheFile = wrapper.cacheFile;
    
    {
      uint32 diskState;
      if (cacheFile->Read ((char*)&diskState, sizeof (diskState))
	  != sizeof (diskState)) continue;
      if (csLittleEndian::UInt32 (diskState) != cpsValid)
      {
        oneReadCorrectly = true;
        continue;
      }
    }
  
    
    description = CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile);
    
    bool breakFail = false;
    csRef<iDocumentNode> cgNode = node->GetNode (progTypeNode);
    if (!cgNode.IsValid()) continue;
    csRef<iDocumentNodeIterator> nodes = cgNode->GetNodes();
    while(nodes->HasNext() && !breakFail)
    {
      csRef<iDocumentNode> child = nodes->Next();
      if(child->GetType() != CS_NODE_ELEMENT) continue;
      const char* value = child->GetValue ();
      csStringID id = xmltokens.Request (value);
      switch(id)
      {
	case XMLTOKEN_VARIABLEMAP:
	  if (!ParseVmap (child))
	    breakFail = true;
	  break;
	case XMLTOKEN_CLIP:
	  if (!ParseClip (child))
	    breakFail = true;
	  break;
	default:
	  /* Ignore unknown nodes. Invalid nodes would have been caught
	     by the first (not from cache) parsing */
	  break;
      }
    }
    if (breakFail) continue;
    
    csString objectCodeCachePathArc =
      CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile);
    if (objectCodeCachePathArc.IsEmpty()) continue;
    csString objectCodeCachePathItem =
      CS::PluginCommon::ShaderCacheHelper::ReadString (cacheFile);
    if (objectCodeCachePathItem.IsEmpty()) continue;
    
    ProgramObjectID progId (objectCodeCachePathArc, objectCodeCachePathItem);
    ProgramObject programObj;
    //if (!LoadObjectCodeFromCompileCache (limits, cache))
    if (!shaderPlug->progCache.LoadObject (progId, programObj))
      continue;
    
    oneReadCorrectly = true;
    if (program)
    {
      cgDestroyProgram (program);
      program = 0;
    }
    
    if (!programObj.IsValid()) continue;
    
    cgGetError(); // Clear error
    program = cgCreateProgram (shaderPlug->context, 
      CG_OBJECT, programObj.GetObjectCode(), limits.profile, 0, 0);
    if (!program) continue;
    CGerror err = cgGetError();
    if (err != CG_NO_ERROR)
    {
      const char* errStr = cgGetErrorString (err);
      shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING,
	"Cg error %s", errStr);
      continue;
    }
    programProfile = limits.profile;
    programPositionInvariant = programObj.GetFlags() & ProgramObject::flagPositionInvariant;
    unusedParams = programObj.GetUnusedParams();
    
    ClipsToVmap();
    GetParamsFromVmap();

    bool doLoadToGL = !shaderPlug->ProfileNeedsRouting (programProfile);

    cgGetError(); // Clear error
    if (doLoadToGL)
    {
      cgGLLoadProgram (program);
    }
    else
    {
      cgCompileProgram (program);
    }
    
    shaderPlug->PrintAnyListing();
    err = cgGetError();
    if ((err != CG_NO_ERROR)
      || (doLoadToGL && !cgGLIsProgramLoaded (program)))
    {
      //if (shaderPlug->debugDump)
	//DoDebugDump();
	
      const char* errStr = cgGetErrorString (err);
      shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING,
	"Cg error %s", errStr);
  
      if (shaderPlug->doVerbose
	  && (((programType == progVP) && (programProfile >= CG_PROFILE_ARBVP1))
	    || ((programType == progFP) && (programProfile >= CG_PROFILE_ARBFP1))))
      {
	const char* err = (char*)glGetString (GL_PROGRAM_ERROR_STRING_ARB);
	shaderPlug->Report (CS_REPORTER_SEVERITY_WARNING,
	  "OpenGL error string: %s", err);
      }
  
      shaderPlug->SetCompiledSource (0);
      continue;
    }
    
    GetPostCompileParamProps ();
    
    if (shaderPlug->debugDump)
      DoDebugDump();
      
    tag->AttachNew (new scfString (wrapper.name));

    if (cacheLimits != 0)
      *cacheLimits = wrapper.limits;
    
    bool loaded = !shaderPlug->ProfileNeedsRouting (programProfile)
      || LoadProgramWithPS1 ();
    if (loaded && (bestLimits < currentLimits))
    {
      /* The best found program is worse than the current limits, so pretend
         that the shader program failed (instead just being 'invalid') -
         that will make xmlshader try to load the program from scratch,
         ie with current limits, which may just work. */
      if (failReason)
        failReason->AttachNew (new scfString ("Provoking clean load with current limits"));
      return iShaderProgram::loadFail;
    }
    return loaded ? iShaderProgram::loadSuccessShaderValid
        : iShaderProgram::loadSuccessShaderInvalid;
  }
  
  if (oneReadCorrectly)
  {
    if (bestLimits < currentLimits)
    {
      /* The 'invalid' programs may compile with the current limits -
         so again, provoke clean load */
      if (failReason)
        failReason->AttachNew (new scfString ("Provoking clean load with current limits"));
      return iShaderProgram::loadFail;
    }
    else
      return iShaderProgram::loadSuccessShaderInvalid;
  }
  else
    return iShaderProgram::loadFail;
}
Ejemplo n.º 18
0
int kbc()
{
  

  char ac[1024];

  
  /*
  sprintf(ac, "c:\\basic\\examples\\kbasic\\sub\\sub2.kbasic");
  sprintf(ac, "c:\\basic\\examples\\kbasic\\important\\type.kbasic");
  sprintf(ac, "c:\\basic\\examples\\kbasic\\examples\\array.kbasic");
  sprintf(ac, "c:\\basic\\examples\\kbasic\\keyword\\goto.kbasic");
  */

  bool bSilent = false;
  bool bDebug = false;
  bool bUseCache = false;   
  char *acLicense = "";
  char *acProjectName = "";
  char *acLogin = "";  
  char *acProjectType = "";
  char *acTranslation = "";
  char *acSQL = "";
  char *acMenu = "";
  
  sLogin = "";
  sProjectName = "";
  sProjectType = "";
  sTranslation = "";
  sSQL = "";
  sMenu = "";

  int i = 1;
  for (; i < MAIN_argc; i++){

    const char *ac = MAIN_argv[i];
   
    if (utility::my_stricmp(ac, "-Silent") == 0) bSilent = true;
    else if (utility::my_stricmp(ac, "-Debug") == 0) bDebug = true;
    else if (utility::my_stricmp(ac, "-UseCache") == 0) bUseCache = true;
    
    else if (utility::my_strnicmp(ac, "-License", 8) == 0){
      acLicense = (char *) ac + 8;
      if (acLicense == 0) acLicense = "";
      /*
    } else if (utility::my_strnicmp(ac, "-ProjectName", 12) == 0){
       

      acProjectName = (char *) ac + 12;
         //CONSOLE printError(ac);
       //  CONSOLE printError("\n");
      if (acProjectName == 0) sProjectName = ""; else sProjectName = acProjectName; 
*/
    } else if (utility::my_strnicmp(ac, "-Login", 6) == 0){
       
      acLogin = (char *) ac + 6;
      if (acLogin == 0) sLogin = ""; else sLogin = acLogin; 

    } else if (utility::my_strnicmp(ac, "-ProjectType", 12) == 0){
       

      acProjectType = (char *) ac + 12;
         //CONSOLE printError(ac);
       //  CONSOLE printError("\n");
      if (acProjectType == 0) sProjectType = ""; else sProjectType = acProjectType; 
        //  CONSOLE printError("2222222222\n");


    } else if (utility::my_strnicmp(ac, "-Translation", 12) == 0){


      acTranslation = (char *) ac + 12;
      if (acTranslation == 0) sTranslation = ""; else sTranslation = acTranslation; 
    
    } else if (utility::my_strnicmp(ac, "-SQL", 4) == 0){


      acSQL = (char *) ac + 4;
      if (acSQL == 0) sSQL = ""; else sSQL = acSQL; 
     // printf(acSQL);
    
    } else if (utility::my_strnicmp(ac, "-Menu", 5) == 0){

      acMenu = (char *) ac + 5;
      if (acMenu == 0) sMenu = ""; else sMenu = acMenu;      
                
    }
    else break;
  }

  /*
  bSilent = false;
  bDebug = false;
  bUseCache = true;   
  sProjectName = "KBasic Default Project";
  sProjectType = "With Forms MainWindow (you must have myMenuBar created)";
  sTranslation = "&Window;Help;C&ontents;A&bout;Cl&ose;Close &All;&Tile;&Cascade;Arrange &icons;Ne&xt;Pre&vious;";
  sSQL = "QPSQL;localhost;test;postgres;test";

*/

 // if (bUseCache) printf("!!!!!");


 // sprintf(ac, "");
  //if (MAIN_argc > 1 && i <= MAIN_argc) sprintf(ac, "%s", MAIN_argv[i]);
  
  //sprintf(ac, "C:/kbasic16/kbide/examples/kbasic/builtin/__class__.kbasic");

  //if (utility::my_stricmp(ac, "") == 0) return 0;

  //bUseCache = false;
  {
    sKBasicPath = MAIN_argv[0];  
    bool bDebug = false;
#ifdef WINDOWS // HIDE
    bDebug = sKBasicPath.contains("Debug"); // HIDE
#endif // HIDE

    sKBasicPath = sKBasicPath.replace("\\", "/");
#ifdef WINDOWS // HIDE
    sKBasicPath = sKBasicPath.replace("/Debug", "", false); // HIDE
    sKBasicPath = sKBasicPath.replace("/Release", "", false); // HIDE
    sKBasicPath = sKBasicPath.replace(".exe", "", false); // HIDE
#endif // HIDE

    if (bDebug){
      int n = sKBasicPath.findRev("/");
      if (n >= 0) sKBasicPath = sKBasicPath.left(n);

      sKBasicPath = sKBasicPath.replace("kbc", "kbide/ide/cache");
    } else {
      sKBasicPath = sKBasicPath.replace("kbc", "ide/cache");
    }
    
    if (sKBasicPath.isEmpty()) return 0;
  }

  // if (checkLicense(acLicense) == false) return 0;


//  checkSerialNo();

	textbuffer *myTextbuffer = new textbuffer(); // needed to truncate big input strings or zero terminate them
 
  cache *my_cache = new cache();
  token *myToken = new token();
	scanner *myScanner = new scanner(myToken, my_cache);

	char *acText;
  bool b = true;

  if (utility::readSourceFile(&acText, cachePath("project.name").ascii(), myTextbuffer)){
    acText = utility::eatUTF16DOM(acText);
    sProjectName = acText;
  }

//  if (b && (b = utility::readSourceFile(&acText, "c:/kbasic16/kbide/ide/cache/C__kbasic16_kbide_examples_kbasic_builtin___class__.kbasic.scanner", myTextbuffer))){}


  { // delete runtime.parser file
    XString m = cachePath("runtime.parser");
    //CONSOLE printError(cachePath("runtime.parser").ascii());
    XFile f(m.ascii());
    if (!f.open(Truncate)){
      CONSOLE printError("Could not create runtime parser file: ");
      CONSOLE printError(m.ascii());
      b = false;
    } else {
      f.close();
    }
  }

  XString m = cachePath("compiler.output");
  finfo.setName(m.ascii());  
  char acInfo[1024];

  //if (utility::my_stricmp(ac, "") == 0)
  if (b){


    {      
      if (!finfo.open(Truncate)){
        CONSOLE printError("Could not write compiler output file:");
        CONSOLE printError(m.ascii());
        b = false;
      } 
    }
    finfo.close();

    XString sFiles = "";

    if (b){ // read compiler.input file
      XString m = cachePath("compiler.input");
      XFile f(m.ascii());
      if (!f.open(ReadOnly)){
        CONSOLE printError("Could not read compiler input file:");
        CONSOLE printError(m.ascii());
        b = false;
      } else {

        int i = 0;
        char acBuffer[10240];
        int nSize = f.size();
        while (i < nSize && (i = f.readBlock(acBuffer, 10240)) > 0){  
          acBuffer[i] = 0;

          const char *ac = utility::eatUTF16DOM(acBuffer);
          sFiles += ac;
        }
        //sFiles = sFiles.appendNull();
        
        f.close();
      }
    }

    if (my_cache){
      my_cache->setMode(bSilent, bDebug); // important, setting right file name for caching

      // sort input files so that non-cached files are at the end, otherwise IDs of classes will collide
      if (bUseCache){

        #define MAX_INPUTFILES 512

        struct inputfile {
          XString sFilename;
          int nDate;
        };
        inputfile files[MAX_INPUTFILES];

        int nCounter = 0;
        
  
        int n = 0;
        int n0 = 0;

        bool bFirst = true;
        do {
          if (nCounter >= MAX_INPUTFILES){
            nCounter = 0;
            CONSOLE printError("too many input files to compile (> 512)");
            break;
          }

          n = sFiles.find("\n", n);
          XString s = sFiles.mid(n0, n >= 0 ? n - n0 : sFiles.length());
          if (n == -1 & bFirst == false) break;

          XFileInfo k(s.ascii());
          int r = k.lastModified();

          files[nCounter].sFilename = s;
          files[nCounter].nDate = r;
          nCounter++;
          
          n0 = n + 1;
          n++;

          if (bFirst) bFirst = false;

        } while (true);

        bool bRedo = false;
        do {
          bRedo = false;

          for (int i = 0; i < nCounter; i++){

            if (i + 1 < nCounter){
              if (files[i].nDate > files[i + 1].nDate){
                inputfile file = files[i + 1];
                files[i + 1] = files[i];
                files[i] = file;

                bRedo = true;
                break;
              }
            }

          }
        } while (bRedo);

        sFiles = "";
        for (int i = 0; i < nCounter; i++){
          sFiles = sFiles + files[i].sFilename + "\n";          
        }
      }
        
    }



    
    if (finfo.open(Truncate)){ sprintf(acInfo, "Scanning..."); finfo.writeBlock(acInfo, strlen(acInfo)); finfo.close(); }
    
    if (finfo.open(Truncate)){ sprintf(acInfo, "%s", cachePath("default.kbasic").ascii()); finfo.writeBlock(acInfo, strlen(acInfo)); finfo.close(); }

    if (b && (b = utility::readSourceFile(&acText, cachePath("default.kbasic").ascii(), myTextbuffer))){

      acText = utility::eatUTF16DOM(acText);
    }

    if (b && (b = myScanner->scan(acText, (char *) cachePath("default.kbasic").ascii(), bSilent, bDebug, false, bUseCache))){} // filename

    if (b){
      int n = 0;
      int n0 = 0;

      bool bFirst = true;
      do {
        n = sFiles.find("\n", n);
        XString s = sFiles.mid(n0, n >= 0 ? n - n0 : sFiles.length());
        if (n == -1 & bFirst == false) break;
        bFirst = false;
        n0 = n + 1;
        n++;
        
        const char *ac99 = s.ascii();

        if (b && (b = utility::readSourceFile(&acText, ac99, myTextbuffer))){
          acText = utility::eatUTF16DOM(acText);
        }


        XString sFile = ac99;

        if (sFile.endsWith(".kbasic_form")){
     
          XString sLanguage = "";
          XString sExt = getFilenameExtension(sFile);
          XString q = sFile.left(sFile.length() - sExt.length() - 1);

          if (q.count(".") > 1){
            sLanguage = getFilenameExtension(q);
            if (sLanguage.contains("/") || sLanguage.contains("\\")){
              sLanguage = "";
            }
          }
        
          if (sLanguage.length() == 0){
   //       if (!sTranslation.contains(sLanguage, false)){
            acText = prepareSourceCode(ac99, acText, sFile); 
          } else {
/*
            char ac[1111];
            sprintf(ac, "omit %s %s", sFile.ascii(), sLanguage.ascii());
            CONSOLE printError(ac);*/
            continue;
//            acText = "";
          }

        } else if (sFile.endsWith(".kbasic_menubar")){

          XString sLanguage = "";
          XString sExt = getFilenameExtension(sFile);
          XString q = sFile.left(sFile.length() - sExt.length() - 1);

          if (q.count(".") > 1){
            sLanguage = getFilenameExtension(q);
            if (sLanguage.contains("/") || sLanguage.contains("\\")){
              sLanguage = "";
            }
          }
        
          if (sLanguage.length() == 0){
   //       if (!sTranslation.contains(sLanguage, false)){
            acText = prepareSourceCode(ac99, acText, sFile); 
          } else {
            continue;
//            acText = "";
          }

        } else if (sFile.endsWith(".kbasic_toolbar")){

          XString sLanguage = "";
          XString sExt = getFilenameExtension(sFile);
          XString q = sFile.left(sFile.length() - sExt.length() - 1);

          if (q.count(".") > 1){
            sLanguage = getFilenameExtension(q);
            if (sLanguage.contains("/") || sLanguage.contains("\\")){
              sLanguage = "";
            }
          }
        
          if (sLanguage.length() == 0){
   //       if (!sTranslation.contains(sLanguage, false)){
            acText = prepareSourceCode(ac99, acText, sFile); 
          } else {

            continue;
//            acText = "";
          }

        } else if (sFile.endsWith(".kbasic_report")){

          XString sLanguage = "";
          XString sExt = getFilenameExtension(sFile);
          XString q = sFile.left(sFile.length() - sExt.length() - 1);

          if (q.count(".") > 1){
            sLanguage = getFilenameExtension(q);
            if (sLanguage.contains("/") || sLanguage.contains("\\")){
              sLanguage = "";
            }
          }
        
          if (sLanguage.length() == 0){
   //       if (!sTranslation.contains(sLanguage, false)){
            acText = prepareSourceCode(ac99, acText, sFile); 
          } else {
            continue;
            //acText = "";
          }

        } else if (sFile.endsWith(".kbasic_module")){
#ifdef WINDOWS // HIDE
  if (sFile.endsWith(".linux.kbasic_module")) continue; // HIDE
  if (sFile.endsWith(".mac.kbasic_module")) continue; // HIDE
#elif defined(MAC) // HIDE
  if (sFile.endsWith(".linux.kbasic_module")) continue; // HIDE
  if (sFile.endsWith(".windows.kbasic_module")) continue; // HIDE
#elif defined(LINUX) // HIDE
  if (sFile.endsWith(".windows.kbasic_module")) continue; // HIDE
  if (sFile.endsWith(".mac.kbasic_module")) continue; // HIDE
#endif // HIDE

          // UNHIDE if (sFile.endsWith(".windows.kbasic_module")) continue;
          // UNHIDE if (sFile.endsWith(".mac.kbasic_module")) continue;

          acText = prepareSourceCode(ac99, acText, sFile);
        } else if (sFile.endsWith(".kbasic_class")){
#ifdef WINDOWS // HIDE
  if (sFile.endsWith(".linux.kbasic_class")) continue; // HIDE
  if (sFile.endsWith(".mac.kbasic_class")) continue; // HIDE
#elif defined(MAC) // HIDE
  if (sFile.endsWith(".linux.kbasic_class")) continue; // HIDE
  if (sFile.endsWith(".windows.kbasic_class")) continue; // HIDE
#elif defined(LINUX) // HIDE
  if (sFile.endsWith(".windows.kbasic_class")) continue; // HIDE
  if (sFile.endsWith(".mac.kbasic_class")) continue; // HIDE
#endif // HIDE

          // UNHIDE if (sFile.endsWith(".windows.kbasic_class")) continue; // HIDE
          // UNHIDE if (sFile.endsWith(".mac.kbasic_class")) continue; // HIDE

          acText = prepareSourceCode(ac99, acText, sFile);
        } else if (sFile.endsWith(".kbasic")){
#ifdef WINDOWS // HIDE
  if (sFile.endsWith(".linux.kbasic")) continue; // HIDE
  if (sFile.endsWith(".mac.kbasic")) continue; // HIDE
#elif defined(MAC) // HIDE
  if (sFile.endsWith(".linux.kbasic")) continue; // HIDE
  if (sFile.endsWith(".windows.kbasic")) continue; // HIDE
#elif defined(LINUX) // HIDE
  if (sFile.endsWith(".windows.kbasic")) continue; // HIDE
  if (sFile.endsWith(".mac.kbasic")) continue; // HIDE
#endif // HIDE
  
  // UNHIDEif (sFile.endsWith(".windows.kbasic")) continue;
  // UNHIDEif (sFile.endsWith(".mac.kbasic")) continue;

        }
        if (finfo.open(Truncate)){ finfo.writeBlock((void *) ac99, strlen(ac99)); finfo.close(); }
        if (b && (b = myScanner->scanAdditional(acText, (char *) ac99, bSilent, bDebug, bUseCache))){} // filename
        if (!b) break;
      } while (true);
    }

    if (b) {
      if (finfo.open(Truncate)){ sprintf(acInfo, "%s", cachePath("default2.kbasic").ascii()); finfo.writeBlock(acInfo, strlen(acInfo)); finfo.close(); }

      if (b && (b = utility::readSourceFile(&acText, cachePath("default2.kbasic").ascii(), myTextbuffer))){

        acText = utility::eatUTF16DOM(acText);
      }
      if (b && (b = myScanner->scanAdditional(acText, (char *) cachePath("default2.kbasic").ascii(), bSilent, bDebug, bUseCache))){} // filename
    }

    myScanner->addEOFToken();
/*
  } else {
    if (b && (b = utility::readSourceFile(&acText, ac, myTextbuffer))){}
    if (b && (b = myScanner->scan(acText, ac, bSilent, bDebug, true, bUseCache))){} // filename*/
  }




  //delete myToken;

//	if (utility::readSourceFile(&acText, ac, myTextbuffer)){
//		if (myScanner->scanAdditional(acText, filename)){

  

  if (b){

    if (finfo.open(Truncate)){ sprintf(acInfo, "Parsing..."); finfo.writeBlock(acInfo, strlen(acInfo)); finfo.close(); }

		pcode *myPcode = new pcode("");
  //  myPcode->setInfoWindow(myInfoConsole);

		parser *myParser = new parser(myPcode, my_cache);
  //  myParser->setInfoWindow(myInfoConsole);

    
    //bool b = false;

    /*
         if (strcmp(acDir, "examples\\veryoldbasic\\") == 0 && (b = myParser->parseVeryOldBasic(myToken, bSilent, bDebug))){}
    else if (strcmp(acDir, "examples\\oldbasic\\") == 0 && (b = myParser->parseOldBasic(myToken, bSilent, bDebug))){}
    else if (strcmp(acDir, "examples\\kbasic\\") == 0 && (b = myParser->parseKBasic(myToken, bSilent, bDebug))){}
    else */
    //bUseCache = false;

  //  CONSOLE printError("myParser->parseKBasic(myToken, bSilent, bDebug, bUseCache);");
    b = myParser->parseKBasic(myToken, bSilent, bDebug, bUseCache);

		if (b){
  //    CONSOLE printError("b=true");

      XString m;// = path(sKBasicPath);
      m = cachePath("runtime.pcode");

      XFile f(m.ascii());
      if (!f.open(Truncate)){
        CONSOLE printError("Could not create runtime pcode file");
        b = false;
      } else {
        //const char *aa = myPcode->ba->getMem();
        int n = myPcode->ba->getSize();
        n = f.writeBlock (myPcode->ba->getMem(), n);

       
        f.close();
      }

    }


		delete myParser;
		delete myPcode;
   

	}	

  

  delete myScanner;
	delete myToken;
	delete myTextbuffer;
  delete my_cache;

	{

    XString m;
    m = cachePath("compiler.done");

    XFile f(m.ascii());
    if (!f.open(Truncate)){
      CONSOLE printError("Could not create runtime done file");
      b = false;
    } else {     
      f.close();
    }
  
  }

  return b ? 0 : -1;
		
}