Beispiel #1
0
Model::Root::Ptr ProjectImpl::parseFile(const QString& fileName) {

    LexicalAnalyzer::Ptr la = analyze(fileName);
    if (!hasErrors()) {
        Q_ASSERT(la);

        Model::Root::Ptr model = parseStream(la->tokenStream());
        if (model) {

            if (testOption(optDumpCodeModel)) {
                QFileInfo fi(fileName);
                QString modelFileName =
                        fi.absolutePath() %
                        fi.completeBaseName() %
                        QLatin1Literal(".pmodel");

                if (!model->exportModel(modelFileName)) {
                    errors()->emitError("Could not export model for file.", fileName);
                }
            }

            return model;
        }

    }

    return NULL;
}
Beispiel #2
0
void loadTexture(char * fileName, int textureID) {
    FILE *fp;
    int i, j, c;
    
    if ((fp = fopen(fileName, "r")) == 0) {
        printf("Error, failed to find the \"%s\".\n", fileName);
        exit(0);
    }
    
    parseStream(fp);
    
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glBindTexture(GL_TEXTURE_2D, texNames[textureID]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, colourMap);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    
    fclose(fp);
}
Beispiel #3
0
int
main (int argc, char* argv[])
{
    Node *result;

    READ_OPTIONS_AND_INIT("testvisit", "Run visit function on input for testing.");

    // read from terminal
    if (getStringOption("input.sql") == NULL)
    {
        result = parseStream(stdin);

        DEBUG_LOG("Address of returned node is <%p>", result);
        ERROR_LOG("PARSE RESULT FROM STREAM IS <%s>", beatify(nodeToString(result)));
    }
    // parse input string
    else
    {
        result = parseFromString(getStringOption("input.sql"));

        DEBUG_LOG("Address of returned node is <%p>", result);
        ERROR_LOG("PARSE RESULT FROM STRING IS:\n%s", nodeToString(result));
        ERROR_LOG("PARSE RESULT FROM STRING IS:\n%s", beatify(nodeToString(result)));
    }


    void *state = NULL;
    visitTheNode(result, state);

    return shutdownApplication();
}
Vic2::Relations::Relations(const std::string& theTag, std::istream& theStream):
	tag(theTag)
{
	registerKeyword(std::regex("value"), [this](const std::string& unused, std::istream& theStream){
		commonItems::singleInt valueInt(theStream);
		value = valueInt.getInt();
	});
	registerKeyword(std::regex("level"), [this](const std::string& unused, std::istream& theStream){
		commonItems::singleInt levelInt(theStream);
		level = levelInt.getInt();
	});
	registerKeyword(std::regex("military_access"), [this](const std::string& unused, std::istream& theStream){
		commonItems::singleString stateString(theStream);
		militaryAccess = (stateString.getString() == "yes");
	});
	registerKeyword(std::regex("last_send_diplomat"), [this](const std::string& unused, std::istream& theStream){
		commonItems::singleString dateString(theStream);
		lastSentDiplomat = date(dateString.getString());
	});
	registerKeyword(std::regex("last_war"), [this](const std::string& unused, std::istream& theStream){
		commonItems::singleString dateString(theStream);
		lastWar = date(dateString.getString());
	});
	registerKeyword(std::regex("truce_until"), [this](const std::string& unused, std::istream& theStream){
		commonItems::singleString dateString(theStream);
		truceUntil = date(dateString.getString());
	});
	registerKeyword(std::regex("[A-Za-z0-9_]+"), commonItems::ignoreItem);

	parseStream(theStream);
}
Beispiel #5
0
int
main (int argc, char* argv[])
{
    Node *result;
    Node *qoModel;
    char *sql;

    READ_OPTIONS_AND_INIT("testtranslate", "Run all stages on input except provenance rewrite and output rewritten SQL code.");

    // read from terminal
    if (getStringOption("input.sql") == NULL)
    {
        result = parseStream(stdin);

        DEBUG_LOG("Address of returned node is <%p>", result);
        ERROR_LOG("PARSE RESULT FROM STREAM IS <%s>", beatify(nodeToString(result)));
    }
    // parse input string
    else
    {
        result = parseFromString(getStringOption("input.sql"));

        DEBUG_LOG("Address of returned node is <%p>", result);
        ERROR_LOG("PARSE RESULT FROM STRING IS:\n%s", beatify(nodeToString(result)));
    }

    qoModel = translateParse(result);
    INFO_LOG("TRANSLATION RESULT FROM STRING IS:\n%s", beatify(nodeToString(qoModel)));
    ERROR_LOG("SIMPLIFIED OPERATOR TREE:\n%s", operatorToOverviewString(qoModel));

    sql = serializeOperatorModel(qoModel);
    ERROR_LOG("SERIALIZED SQL:\n%s", sql);

    return shutdownApplication();
}
Beispiel #6
0
void Packed::poll(bool can_read)
{
    if (!can_read) return;

    m_socket.peek();

    std::streamsize count;

    while ((count = m_socket.rdbuf()->in_avail()) > 0) {

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

	    int next = m_socket.rdbuf()->sbumpc();

	    switch (m_state.top())
	    {
	        case PARSE_STREAM:	    parseStream(next); break;
	        case PARSE_MAP:		    parseMap(next); break;
	        case PARSE_LIST:	    parseList(next); break;
	        case PARSE_MAP_BEGIN:	    parseMapBegin(next); break;
	        case PARSE_LIST_BEGIN:	    parseListBegin(next); break;
	        case PARSE_INT:		    parseInt(next); break;
	        case PARSE_FLOAT:	    parseFloat(next); break;
	        case PARSE_STRING:	    parseString(next); break;
	        case PARSE_NAME:	    parseName(next); break;
	    }
        }
    }
}
std::pair<bool, std::string>
SimForth::interpreteCell(ASpreadSheetCell &cell)
{
  m_err_stream = 0;
  STREAM.loadString(cell.formulae(), cell.name());

  Cell32 value;
  std::pair<bool, std::string> res = parseStream();
  if (true == res.first)
    {
      try
        {
          DPOP(value);
          isStackUnderOverFlow(forth::DataStack);
          cell.value(value);
        }
      catch (ForthException const& e)
        {
          res = std::make_pair(false, e.message());
        }
    }

  std::cout << "interpretCell '" << cell.formulae() << "': "
            << res.second << std::endl;
  if (true == res.first)
    {
      std::cout << "Result " << value << std::endl;
    }
  return res;
}
Beispiel #8
0
void dl_vlive_live(std::string url)
{
	streamInfo currentInfo;
	vidUrlInfo currentLiveInfo;
	m3u8Info currentMediaInfo;
	std::string v_title;
	std::string strUrl;
	int cnt = 0;
	float time = 0;

	getStreamInfo(retrievePage((char *)url.c_str()), &currentInfo, NULL, TYPE_VLIVE);
	getStreamInfo(retrievePage((char *)url.c_str()), NULL, &currentLiveInfo, TYPE_VLIVE_LIVE);
	for (int i = 0; i <= currentLiveInfo.num_list; i++)
		modifyUrl(&currentLiveInfo.url[i], TYPE_VLIVE_LIVE);
	printLine(3);
	getline(cin, v_title);
	printLine(5);
	while (strcmp(currentInfo.v_stat.c_str(), "LIVE_END") != 0)
	{
		parseStream(retrievePage((char*)currentLiveInfo.url[currentLiveInfo.num_list].c_str()), &currentMediaInfo);
		for (int i = 0; i <= currentMediaInfo.list_num; i++)
		{
			strUrl = "http://vlive.hls.edgesuite.net/" + parseUrl(currentLiveInfo.url[currentLiveInfo.num_list]) + currentMediaInfo.fname[i];
			retrieveFileFromUrl(strUrl, v_title, TYPE_VLIVE_LIVE, cnt, &time);
			std::this_thread::sleep_for(std::chrono::milliseconds((int)(currentMediaInfo.sec_sleep[i] - time) - 250));
			cnt++;
		}
		getStreamInfo(retrievePage((char *)url.c_str()), &currentInfo, NULL, TYPE_VLIVE);
	}
	cout << v_title;
	printLine(6);
}
Beispiel #9
0
bool parsepdf(const char* filename) {
  PoDoFo::PdfVecObjects objects;
  PoDoFo::PdfParser parser(&objects, filename);
  PoDoFo::TIVecObjects it = objects.begin();
  bool result = false;
  do {
    PoDoFo::PdfObject *obj = (*it);
#if (PODOFO_VERSION_MAJOR > 0) || (PODOFO_VERSION_MINOR > 8) || (PODOFO_VERSION_PATCH >= 3)
    if (obj->HasStream() && (obj->GetObjectLength(PoDoFo::ePdfWriteMode_Compact) > 10000)) {
#else
    if (obj->HasStream() && (obj->GetObjectLength() > 10000)) {
#endif
        PoDoFo::PdfStream *stream = obj->GetStream();
        char *buffer;
        PoDoFo::pdf_long bufferLen;
        stream->GetFilteredCopy(&buffer, &bufferLen);
        //std::cerr << "Buffer length : " << bufferLen << std::endl;
        if (bufferLen > 1000)
            result = parseStream(buffer, bufferLen);
        free(buffer);
    }
    it++;
  } while (it != objects.end());
  return result;
}

int main(int argc, char** argv) {

  if (argc != 2) {
      std::cerr << "ERROR: wrong number of argument" << std::endl;
      return -1;
  } else {
      parsepdf(argv[1]);
  }
}
	colonialRegion::colonialRegion(std::istream& theStream)
	{
		registerKeyword(std::regex("color"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::Color unusedColor(theStream);
		});
		registerKeyword(std::regex("tax_income"), commonItems::ignoreObject);
		registerKeyword(std::regex("native_size"), commonItems::ignoreObject);
		registerKeyword(std::regex("native_ferocity"), commonItems::ignoreObject);
		registerKeyword(std::regex("native_hostileness"), commonItems::ignoreObject);
		registerKeyword(std::regex("trade_goods"), commonItems::ignoreObject);
		registerKeyword(std::regex("culture"), commonItems::ignoreObject);
		registerKeyword(std::regex("religion"), commonItems::ignoreObject);
		registerKeyword(std::regex("names"), commonItems::ignoreObject);
		registerKeyword(std::regex("provinces"), [this](const std::string& unused, std::istream& theStream)
			{
				auto equals = getNextToken(theStream);
				commonItems::intList theProvinces(theStream);
				auto provincesVector = theProvinces.getInts();
				std::for_each(provincesVector.begin(), provincesVector.end(), [this](const int& province)
					{
						provinces.insert(province);
					}
				);
			}
		);

		parseStream(theStream);
	}
Beispiel #11
0
CppCompoundPtr CppParser::parseFile(const std::string& filename)
{
  auto stm         = readFile(filename);
  auto cppCompound = parseStream(stm.data(), stm.size());
  if (!cppCompound)
    return cppCompound;
  cppCompound->name(filename);
  return cppCompound;
}
Beispiel #12
0
void runNrlIndexFromStream(bt *btr, uchar *stream, d_l_t *nrlind, int itbl) {
    aobj akey;
    convertStream2Key(stream, &akey, btr);
    void *rrow = parseStream(stream, btr);
    /* create command and run it */
    sds cmd    = genNRL_Cmd(btr, nrlind, &akey, NULL, NULL, rrow, itbl);
    //printf("run_nri: cmd: %s\n", cmd);
    runCmdInFakeClient(cmd);
    sdsfree(cmd);                                        /* DESTROYED 016 */
    releaseAobj(&akey);
}
  /**
   *
   * This function will throw an IllegalArgumentException if the file contents cannot be multibyte decoded.
   */
  void PropertiesConfiguration::load(const String &file) {
    // std::clog << "Loading properties file: " << file << std::endl;
    std::ifstream input(file.c_str(), std::ifstream::in);

    // fail() catches File Not Found, bad() does not.
    ASSERT(!input.fail());
    if (input.fail())
      throw FileNotFoundException("Failed to open file for read: " + file);

    parseStream(input);
  }
Beispiel #14
0
bool ossimApplanixEOFile::parseFile(const ossimFilename& file)
{
   bool result = false;
   
   std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->
      createIstream(file, std::ios_base::in);
      
   if ( in )
   {
      result = parseStream( *in );
   }

   return result;
}
ConfigErrorCode Config::parseFile(const char *fileName)
{
   FILE *stream = fopen(fileName, "r");
   if (stream == NULL) {
      if (errno == ENOENT || errno == ENOTDIR)
         return setErrorCode(kConfigFileMissingErr);
      else if (errno == EACCES)
         return setErrorCode(kConfigFileNoAccessErr);
      return setErrorCode(kConfigOpenFileErr);
   }
   ConfigErrorCode status = parseStream(stream);
   if (status == kConfigParseStreamErr)
      status = setErrorCode(kConfigParseFileErr);
   fclose(stream);
   return status;
}
static bool streamToBTEntry(uchar *stream, btSIter *siter, bt_n *x, int i) {
	if (!stream) return 0;
	if (i < 0) i = 0;
	convertStream2Key(stream, siter->be.key, siter->x.btr);
	siter->be.val    = parseStream(stream, siter->x.btr);
	bool  gost       = IS_GHOST(siter->x.btr, siter->be.val);
	if (gost) {
		siter->missed = 1;    // GHOST key
		siter->nim = 0;
	}
	siter->be.dr = x ? getDR(siter->x.btr, x, i) : 0;
	siter->be.stream = stream;
	siter->be.x      = x;
	siter->be.i = i; //NOTE: used by bt_validate_dirty
	//DUMP_STREAM_TO_BT_ENTRY
	return 1;
}
Beispiel #17
0
//*******************************************************************
// Private Method:
//*******************************************************************
bool ossimKeywordlist::parseFile(const ossimFilename& file,
                                 bool ignoreBinaryChars)
{
   if(!file.exists()) return false;
   bool result = false;
   std::ifstream is;
   is.open(file.c_str(), std::ios::in | std::ios::binary);
   
   if(!is.fail())
   {
      result = parseStream(is, ignoreBinaryChars);
   }
   
   is.close();
   
   return result;
}
Beispiel #18
0
//*******************************************************************
// Private Method:
//*******************************************************************
bool ossimKeywordlist::parseFile(const ossimFilename& file,
                                 bool ignoreBinaryChars)
{
   std::ifstream is;
   is.open(file.c_str(), std::ios::in | std::ios::binary);

   if ( !is.is_open() )
   {
      // ESH 07/2008, Trac #234: OSSIM is case sensitive 
      // when using worldfile templates during ingest
      // -- If first you don't succeed with the user-specified
      // filename, try again with the results of a case insensitive search.
      ossimDirectory directory(file.path());
      ossimFilename filename(file.file());

      std::vector<ossimFilename> result;
      bool bSuccess = directory.findCaseInsensitiveEquivalents( filename, result );
      if ( bSuccess == true )
      {
         int numResults = (int)result.size();
         int i;
         for ( i=0; i<numResults && !is.is_open(); ++i )
         {
            is.open( result[i].c_str(), std::ios::in | std::ios::binary );
         }
      }

      if ( !is.is_open() )
      {
         if ( traceDebug() ) 
         {
            // report all errors that aren't existence problems.
            // we want to know about things like permissions, too many open files, etc.
            ossimNotify(ossimNotifyLevel_DEBUG)
            << "Error opening file: " << file.c_str() << std::endl;
         }
         return false;
      }
   }

   bool result = parseStream(is, ignoreBinaryChars);

   is.close();

   return result;
}
void QTweetUserStream::replyReadyRead()
{
    QByteArray response = m_reply->readAll();

#ifdef STREAM_LOGGER
    m_streamLog.write(response);
    m_streamLog.write("\n");
#endif

    if (m_streamTryingReconnect) {
        emit reconnected();
        m_streamTryingReconnect = false;
    }

    //set backoff timer to initial interval
    m_backofftimer->setInterval(20000);

    QByteArray responseWithPreviousCache = response.prepend(m_cachedResponse);

    int start = 0;
    int end;

    while ((end = responseWithPreviousCache.indexOf('\r', start)) != -1) {
        if (start != end) {
            QByteArray element = responseWithPreviousCache.mid(start, end - start);

            if (!element.isEmpty()) {
                emit stream(element);
                parseStream(element);
            }
        }

        int skip = (response.at(end + 1) == QLatin1Char('\n')) ? 2 : 1;
        start = end + skip;
    }

    //undelimited part just cache it
    m_cachedResponse.clear();

    if (start != responseWithPreviousCache.size()) {
        QByteArray element = responseWithPreviousCache.mid(start);
        if (!element.isEmpty())
            m_cachedResponse = element;
    }
}
Beispiel #20
0
QString B9ModelLoader::DetermineFileType(QString filename, bool &readyRead)
{
    QFileInfo info(filename);
    QString suffix = info.suffix();
    QFile parsefile(filename);
    QTextStream parseStream(&parsefile);
    QString asciiTest;
    unsigned int i = 0;


    if(suffix.toLower() == "stl")
    {
        //see if wee can open the file
        if(!parsefile.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            lastError = "Unable to open file:" + filename;
            qDebug() << "B9UpdateLoader: Unable to open file: " << filename;
            readyRead = false;
            return "";
        }

        //we can get the byte count right away
        byteCount = parsefile.size();

        //now determine if the Stl is binary or ascii
        while(i < 50)
        {
            parseStream >> asciiTest;
            if(asciiTest.toLower().trimmed() == "facet")
            {
                parsefile.close();
                qDebug() << "B9ModelLoader: the file is an ascii stl";
                readyRead = true;
                return "ASCII_STL";
            }
            i++;
        }
        //if we didnt find the string "facet within 50 words, assum its a bin.
        qDebug() << "B9ModelLoader: the file is a binary stl";
        readyRead = true;
        parsefile.close();
        return "BIN_STL";
    }
    else if(suffix.toLower() == "amf")
Vic2::State::State(std::istream& theStream, const string& ownerTag):
	owner(ownerTag)
{
	registerKeyword(std::regex("provinces"), [this](const std::string& unused, std::istream& theStream){
		commonItems::intList provinceList(theStream);
		for (auto province: provinceList.getInts())
		{
			provinceNums.insert(province);
		}
	});
	registerKeyword(std::regex("state_buildings"), [this](const std::string& unused, std::istream& theStream){
		Building theBuilding(theStream);
		factoryLevel += theBuilding.getLevel();
	});
	registerKeyword(std::regex("[A-Za-z0-9_]+"), commonItems::ignoreItem);

	parseStream(theStream);
	setID();
}
int GraphicProducer::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: strikePath((*reinterpret_cast< const VectorPath(*)>(_a[1])),(*reinterpret_cast< const GraphicContext(*)>(_a[2]))); break;
        case 1: fillPath((*reinterpret_cast< const VectorPath(*)>(_a[1])),(*reinterpret_cast< const GraphicContext(*)>(_a[2])),(*reinterpret_cast< Qt::FillRule(*)>(_a[3]))); break;
        case 2: parsingDone((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 3: { bool _r = parseStream((*reinterpret_cast< const char*(*)>(_a[1])),(*reinterpret_cast< ulong(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 4: { bool _r = parsePDF((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        default: ;
        }
        _id -= 5;
    }
    return _id;
}
Beispiel #23
0
static void
destroy_index(bt *ibtr, bt_n *n)                        
{                                                                               
	if (! n->leaf) {                                                             
		for (int i = 0; i <= n->n; i++) {                                       
			destroy_index(ibtr, NODES(ibtr, n)[i]);                     
		}                                                                       
	}                                                                           

	for (int i = 0; i < n->n; i++) {                                            
		void *be = KEYS(ibtr, n, i);                                            
		ai_nbtr *anbtr = (ai_nbtr *) parseStream(be, ibtr);                     
		if (anbtr) {                                                            
			if (anbtr->is_btree) {                                              
				bt_destroy(anbtr->u.nbtr);                                      
			} else {                                                            
				ai_arr_destroy(anbtr->u.arr);                                   
			}                                                                   
			cf_free(anbtr);                                                     
		}                                                                       
	}                                                                           
}                 
Beispiel #24
0
int CHttpClientLink::processRecv()
{
   mCode.clear();
   int rt = receive(mCode);
   if(rt==1)
   {
      int re = parseStream(mCode.content, mCode.length);
      if(re == 1)
      {
  //       httpResponseToApp(appKey, linkId(), version, rCode, content);
         return -1;
      }
      else if(re<0)
      {
         return -1;
      }
   }
   else if( -9 == rt || 0 == rt)
   {
      return -1;
   }
   return 1;
}
Beispiel #25
0
SidTune::LoadStatus SidTune::SID_fileSupport(Buffer_sidtt<const uint_least8_t>& dataBuf,
                                             Buffer_sidtt<const uint_least8_t>& sidBuf)
{
    uint_least32_t parseLen = sidBuf.len();
    // Make sure SID buffer pointer is not zero.
    // Check for a minimum file size. If it is smaller, we will not proceed.
    if (parseLen<sidMinFileSize)
    {
        return LOAD_NOT_MINE;
    }

    // Here use a smart pointer to prevent access violation errors.
    const char* pParseBuf = (const char*)sidBuf.get();
    // First line has to contain the exact identification string.
    if ( SidTuneTools::myStrNcaseCmp( pParseBuf, keyword_id ) == 0 )
    {
        // At least the ID was found, so set a default error message.
        m_info.formatString = text_truncatedError;
        
        // Defaults.
        fileOffset = 0;                // no header in separate data file
        m_info.sidChipBase1 = 0xd400;
        m_info.sidChipBase2 = 0;
        m_info.musPlayer = false;
        m_info.numberOfInfoStrings = 0;
        uint_least32_t oldStyleSpeed = 0;

        // Flags for required entries.
        bool hasAddress = false,
            hasName = false,
            hasAuthor = false,
            hasReleased = false,
            hasSongs = false,
            hasSpeed = false,
            hasInitAddr = false;
    
        // Using a temporary instance of an input string chunk.
#ifdef HAVE_EXCEPTIONS
        char* pParseChunk = new(std::nothrow) char[parseChunkLen+1];
#else
        char* pParseChunk = new char[parseChunkLen+1];
#endif
        if ( pParseChunk == 0 )
        {
            m_info.formatString = text_noMemError;
            return LOAD_ERROR;
        }
        
        // Parse as long we have not collected all ``required'' entries.
        //while ( !hasAddress || !hasName || !hasAuthor || !hasCopyright
        //        || !hasSongs || !hasSpeed )

        // Above implementation is wrong, we need to get all known
        // fields and then check if all ``required'' ones were found.
        do
        {
            uint_least32_t restLen;
            {
                const char* pNextLine = SidTuneTools::returnNextLine( pParseBuf, parseLen );
                if ( pNextLine != 0 )
                {
                    // Calculate number of chars between current pos and next line.
                    restLen = (uint_least32_t)(pNextLine - pParseBuf);
                }
                else
                {
                    // Calculate number of chars between current pos and end of buf.
                    restLen = parseLen;
                }
            }
#ifdef HAVE_SSTREAM
            std::string sParse( pParseBuf, restLen );            
            // Create whitespace eating (!) input string stream.
            std::istringstream parseStream( sParse );
            // A second one just for copying.
            std::istringstream parseCopyStream( sParse );
#else
            std::istrstream parseStream((char *) pParseBuf, restLen );
            std::istrstream parseCopyStream((char *) pParseBuf, restLen );
#endif
            if ( !parseStream || !parseCopyStream )
            {
                break;
            }
            // Now copy the next X characters except white-spaces.
            for ( uint_least16_t i = 0; i < parseChunkLen; i++ )
            {
                char c;
                parseCopyStream >> c;
                pParseChunk[i] = c;
            }
            pParseChunk[parseChunkLen]=0;
            // Now check for the possible keywords.
            // ADDRESS
            if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_address ) == 0 )
            {
                SidTuneTools::skipToEqu( parseStream );
                m_info.loadAddr = (uint_least16_t)SidTuneTools::readHex( parseStream );
                m_info.initAddr = m_info.loadAddr;
                hasInitAddr = true;
                if ( parseStream )
                {
                    m_info.initAddr = (uint_least16_t)SidTuneTools::readHex( parseStream );
                    if ( !parseStream )
                        break;
                    m_info.playAddr = (uint_least16_t)SidTuneTools::readHex( parseStream );
                    hasAddress = true;
                }
            }
            // NAME
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_name ) == 0 )
            {
                SidTuneTools::copyStringValueToEOL(pParseBuf,&infoString[0][0],SIDTUNE_MAX_CREDIT_STRLEN);
                m_info.infoString[0] = &infoString[0][0];
                hasName = true;
            }
            // AUTHOR
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_author ) == 0 )
            {
                SidTuneTools::copyStringValueToEOL(pParseBuf,&infoString[1][0],SIDTUNE_MAX_CREDIT_STRLEN);
                m_info.infoString[1] = &infoString[1][0];
                hasAuthor = true;
            }
            // COPYRIGHT
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_copyright ) == 0 )
            {
                SidTuneTools::copyStringValueToEOL(pParseBuf,&infoString[2][0],SIDTUNE_MAX_CREDIT_STRLEN);
                m_info.infoString[2] = &infoString[2][0];
                hasReleased = true;
            }
            // RELEASED
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_released ) == 0 )
            {
                SidTuneTools::copyStringValueToEOL(pParseBuf,&infoString[2][0],SIDTUNE_MAX_CREDIT_STRLEN);
                m_info.infoString[2] = &infoString[2][0];
                hasReleased = true;
            }
            // SONGS
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_songs ) == 0 )
            {
                SidTuneTools::skipToEqu( parseStream );
                m_info.songs = (uint_least16_t)SidTuneTools::readDec( parseStream );
                m_info.startSong = (uint_least16_t)SidTuneTools::readDec( parseStream );
                hasSongs = true;
            }
            // SPEED
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_speed ) == 0 )
            {
                SidTuneTools::skipToEqu( parseStream );
                oldStyleSpeed = SidTuneTools::readHex(parseStream);
                hasSpeed = true;
            }
            // SIDSONG
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_musPlayer ) == 0 )
            {
                m_info.musPlayer = true;
            }
            // RELOC
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_reloc ) == 0 )
            {
                m_info.relocStartPage = (uint_least8_t)SidTuneTools::readHex( parseStream );
                if ( !parseStream )
                    break;
                m_info.relocPages = (uint_least8_t)SidTuneTools::readHex( parseStream );
            }
            // CLOCK
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_clock ) == 0 )
            {
                char clock[8];
                SidTuneTools::copyStringValueToEOL(pParseBuf,clock,sizeof(clock));
                if ( SidTuneTools::myStrNcaseCmp( clock, "UNKNOWN" ) == 0 )
                    m_info.clockSpeed = SIDTUNE_CLOCK_UNKNOWN;
                else if ( SidTuneTools::myStrNcaseCmp( clock, "PAL" ) == 0 )
                    m_info.clockSpeed = SIDTUNE_CLOCK_PAL;
                else if ( SidTuneTools::myStrNcaseCmp( clock, "NTSC" ) == 0 )
                    m_info.clockSpeed = SIDTUNE_CLOCK_NTSC;
                else if ( SidTuneTools::myStrNcaseCmp( clock, "ANY" ) == 0 )
                    m_info.clockSpeed = SIDTUNE_CLOCK_ANY;
            }
            // SIDMODEL
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_sidModel ) == 0 )
            {
                char model[8];
                SidTuneTools::copyStringValueToEOL(pParseBuf,model,sizeof(model));
                if ( SidTuneTools::myStrNcaseCmp( model, "UNKNOWN" ) == 0 )
                    m_info.sidModel1 = SIDTUNE_SIDMODEL_UNKNOWN;
                else if ( SidTuneTools::myStrNcaseCmp( model, "6581" ) == 0 )
                    m_info.sidModel1 = SIDTUNE_SIDMODEL_6581;
                else if ( SidTuneTools::myStrNcaseCmp( model, "8580" ) == 0 )
                    m_info.sidModel1 = SIDTUNE_SIDMODEL_8580;
                else if ( SidTuneTools::myStrNcaseCmp( model, "ANY" ) == 0 )
                    m_info.sidModel1 = SIDTUNE_SIDMODEL_ANY;
            }
            // COMPATIBILITY
            else if ( SidTuneTools::myStrNcaseCmp( pParseChunk, keyword_compatibility ) == 0 )
            {
                char comp[6];
                SidTuneTools::copyStringValueToEOL(pParseBuf,comp,sizeof(comp));
                if ( SidTuneTools::myStrNcaseCmp( comp, "C64" ) == 0 )
                    m_info.compatibility = SIDTUNE_COMPATIBILITY_C64;
                else if ( SidTuneTools::myStrNcaseCmp( comp, "PSID" ) == 0 )
                    m_info.compatibility = SIDTUNE_COMPATIBILITY_PSID;
                else if ( SidTuneTools::myStrNcaseCmp( comp, "R64" ) == 0 )
                    m_info.compatibility = SIDTUNE_COMPATIBILITY_R64;
                else if ( SidTuneTools::myStrNcaseCmp( comp, "BASIC" ) == 0 )
                    m_info.compatibility = SIDTUNE_COMPATIBILITY_BASIC;
            }
            parseLen  -= restLen;
            pParseBuf += restLen;
            // Skip to next line. Leave loop, if none.
        } while (parseLen != 0);

        delete[] pParseChunk;
        
        if ( !(hasName && hasAuthor && hasReleased && hasSongs) )
        {   // Something is missing (or damaged ?).
            // Error string set above.
            return LOAD_ERROR;
        }

        switch ( m_info.compatibility )
        {
        case SIDTUNE_COMPATIBILITY_PSID:
        case SIDTUNE_COMPATIBILITY_C64:
            if ( !(hasAddress && hasSpeed) )
                return LOAD_ERROR; // Error set above
            break;

        case SIDTUNE_COMPATIBILITY_R64:
            if ( !(hasInitAddr || hasAddress) )
                return LOAD_ERROR; // Error set above
            // Allow user to provide single address
            if ( !hasAddress )
                m_info.loadAddr = 0;
            else if ( m_info.loadAddr || m_info.playAddr )
            {
                m_info.formatString = text_invalidError;
                return LOAD_ERROR;
            }
            // Deliberate run on

        case SIDTUNE_COMPATIBILITY_BASIC:
            oldStyleSpeed = ~0;
        }

        // Create the speed/clock setting table.
        convertOldStyleSpeedToTables(oldStyleSpeed, m_info.clockSpeed);
        m_info.numberOfInfoStrings = 3;
        // We finally accept the input data.
        m_info.formatString = text_format;
        if ( m_info.musPlayer && !dataBuf.isEmpty() )
            return MUS_load (dataBuf);
        return LOAD_OK;
    }
bool rspfApplanixEOFile::parseFile(const rspfFilename& file)
{
    std::ifstream in(file.c_str());

    return parseStream(in);
}
HoI4::Event::Event(const std::string& theType, std::istream& theStream):
	type(theType)
{
	registerKeyword(std::regex("id"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::singleString idString(theStream);
			id = idString.getString();
		}
	);
	registerKeyword(std::regex("title"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::singleString titleString(theStream);
			title = titleString.getString();
		}
	);
	registerKeyword(std::regex("desc"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::stringOfItem descriptionString(theStream);
			descriptions.push_back("desc " + descriptionString.getString());
		}
	);
	registerKeyword(std::regex("picture"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::singleString pictureString(theStream);
			picture = pictureString.getString();
		}
	);
	registerKeyword(std::regex("major"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::singleString majorString(theStream);
			majorEvent = (majorString.getString() == "yes");
		}
	);
	registerKeyword(std::regex("is_triggered_only"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::singleString triggeredString(theStream);
			triggeredOnly = (triggeredString.getString() == "yes");
		}
	);
	registerKeyword(std::regex("hidden"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::singleString hiddenString(theStream);
			hidden = (hiddenString.getString() == "yes");
		}
	);
	registerKeyword(std::regex("trigger"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::stringOfObject triggerString(theStream);
			trigger = triggerString.getString();
		}
	);
	registerKeyword(std::regex("mean_time_to_happen"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::stringOfObject MTTHString(theStream);
			meanTimeToHappen = MTTHString.getString();
		}
	);
	registerKeyword(std::regex("immediate"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::stringOfObject immediateString(theStream);
			immediate = immediateString.getString();
		}
	);
	registerKeyword(std::regex("option"), [this](const std::string& unused, std::istream& theStream)
		{
			commonItems::stringOfObject optionString(theStream);
			options.push_back(optionString.getString());
		}
	);

	parseStream(theStream);
}
Beispiel #28
0
bool ossimKeywordlist::parseString(const std::string& inString)
{
   std::istringstream in(inString);
   
   return parseStream(in);
}
Beispiel #29
0
bool ossimKeywordlist::parseStream(std::istream& is, bool /* ignoreBinaryChars */)
{
   return parseStream(is);
}
Beispiel #30
0
void StyleSheetParser::parseString(const char *data, std::size_t len) {
	parseStream(new StringInputStream(data, len));
}