Beispiel #1
0
		const char *parseField(QString &fname, QVariant &fvalue, const char *s, int *maxLength)
		{
			return reinterpret_cast<const char *>(parseField(fname,
															 fvalue,
															 reinterpret_cast<const uchar *>(s),
															 maxLength));
		}
Beispiel #2
0
bool OBJ::parseFile(const QString &filepath)
{
	QFile file(filepath);

	if (!file.open(QIODevice::ReadOnly))
		return false;

	QTextStream ts(&file);
	int lineNumber = 0;

	while (!ts.atEnd())
	{
		QString line = ts.readLine();
		QStringList field = line.split(" ");

		if (!parseField(field))
		{
			//qDebug() << filepath << "- Error parsing line " << lineNumber << ": " << line;
		}

		++lineNumber;
	}

	return true;
}
void parseLine(String line) {
    int i=0;
    String home=parseField(line,&i);
    String time=parseField(line,&i);
    String hour=time.substring(0,2);
    String min=time.substring(3,5);
    int minsSinceMidnight=strtol(hour, NULL, 10)*60+strtol(min, NULL, 10);
    String color=parseField(line,&i);
    String fade="300"; //parseField(line,&i);
    schedule[scheduleCount].home=(int)strtol(home,NULL,10);
    schedule[scheduleCount].timeString=time;
    schedule[scheduleCount].time=minsSinceMidnight;
    schedule[scheduleCount].color=color;
    schedule[scheduleCount].fade=strtol(fade, NULL, 10)*1000/MORPH_TIMER_MS;
    scheduleCount++;
}
		/*
		 * CREATE TABLE <name> (
		 *    <columnDefinitions>
		 * )
		 *
		 * <name> == <columnName> == identifier
		 * <columnDefinitions> := <columnName> <columnType> [, <columnDefinitions>]
		 * <columnType> := byte | int | uint | char(<length>)
		 * <length> == int
		 */
		void CreateTable::Parse(Lexer& lex)
		{
			Token t;
			
			// <name>
			t = lex.NextToken(TokenType::Identifier, false);
			name = t.strData;
			
			// (
			lex.NextToken("(", TokenType::Parenthesis);

			string tableName;
			// While not )
			do
			{
				Field f = parseField(lex);
				AddField(f);
			
				// , or )
				t = lex.NextToken();
			}
			while (t.type == TokenType::Separator);

			if (t.type != TokenType::Parenthesis || t.strData != ")")
				throw InvalidTokenException(t);
		}
Beispiel #5
0
/**
 * Parses the class member (field or method) contained within the given token stack
 */
int CodeParser::parseClassMember( Scope* scope, TokenStack* stack ) {
	int errorCode = 0;
	TypeReference* type;
	const char* name;

	// the following types are parsed:
	// 	method layout: "[static] [final] type|[]| methodName(...) { ... }"
	//	field layout:  "[static] [final] type|[]| fieldName| = ....|"

	int step = 0;
	bool done = false;
	while( !done && stack->hasNext() ) {
		switch( ++step ) {
			// step 1: get the type of the class member (e.g. "string" or "string[]")
			case 1:
				// extract the name of the identifier
				if( !( type = parseType( scope, stack ) ) ) {
					return -1;
				}
				break;

			// step 2: get the class member name
			case 2:
				// get the type name
				if( !( name = state->getIdentifierName( stack, "class member" ) ) ) {
					return -2;
				}
				break;

			// step 3: get the class member instance (field or method)
			// 			method layout: "[static] [final] type methodName(...) { ... }"
			//			field layout:  "[static] [final] type fieldName[ = ....]"
			case 3:
				// each child should be a method (e.g. "type methodName(...)") or field (e.g. "type fieldName")
				// if there is a parenthesis block, it's likely to be a method
				errorCode = ( stack->peek()->getType() == tok::PARENTHESIS_BLOCK )
						? parseMethod( scope, name, type, stack )
						: parseField( scope, name, type, stack );

				// was there an error?
				if( errorCode ) {
					return errorCode;
				}
				done = true;
				break;
		}
	}

	// did it complete?
	if( !done ) {
		SYNTAX_ERROR( "unexpected end of statement", stack->last() );
		return -4;
	}

	// return the error code
	return 0;
}
bool mod_mimikatz_minesweeper::infos(vector<wstring> * arguments)
{
	structHandleAndAddr * maStruct = new structHandleAndAddr();
	if(giveHandleAndAddr(maStruct))
	{
		STRUCT_MINESWEEPER_GAME monGame;
		if(mod_memory::readMemory(maStruct->G, &monGame, sizeof(STRUCT_MINESWEEPER_GAME), maStruct->hMineSweeper))
		{
#ifdef _M_IX86
			if(mod_system::GLOB_Version.dwBuildNumber >= 7000)
				monGame.pBoard = monGame.pBoard_WIN7x86;
#endif
			STRUCT_MINESWEEPER_BOARD monBoard;
			if(mod_memory::readMemory(monGame.pBoard, &monBoard, sizeof(STRUCT_MINESWEEPER_BOARD), maStruct->hMineSweeper))
			{
				wcout << L"Mines           : " << monBoard.nbMines << endl <<
					L"Dimension       : " << monBoard.nbLignes << L" lignes x " << monBoard.nbColonnes << L" colonnes" << endl <<
					L"Champ           : " << endl << endl;

				char ** monTableau;
				monTableau = new char*[monBoard.nbLignes];
				for(DWORD l = 0; l < monBoard.nbLignes; l++)
					monTableau[l] = new char[monBoard.nbColonnes];
					
				parseField(maStruct, monBoard.ref_visibles, monTableau, true);
				parseField(maStruct, monBoard.ref_mines, monTableau, false);

				for(DWORD l = 0; l < monBoard.nbLignes; l++)
				{
					wcout << L'\t';
					for(DWORD c = 0; c < monBoard.nbColonnes; c++)
						wcout << monTableau[l][c] << L' ';
					wcout << endl;
					delete[] monTableau[l];
				}
				delete[] monTableau;
			} else wcout << L"Impossible de lire les données du plateau" << endl;
		} else wcout << L"Impossible de lire les données du jeu" << endl;
		CloseHandle(maStruct->hMineSweeper);
	}
	delete maStruct;

	return true;
}
int main(void){
	int row = 0, col = 0;
	int fieldNum = 0;
	while(fscanf(stdin, "%d%d", &row, &col) == 2 && row > 0 && row <= 100 && col > 0 && col <= 100){
		char** data = readField(row, col);
		parseField(data, row, col);

		if(fieldNum > 0)
			printf("\n");
		printf("Field #%d:\n", ++fieldNum);
		display(data, row, col);
		
		destroy(data, row);
	}	
	return 0;
}
Beispiel #8
0
ValidationList ConfigSection::parse(const INIConfigSection& section) {
	section_name = section.getName();

	preParse(section, validation);

	auto entries = section.getEntries();
	for (auto entry_it = entries.begin(); entry_it != entries.end(); ++entry_it) {
		std::string key = entry_it->first;
		std::string value = entry_it->second;

		if (!parseField(key, value, validation))
			validation.warning("Unknown configuration option '" + key + "'!");
	}

	postParse(section, validation);

	return validation;
}
Beispiel #9
0
int main()
{
	void updateColor();
	
	Display *d = XOpenDisplay( NULL );
	Window w = RootWindow(d, DefaultScreen(d));

	void parseField();
	int ix;
	for(ix = 0; ix < 110; ix++){ //main loop
		int j;  //index convention (0-63)
		printf("Loop %d/110. Colours updated:\n\n", ix);
		for(j = 63; j >= 0; j--){ //update from below to increase accuracy
			updateColor(j, d, w, tlx + dx*(j % 8), tly + dy*(j / 8), dx, dy);
			printf("%d:%x ", j + 1, colArr[j]);
			if(j % 8 == 0){printf("\n");}
		}
		parseField();
		system("sleep 0.6");
	}

	return 0;
}
Beispiel #10
0
int main(int argc, char *argv[]) {
	int ret; //fuer getopt funktion
	char player = '3';
	char gameId[15];
	char *confDateiName = malloc(256);
	strcpy(confDateiName, "client.conf");
	pid_t pid;

  //Config-Datei einlesen und struct betanken
	log_printf(LOG_DEBUG,"Using config-file %s\n",confDateiName);
	configstruct = get_config(confDateiName);

	log_printf(LOG_PRINTF,"\n");

	//11-stellige Game-Id aus Kommandozeile auslesen
	if (argc < 2) {
		printf("Keine Game-Id angegeben!\n");
		help();
		exit(EXIT_FAILURE);
	}
	strcpy(gameId,argv[1]);
	
	if(strlen(gameId) != 11) {
		printf("Game-Id muss 11-stellig sein!\n");
		help();
		exit(EXIT_FAILURE);
	}

	//optional gewunschte Spielernummer, config Dateiname oder log Level einlesen 
	while ((ret=getopt(argc, argv, "p:c:l:")) != -1) {
	switch (ret) {
	case 'p':
		player = optarg[0];
		if (player!='0' && player != '1') {
			printf("Es gibt nur 2 Spieler! 0 oder 1 eingeben!\n");
			help();
			exit(EXIT_FAILURE);
		}
		break;
	case 'c':
		strcpy(confDateiName, optarg);
		break;
	case 'l':
		configstruct.loglevel = atoi(optarg);
		break;
	default:
		help();
		exit(EXIT_FAILURE);
	}
	}

	//Shared-Memory erstellen 
	//shmSegment() um die ID zu erstellen -> vor fork()
	int shmid = shmSegment(sizeof(struct shmInfos));

	//shmAnbinden(shmid); um es an den Prozess zu binden
	shmPtr = shmAnbinden(shmid);

	//shm automatisch entfernen, wenn alle prozesse detached sind
	shmDelete(shmid);
	
	//Pipe anlegen
	int pipe_fd[2];
	if(pipe(pipe_fd)<0){
		log_printf(LOG_ERROR,"Fehler bei Pipe anlegen");
	};

	// zweiten Prozess erstellen.
	// Connector ist der Kindprozess
	// Thinker der Elternprozess
	switch (pid = fork ()) {
	case -1:
		log_printf (LOG_ERROR,"Fehler bei fork()\n");
		break;
	case 0: // Connector
		shmPtr->pid1=pid;
		char *getText;
		
		//Verbindung mit Server herstellen
		netConnect(configstruct.port, configstruct.hostname);

		while (1) {
			getText = netReadLine();

			if (strncmp(getText, "+ MNM ",6) == 0) {
				//+ MNM Gameserver v1.0 accepting connections
				sendVersion();
			} else if (strncmp(getText, "+ Clie",6) == 0) {
				//+ Client version accepted - please send Game-ID to join
				sendGameId(gameId);
			} else if (strncmp(getText, "+ PLAY",6) == 0) {
				//+ PLAYING Quarto
				parseGamekind(getText, shmPtr);
				sendPlayer(player, shmPtr);
			} else if (strncmp(getText, "+ ENDP",6) == 0) {
				//+ ENDPLAYERS
				//noop
			} else if (strncmp(getText, "+ MOVE",6) == 0) {
				//+ MOVE 3000
				parseMovetimeout(getText, shmPtr);
			} else if (strncmp(getText, "+ NEXT",6) == 0) {
				//+ NEXT 7
				parseNext(getText, shmPtr);
			} else if (strncmp(getText, "+ FIEL",6) == 0) {
				//+ FIELD 4,4
				parseField(getText);
			} else if (strncmp(getText, "+ ENDF",6) == 0) {
				//+ ENDFIELD
        if (shmPtr->gameover != 1) {
  				sendThinking();
        }
			} else if (strncmp(getText, "+ OKTH",6) == 0) {
				
				//Hier Zug erhalten und per sendMove(stein, naechsterstein) senden
				if(ueberwacheFd(pipe_fd,getText)==1){
					log_printf(LOG_DEBUG,"Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
					sendMove(getText);
				}
				else{
					log_printf(LOG_PRINTF,"Gandalf ist ersoffen\n");
				}
			} else if (strncmp(getText, "+ WAIT",6) == 0) {
				//+ WAIT
				sendOkwait();
			} else if (strncmp(getText, "+ GAME",6) == 0) {
				//+ GAMEOVER [[ hh Spielernummer des Gewinners ii hh Spielername des Gewinners ii ]]
        shmPtr->gameover = 1;
				parseGameover(getText);
			} else if (strncmp(getText, "+ QUIT",6) == 0) {
				//+ QUIT
				netDisconnect();
				break;
			} else if (strncmp(getText, "-",1) == 0) {
				//Well, f**k.

				//aufraeumen + signal an parent schicken, damit der sich beendet
				netDisconnect();
				free(confDateiName);
				kill(getppid(),SIGCHLD);
				break;
			}
		}

		break;

	default: // Thinker
		
		shmPtr->pid0=pid;

		//wenn das Signal kommt, dass er denken soll
		signal(SIGUSR1, signalHandler);
		//wenn das Signal vom Kind kommt, dass er sich beenden soll (wegen Fehler)
		signal(SIGCHLD, endHandler);
		
		while (1){
			// Auf Signal warten	
			pause();
			
			log_printf(LOG_DEBUG,"thinker hat fertig gedacht\n");
			// In die Pipe schreiben
			pipe_write(pipe_fd);
		}

		if (wait (NULL) != pid) {
			log_printf(LOG_ERROR,"Fehler beim Warten auf den Kindprozess\n");
			return EXIT_FAILURE;
		}
		break;
	}

	return 0;
}
Beispiel #11
0
//
// Reloads all cookies from the file '_filename'.
// On succes 'true' is returned.
// On failure 'false' is returned.
bool KCookieJar::loadCookies(const QString &_filename)
{
    FILE *fStream = fopen( QFile::encodeName(_filename), "r");
    if (fStream == 0)
    {
        return false;
    }

    time_t curTime = time(0);

    char *buffer = new char[READ_BUFFER_SIZE];

    bool err = false;
    err = (fgets(buffer, READ_BUFFER_SIZE, fStream) == 0);

    int version = 1;
    if (!err)
    {
        if (strcmp(buffer, "# KDE Cookie File\n") == 0)
        {
          // version 1
        }
        else if (sscanf(buffer, "# KDE Cookie File v%d\n", &version) != 1)
        {
          err = true;
        }
    }

    if (!err)
    {
        while(fgets(buffer, READ_BUFFER_SIZE, fStream) != 0)
        {
            char *line = buffer;
            // Skip lines which begin with '#' or '['
            if ((line[0] == '#') || (line[0] == '['))
                continue;

            const char *host( parseField(line) );
            const char *domain( parseField(line) );
            const char *path( parseField(line) );
            const char *expStr( parseField(line) );
            if (!expStr) continue;
            int expDate  = (time_t) strtoul(expStr, 0, 10);
            const char *verStr( parseField(line) );
            if (!verStr) continue;
            int protVer  = (time_t) strtoul(verStr, 0, 10);
            const char *name( parseField(line) );
            bool keepQuotes = false;
            bool secure = false;
            bool httpOnly = false;
            bool explicitPath = false;
            const char *value = 0;
            if ((version == 2) || (protVer >= 200))
            {
                if (protVer >= 200)
                    protVer -= 200;
                int i = atoi( parseField(line) );
                secure = i & 1;
                httpOnly = i & 2;
                explicitPath = i & 4;
                if (i & 8)
                   name = "";
                line[strlen(line)-1] = '\0'; // Strip LF.
                value = line;
            }
            else
            {
                if (protVer >= 100)
                {
                    protVer -= 100;
                    keepQuotes = true;
                }
                value = parseField(line, keepQuotes);
                secure = atoi( parseField(line) );
            }

            // Parse error
            if (!value) continue;

            // Expired or parse error
            if ((expDate == 0) || (expDate < curTime))
                continue;

            KHttpCookie *cookie = new KHttpCookie(QString::fromLatin1(host),
                                                  QString::fromLatin1(domain), 
                                                  QString::fromLatin1(path), 
                                                  QString::fromLatin1(name),
                                                  QString::fromLatin1(value), 
                                                  expDate, protVer,
                                                  secure, httpOnly, explicitPath);
            addCookie(cookie);
        }
    }
    delete [] buffer;
    m_cookiesChanged = false;

    fclose( fStream);
    return err;
}
Beispiel #12
0
Structure* PDBReader::readStructure(Alphabet* alphabet, char* filename, const char* backboneAtomName) {

    FILE* infile = fopen(filename, "r");
    
    if (infile == NULL) {
        return 0;
    }
    
    Structure* structure = new Structure(alphabet, filename);

    // Create the entries from the PDB file.
    char recordType[7];
    char serialNumber[6];
    char atomName[5];
    char altLoc[2];
    char residueName[4];
    char chain[2];
    char resID[5];
    char insertion[2];
    char x[9];
    char y[9];
    char z[9];
  
    // Go through the file and parse out the records.
    char line[1024];
    Coordinate3D backboneCoord;
    Residue* currentResidue = NULL;
    while (!feof(infile)) {
      
        // Get the next line.
        if (fgets(line, 1023, infile) == NULL)
            break;
      
        // Make sure this is an atom or hetatom record.
        parseField(recordType, line, 0, 6);
        if (strcmp(recordType, "ATOM") == 0 || strcmp(recordType, "HETATOM") == 0)
        {
            // Parse the fields.
            parseField(serialNumber, line, 6, 5);
            parseField(atomName, line, 12, 4);
            parseField(altLoc, line, 16, 1);
            parseField(residueName, line, 17, 3);
            parseField(chain, line, 21, 1);
            parseField(resID, line, 22, 4);
            parseField(insertion, line, 26, 1);
            parseField(x, line, 30, 8);
            parseField(y, line, 38, 8);
            parseField(z, line, 46, 8);
            
            // If this is a new residue, save the old one (if we have one) and start over.
            if (currentResidue == NULL || (strcmp(resID, currentResidue->getResID()) != 0 || strcmp(insertion, currentResidue->getInsertionName()) != 0))
            {
                if (currentResidue != NULL)
                {
                    structure->addResidue(currentResidue->getName(), backboneCoord, currentResidue);
                }
                
                // Start the new residue.
                backboneCoord.unset();
                currentResidue = new Residue(residueName, resID, insertion);
            }
            
            // If this is a backbone atom, save it.
            if (strcmp(atomName, backboneAtomName) == 0)
            {
                backboneCoord.set(charToFloat(x), charToFloat(y), charToFloat(z));
            }
            
            // Add the atom to the list.
            currentResidue->addAtom(new Atom(atomName, charToFloat(x),charToFloat(y),charToFloat(z)));
        }
        else if (strcmp(recordType, "TER") == 0)
        {
            break;
        }
    
    }
    
    // If we have one last residue, save it.
    if (currentResidue != NULL)
    {
        structure->addResidue(currentResidue->getName(), backboneCoord, currentResidue);
    }
                
    fclose(infile);

    return structure;
}