Пример #1
0
str_list_t* dataParseList(const str_list_t records, str_list_t* columns, dataLineParser_t lineParser)
{
	size_t		ri=0;
	size_t		li=0;
	str_list_t* list;

	if(records==NULL)
		return(NULL);

	if((list=(str_list_t*)malloc(sizeof(str_list_t)*(strListCount(records)+1)))==NULL)
		return(NULL);

	if(columns!=NULL) {
		if((*columns=lineParser(records[ri++]))==NULL) {
			free(list);
			return(NULL);
		}
	}

	while(records[ri]!=NULL)
		list[li++]=lineParser(records[ri++]);

	list[li]=NULL; /* terminate */

	return(list);
}
Пример #2
0
/**
 * This loads the configuration file from disk to memory
 * @return bool of status whether config is valid or not
 */
bool Config::loadConfig() {

	// File object handle
	std::ifstream config;
	// Parsing variables
	std::string token, tmp;

	// Open file
	config.open(getPath().c_str());

	// File doesn't exist
	if (!config.is_open()) {
		config.close();
		// Set defaults
		setUrl(defaultURL);

		return false;
	}

	// Read through file line by line
	while (config.is_open() && std::getline(config, token)) {

		std::stringstream lineParser(token);
		lineParser >> tmp;

		// Handle each key here

		// Mode
		if (tmp == "mode:") {
			lineParser >> tmp;

			// Nothing set
			if (tmp.empty()) {
				std::cout << "Error: No mode set." << std::endl;
				setMode(PASSIVE);
			}
			// Passive mode
			else if (tmp == "passive") {
				setMode(PASSIVE);
			}
			// Active mode
			else if (tmp == "active") {
				setMode(ACTIVE);
			}
			// Bad option
			else {
				std::cout << "Mode invalid option: " << tmp;
				setMode(PASSIVE);
			}
		}
		// URL
		else if (tmp == "url:") {
Пример #3
0
    Material Model::loadMaterial( std::string& data, int numOfTextures, int programID )
    {
        Material material( programID );

        for( unsigned int i = 0; i < data.length(); ++i )
        {
            std::string line;
            while( data[i] != '\n' )
            {
                line += data[i];
                ++i;
            }            

            StringParser lineParser( line, std::string( ", " ) );
            int textureType = atoi( lineParser.getNextToken().c_str() );
            std::string fileName = lineParser.getNextToken();

            std::string filePath( "Models\\Images\\" );

            if( fileName.length() == 0 )
                return material;

            std::string extension = fileName.substr( fileName.length() - 3, 3 );
            if( extension.compare( "dds" ) == 0 )
            {
                convertToPNG( fileName );
            }

            switch( textureType )
            {
            case DIFFUSE:
                material.setTexture( std::string( "diffuseTex" ), GL_TEXTURE0, Texture::CreateOrGetTexture( filePath + fileName )->getTextureID() );
                break;

            case SPECULAR:
                material.setTexture( std::string( "specularTex" ), GL_TEXTURE1, Texture::CreateOrGetTexture( filePath + fileName )->getTextureID() );
                break;

            case EMISSIVE:
                material.setTexture( std::string( "emissiveTex" ), GL_TEXTURE2, Texture::CreateOrGetTexture( filePath + fileName )->getTextureID() );
                break;

            case NORMAL:
                material.setTexture( std::string( "normalTex" ), GL_TEXTURE3, Texture::CreateOrGetTexture( filePath + fileName )->getTextureID() );
                break;
            }
        }

        return material;
    }
Пример #4
0
void MainWindow::loadFile(const QString &fileName)
{
    //if is empty
    if(fileName.isEmpty())
    {
        //set the file name
        this->setFileName(QString ());
        ui->AppOutput->append("No file is open");
        return;
    }
    // create a QFile Object with the fileName variable
    QFile *qfo=new QFile(fileName);

    //if
    if(!(qfo->open(QIODevice::Text|QIODevice::ReadOnly)))
    {
        ui->AppOutput->append("The file "+fileName+" cannot be opened");
        QMessageBox::warning(this,"Error","The file cannot be opened",QMessageBox::Ok,QMessageBox::Ok);
        setFileName(QString());
        return;
    }
    else
    {
        ui->AppOutput->append("The file at "+fileName+" is opened");
        QTextStream qts(qfo);
        //codigo de parseo.

        int count_lines=0;
        while(!qts.atEnd())
        {
            //se lee la linea
            QString line=qts.readLine();
            //se muestra en la pantalla
            ui->textEdit->appendPlainText(line);
            //se envia a parsearla
            lineParser(line);
            //se cuenta la cantidad de lineas
            count_lines++;
        }
        ui->AppOutput->append("Lines: "+QString::number(count_lines));
        qfo->close();
        setFileName(fileName);
        setWindowModified(false);
    }

}
Пример #5
0
/**
 * read function for the configuration file. It
 * reads and interprets the complete file.
 * @exception thows assert if an error in the file occured
 */
void parserReadConf(void) {
    char name[NAMELEN];

    /* expecting name */
    parserExpectTokenNeu(tokName);
    /* copy name of station */
    parserExpectName(name, "Bahnhofname erwartet");
    strncpy(cStationName, name, NAMELEN - 1);
    cStationName[NAMELEN] = '\0';

    parserExpectTokenNeu(tokLBracket);
    registerParser();     /* now ios are made */
    parserExpectTokenNeu(tokRBracket);

    ledParser();
    duoledParser();

    parserExpectTokenNeu(tokLBracket);
    buttonParser();			/* now keys are parsed			*/
    turnoutParser();		/* the switches				*/
    sectionsParser();		/* the sections				*/
    dwarfParser();			/* the dwarfs (Zwergsignale, Sperrsignale)	*/
    shuntrouteParser();		/* the shunting routes (RaFas)		*/
    combishuntrouteParser();	/* the combined shunting routes	*/
    mainsParser();			/* the main signals (Hauptsignale)	*/
    routeParser();			/* the train routes (ZuFas)		*/
    dwarfParserResolve();		/* resolve unknown issues		*/
    combirouteParser();		/* the combined train routes		*/
    distantsParser();		/* the distant signals (Vorsignale	*/
    lineParser();			/* the lines (Strecken)			*/
    routeParserResolve();		/* resolve unknown lines in route	*/
    blockParser();			/* the blocks				*/
    lineParserResolve();		/* resolve unknown blocks in line	*/
    automatParser();		/* the automat				*/
    parserExpectTokenNeu(tokRBracket);
}
Пример #6
0
// allocates memory for outUsersFilePath and outGroupsFilePath - remember to delete
// returns the auth scheme
QTSS_AuthScheme QTAccessFile::FindUsersAndGroupsFilesAndAuthScheme(char* inAccessFilePath, QTSS_ActionFlags inAction, char** outUsersFilePath, char** outGroupsFilePath)
{
    QTSS_AuthScheme authScheme = qtssAuthNone;
    QTSS_ActionFlags currentFlags = qtssActionFlagsRead;
    
    if (inAccessFilePath == NULL)
    return authScheme;
        
    *outUsersFilePath = NULL;
    *outGroupsFilePath = NULL;
    //Assert(outUsersFilePath == NULL);
    //Assert(outGroupsFilePath == NULL);
    
    StrPtrLen accessFileBuf;
    (void)QTSSModuleUtils::ReadEntireFile(inAccessFilePath, &accessFileBuf);
    OSCharArrayDeleter accessFileBufDeleter(accessFileBuf.Ptr);
    
    StringParser accessFileParser(&accessFileBuf);
    StrPtrLen line;
    StrPtrLen word;
    
    while( accessFileParser.GetDataRemaining() != 0 ) 
    {
        accessFileParser.GetThruEOL(&line);     // Read each line   
        StringParser lineParser(&line);
        lineParser.ConsumeWhitespace();         //skip over leading whitespace
        if (lineParser.GetDataRemaining() == 0)     // must be an empty line
            continue;

        char firstChar = lineParser.PeekFast();
        if ( (firstChar == '#') || (firstChar == '\0') )
            continue;               //skip over comments and blank lines...
        
        lineParser.ConsumeUntilWhitespace(&word);
               
        if ( word.Equal("<Limit") ) // a limit line
        {
            currentFlags = qtssActionFlagsNoFlags; // clear to no access
            lineParser.ConsumeWhitespace();
            lineParser.ConsumeUntil( &word, sWhitespaceAndGreaterThanMask); // the flag <limit Read> or <limit Read >
            while (word.Len != 0) // compare each word in the line
            {   
                if (word.Equal("WRITE")  ) 
                {   
                    currentFlags |= inAction & qtssActionFlagsWrite; // accept following lines if inFlags has write
                }
                    
                if (word.Equal("READ") ) 
                {   
                    currentFlags |= inAction & qtssActionFlagsRead; // accept following lines if inFlags has read
                }
                            
                lineParser.ConsumeWhitespace();
                lineParser.ConsumeUntil(&word, sWhitespaceAndGreaterThanMask);
            }
            continue; //done with limit line
        }
        
        if ( word.Equal("</Limit>") )
            currentFlags = qtssActionFlagsRead; // set the current access state to the default of read access
        
        if (0 == (currentFlags & inAction))
            continue; // ignore lines because inFlags doesn't match the current access state
            
        if (word.Equal("AuthUserFile") )
        {
            lineParser.ConsumeWhitespace();
            lineParser.GetThruEOL(&word);
            StringParser::UnQuote(&word);// if the parsed string is surrounded by quotes then remove them.
    
            if(*outUsersFilePath != NULL)       // we are encountering the AuthUserFile keyword twice!
                delete[] *outUsersFilePath; // The last one found takes precedence...delete the previous path
            
            *outUsersFilePath = word.GetAsCString();
            continue;
        }
        
        if (word.Equal("AuthGroupFile") )
        {
            lineParser.ConsumeWhitespace();
            lineParser.GetThruEOL(&word);
            StringParser::UnQuote(&word);// if the parsed string is surrounded by quotes then remove them.

            if(*outGroupsFilePath != NULL)      // we are encountering the AuthGroupFile keyword twice!
                delete[] *outGroupsFilePath;    // The last one found takes precedence...delete the previous path       
            
            *outGroupsFilePath = word.GetAsCString();
            
            continue;
        }
        
        if (word.Equal("AuthScheme") )
        {
            lineParser.ConsumeWhitespace();
            lineParser.GetThruEOL(&word);
            StringParser::UnQuote(&word);// if the parsed string is surrounded by quotes then remove them.

            if (word.Equal("basic"))
                authScheme = qtssAuthBasic;
            else if (word.Equal("digest"))
                authScheme = qtssAuthDigest;
                
            continue;
        }
    }
    
    return authScheme;
}
Пример #7
0
Bool16 QTAccessFile::AccessAllowed  (   char *userName, char**groupArray, UInt32 numGroups, StrPtrLen *accessFileBufPtr,
                                        QTSS_ActionFlags inFlags,StrPtrLen* ioRealmNameStr, Bool16 *outAllowAnyUserPtr, void *extraDataPtr
                                    )
{       
    if (NULL == accessFileBufPtr || NULL == accessFileBufPtr->Ptr || 0 == accessFileBufPtr->Len)
        return true; // nothing to check
        
    if (ioRealmNameStr != NULL && ioRealmNameStr->Ptr != NULL && ioRealmNameStr->Len > 0)
        ioRealmNameStr->Ptr[0] = 0;
        
    StringParser            accessFileParser(accessFileBufPtr);
    QTSS_ActionFlags        currentFlags = qtssActionFlagsRead; 
    StrPtrLen               line;
    StrPtrLen               word;
    Bool16                  haveUserName = false;
    Bool16                  haveRealmResultBuffer = false;
    Bool16                  haveGroups = false;
    
    *outAllowAnyUserPtr = false;
        
    haveUserName = HaveUser(userName, extraDataPtr);
  
    haveGroups = HaveGroups(groupArray, numGroups, extraDataPtr);

    haveRealmResultBuffer =  HaveRealm(userName, ioRealmNameStr, extraDataPtr );
  
    while( accessFileParser.GetDataRemaining() != 0 ) 
    {
        accessFileParser.GetThruEOL(&line);  // Read each line  
        StringParser lineParser(&line);
        lineParser.ConsumeWhitespace();//skip over leading whitespace
        if (lineParser.GetDataRemaining() == 0) // must be an empty line
            continue;

        char firstChar = lineParser.PeekFast();
        if ( (firstChar == '#') || (firstChar == '\0') )
            continue; //skip over comments and blank lines...
        
        lineParser.ConsumeUntilWhitespace(&word);
        if ( word.Equal("<Limit") ) // a limit line
        {
            currentFlags = qtssActionFlagsNoFlags; // clear to no access
            lineParser.ConsumeWhitespace();
            lineParser.ConsumeUntil( &word, sWhitespaceAndGreaterThanMask); // the flag <limit Read> or <limit Read >
            while (word.Len != 0) // compare each word in the line
            {   
                if (word.Equal("WRITE")  ) 
                {   currentFlags |= inFlags & qtssActionFlagsWrite; // accept following lines if inFlags has write
                }
                
                if (word.Equal("READ") ) 
                {   currentFlags |= inFlags & qtssActionFlagsRead; // accept following lines if inFlags has read
                }
                lineParser.ConsumeWhitespace();
                lineParser.ConsumeUntil(&word, sWhitespaceAndGreaterThanMask);
            }
            continue; //done with limit line
        }
        if ( word.Equal("</Limit>") )
            currentFlags = qtssActionFlagsRead; // set the current access state to the default of read access
        
        if (0 == (currentFlags & inFlags))
            continue; // ignore lines because inFlags doesn't match the current access state
            
        if (haveRealmResultBuffer && word.Equal("AuthName") ) //realm name
        {   
            lineParser.ConsumeWhitespace();
            lineParser.GetThruEOL(&word);
            StringParser::UnQuote(&word);// if the parsed string is surrounded by quotes then remove them.
            
            GetRealm(&word, ioRealmNameStr, userName, extraDataPtr );

            // we don't change the buffer len ioRealmNameStr->Len because we might have another AuthName tag to copy
            continue; // done with AuthName (realm)
        }
        
        
        if (word.Equal("require") )
        {
            lineParser.ConsumeWhitespace();
            lineParser.ConsumeUntilWhitespace(&word);       

            if (haveUserName && word.Equal("valid-user") ) 
            {   return true; 
            }
            
            if ( word.Equal("any-user")  ) 
            {   
                *outAllowAnyUserPtr = true;
                return true; 
            }
    
            if (!haveUserName)
                continue;
                
            if (word.Equal("user") )
            {   
                lineParser.ConsumeWhitespace();
                lineParser.ConsumeUntilWhitespace(&word);   
                    
                while (word.Len != 0) // compare each word in the line
                {   
                    if (TestUser(&word, userName, extraDataPtr ))
                        return true;

                    lineParser.ConsumeWhitespace();
                    lineParser.ConsumeUntilWhitespace(&word);       
                }
                continue; // done with "require user" line
            }
            
            if (haveGroups && word.Equal("group")) // check if we have groups for the user
            {
                lineParser.ConsumeWhitespace();
                lineParser.ConsumeUntilWhitespace(&word);       
                
                while (word.Len != 0) // compare each word in the line
                {   
                    if (TestGroup(&word, userName, groupArray, numGroups, extraDataPtr) )
                        return true;

                    lineParser.ConsumeWhitespace();
                    lineParser.ConsumeUntilWhitespace(&word);
                }
                continue; // done with "require group" line
            }
            
            if (TestExtraData(&word, &lineParser, extraDataPtr))
                return true;
                
                    
            continue; // done with unparsed "require" line
        }
        
    }
    
    return false; // user or group not found
}
Пример #8
0
    bool Model::loadModel( const char* filePath, int programID )
    {
        FILE* file = fopen( filePath, "rb" );

        if( !file )
            return false;

        while( !feof( file ) )
        {
            std::string line;
            char buffer = '\0';
            while( !feof( file ) && buffer != '\n' )
            {
                buffer = (char)fgetc( file );
                line += buffer;
            }

            StringParser lineParser( line, std::string( ", " ) );
            std::string type = lineParser.getNextToken();

            if( type.compare( "StaticMesh" ) == 0 )
            {
                Mesh newMesh;
                std::string meshData;
                int numOfVerts = atoi( lineParser.getNextToken().c_str() );
                int numOfTransforms = atoi( lineParser.getNextToken().c_str() );
                int transformID = atoi( lineParser.getNextToken().c_str() );
                int parentTransformID = atoi( lineParser.getNextToken().c_str() );

                newMesh.readMeshData( file, numOfVerts, numOfTransforms, transformID, parentTransformID );

                m_Meshs.insert( std::pair< int, Mesh >( newMesh.getTransformID(), newMesh ) );

            }

            else if( type.compare( "SkeletalMesh" ) == 0 )
            { 
                SkeletalMesh skeletalMesh;

                int numOfVerts = atoi( lineParser.getNextToken().c_str() );

                skeletalMesh.readSkeletalMeshData( file, numOfVerts );

                m_SkeletalMeshs.push_back( skeletalMesh );
            }

            else if( type.compare( "Bone" ) == 0 )
            {
                Bone bone;

                int boneID = atoi( lineParser.getNextToken().c_str() );
                int numOfTransforms = atoi( lineParser.getNextToken().c_str() );

                std::vector< Matrix3 > transforms( numOfTransforms );
                Matrix3 initialInverse;

                fread( &initialInverse, sizeof( Matrix3 ), 1, file );
                fread( transforms.data(), sizeof( Matrix3 ), numOfTransforms, file );

                bone.initialInverse = initialInverse.convertTo4x4Matrix();
                for( int i = 0; i < numOfTransforms; ++i )
                {
                    bone.transforms.push_back( transforms[i].convertTo4x4Matrix() );
                }

                m_Bones[boneID] = bone;
            }

            else if( type.compare( "Material" ) == 0 )
            {
                int materialID = atoi( lineParser.getNextToken().c_str() );
                int numOfTextures = atoi( lineParser.getNextToken().c_str() );

                std::string materialData;
                for( int i = 0; i < numOfTextures; )
                {
                    buffer = (char)fgetc( file );
                    materialData += buffer;
                    if( buffer == '\n' )
                    {
                        ++i;
                    }
                }

                m_Materials.push_back( loadMaterial( materialData, numOfTextures, programID ) );
            }
        }

        if( m_Materials.size() == 0 )
        {
            m_Materials.push_back( Material( programID ) );
        }

        fclose( file );

        std::cout << "Finished loading " << filePath << std::endl;
        return true;
    }
Пример #9
0
int main(int argc,char** argv)
{
	if(argc!= 2){
		printf("Wrong arguments!\nSintax: GESTAUTS 'file_path'\n");
	return 1;
   }
   time_t seconds = time(NULL);
 
 int entradas = 0;
	int menor_ano = 2015;
	int maior_ano = 0;
	int autores = 0;
	char *filename = argv[1];
	FILE* fl = fopen(filename,"a+");
	int read;
	char * line = NULL;
	size_t len = 0;
	int ano;
	Indice* indice;
	 int i = 0;
	indice = initInd(indice); 

	/*malloc(28*sizeof(Node));
	for(i;i<28;i++)
		indice[i] = NULL;
		*/
	Catalog * catalog;
	catalog = catInit(catalog);

i=0 ;
	while ((read = getline(&line, &len, fl)) != -1) {
	int nap= 0;
	char** nomes;
	lineParser(line,&autores, &ano,&nap,&nomes); 

    if(ano > maior_ano)
    	maior_ano = ano;

    if(ano < menor_ano)
    	menor_ano = ano;
 
catalog = add(catalog,ano,nomes,nap); 

while(nap>0)
{
 indice = addToInd(indice ,nomes[nap-1]);
nap--;
}
 

    //printf("%s\n", nomes[0]);
    entradas++;
 
    free(nomes);
    len= 0;
}
printf("Ficheiro: %s\n", filename);
printf("Publicaçoes: %d\n",entradas );
printf("Numero total de autores: %d\n",autores );
printf("Intervalo de anos: [%d-%d]\n", menor_ano,maior_ano);



printCatalog(catalog);




//printIndice(indice);
free(line);
fclose(fl);
free(indice);
free(catalog);
time_t seconds2 = time(NULL);
printf("time in seconds :: %ld\n", (seconds2-seconds) );
return 0;
}
Пример #10
0
void SDPContainer::Parse()
{
	char*	    validChars = "vosiuepcbtrzkam";
	char        nameValueSeparator = '=';

	Bool16      valid = true;

	StringParser	sdpParser(&fSDPBuffer);
	StrPtrLen		line;
	StrPtrLen 		fieldName;
	StrPtrLen		space;
	Bool16          foundLine = false;

	while (sdpParser.GetDataRemaining() != 0)
	{
		foundLine = sdpParser.GetThruEOL(&line);  // Read each line  
		if (!foundLine)
		{
			break;
		}
		StringParser lineParser(&line);

		lineParser.ConsumeWhitespace();//skip over leading whitespace
		if (lineParser.GetDataRemaining() == 0) // must be an empty line
			continue;

		char firstChar = lineParser.PeekFast();
		if (firstChar == '\0')
			continue; //skip over blank lines

		fFieldStr[(UInt8)firstChar] = firstChar;
		switch (firstChar)
		{
		case 'v': fReqLines |= kV;
			break;

		case 's': fReqLines |= kS;
			break;

		case 't': fReqLines |= kT;
			break;

		case 'o': fReqLines |= kO;
			break;

		}

		lineParser.ConsumeUntil(&fieldName, nameValueSeparator);
		if ((fieldName.Len != 1) || (::strchr(validChars, fieldName.Ptr[0]) == NULL))
		{
			valid = false; // line doesn't begin with one of the valid characters followed by an "="
			break;
		}

		if (!lineParser.Expect(nameValueSeparator))
		{
			valid = false; // line doesn't have the "=" after the first char
			break;
		}

		lineParser.ConsumeUntil(&space, StringParser::sWhitespaceMask);

		if (space.Len != 0)
		{
			valid = false; // line has whitespace after the "=" 
			break;
		}
		AddHeaderLine(&line);
	}

	if (fNumUsedLines == 0) // didn't add any lines
	{
		valid = false;
	}
	fValid = valid;

}