Ejemplo n.º 1
0
void exportMetaData(CFURLRef url, struct metaData *mtData){
	
	CFStringRef UrlToPath;
	char path[1024];
	
	UrlToPath = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
	CFStringGetCString(UrlToPath, path, sizeof(path), kCFStringEncodingUTF8);
	
	FILE * handleFile;
	handleFile = fopen(path, "r");
	
	if(handleFile == NULL){
		printf("Error opening file\n");
		return;
	}
	
	char buff[4000];
	char strHeader[8000] = {}, strTitle[8000] = {}, strKeywds[8000] = {};
	char strExpdata[1024] = {}, strJrnlAuthor[4000] = {};
	char strJrnlTitle[1024] = {}, strJrnlRef[1024] = {};
	char strResolution[1024] = {};
	
	int JRNL_AUTH = 0;	//Author flag :: To know if we should skip the number or not
	int JRNL_TITL = 0; // Title flag
	int JRNL_REF = 0;
	int TITLE = 0;
	int KEYWDS = 0;
	int EXPDTA = 0;
	
	
	//Move through the file, line by line
	while (fgets(buff, sizeof(buff), handleFile)){
		
		char *split;
		split = strtok(buff, " "); //Split the line by spaces.
		//Sort through the first element and match against it.
		//If match, process the rest of the data.
		
		
		//This is going to be horrible :(
		
		if (strcmp(split, "HEADER") == 0 ){ //Lets pull out the header.
			split = strtok(NULL, " "); // Lets skip the HEADER element
			while (split != NULL) {
				strcat(strHeader, split);
				strcat(strHeader, " ");
				split = strtok(NULL, " ");
			}
			cleanupString(strHeader);
			if( strHeader != NULL){
				strcpy(mtData->Header, strHeader);
			}
			continue;
		}
        
        //Quick check if header exists - If not - file does not conform to pdb standard
        //Return, just incase...
        if(mtData->Header[0] == 0){
            return;
        }
		
		if (strcmp(split, "TITLE") == 0 ){ //Lets pull out the title
			split = strtok(NULL, " "); // Lets skip the TITLE element
			if (TITLE != 0) {
				split = strtok(NULL, " ");	//Skip the number!
			}
			while (split != NULL){
				strcat(strTitle, split);
				strcat(strTitle, " ");
				split = strtok(NULL, " ");
			}
			TITLE = 1;
			cleanupString(strTitle);
			if( strTitle != NULL){
				strcpy(mtData->Title, strTitle);
			}
			continue;
		}
		
		if (strcmp(split, "KEYWDS") == 0 ){ //Lets pull out the keywords
			split = strtok(NULL, " "); // Lets skip the KEYWDS element
			if (KEYWDS != 0) {
				split = strtok(NULL, " ");	//Skip the number!
			}
			while (split != NULL) {
				strcat(strKeywds, split);
				strcat(strKeywds, " ");
				split = strtok(NULL, " ");
			}
			KEYWDS = 1;
			cleanupString(strKeywds);
			if( strKeywds != NULL){
				strcpy(mtData->Keywds, strKeywds);
			}
			continue;
		}
		
		if (strcmp(split, "EXPDTA") == 0 ){ //Lets pull out the experimental data
			split = strtok(NULL, " "); // Lets skip the EXPDTA element
			if (EXPDTA != 0) {
				split = strtok(NULL, " ");	//Skip the number!
			}
			while (split != NULL) {
				strcat(strExpdata, split);	//Move through the rest of the elements and add them to the string
				strcat(strExpdata, " ");	//Insert a space between elements...
				split = strtok(NULL, " ");	//Iterate
			}
			EXPDTA = 1;
			cleanupString(strExpdata);
			if( strExpdata != NULL){
				strcpy(mtData->Expdata, strExpdata);
			}
			continue;	//End processing of this line
		}
		
		//Start JRNL tag
		if (strcmp(split, "JRNL") == 0){
			
			split = strtok(NULL, " "); // Skip the first element.
			
			//Now lets pull out author information
			
			if (strcmp(split, "AUTH") == 0){
				split = strtok(NULL, " "); //Skip the AUTH element.
				if (JRNL_AUTH != 0) {
					split = strtok(NULL, " ");	//Skip the number!
				}
				strcat(strJrnlAuthor, split);
				JRNL_AUTH = 1;
				cleanupString(strJrnlAuthor);
				if( strJrnlAuthor != NULL){
					strcpy(mtData->JrnlAuthor, strJrnlAuthor);
				}
				continue;
			}
			
			//Pull out the journal article info
			
			//Article title
			if (strcmp(split, "TITL") == 0) {
				split = strtok(NULL, " "); //Skip the TITL element.
				if (JRNL_TITL != 0) {
					split = strtok(NULL, " ");	//Skip the number!
				}
				while (split != NULL){
					strcat(strJrnlTitle, split);
					strcat(strJrnlTitle, " ");
					split = strtok(NULL, " ");
				}
				JRNL_TITL = 1;
				cleanupString(strJrnlTitle);
				if( strJrnlTitle != NULL){
					strcpy(mtData->JrnlTitle, strJrnlTitle);
				}
				continue;
			}
			
			//Which Journal
			if (strcmp(split, "REF") == 0) {
				split = strtok(NULL, " "); //Skip the REF element.
				if (JRNL_REF != 0) {
					split = strtok(NULL, " ");	//Skip the number!
				}
				while (split != NULL){
					strcat(strJrnlRef, split);
					strcat(strJrnlRef, " ");
					split = strtok(NULL, " ");
				}
				JRNL_REF = 1;
				cleanupString(strJrnlRef);
				if( strJrnlRef != NULL){
					strcpy(mtData->JrnlRef, strJrnlRef);
				}
				continue;
			}
			continue;
		}	//End JRNL tag
		
		
		//Start REMARK tag
		
		if (strcmp(split, "REMARK") == 0) {
			split = strtok(NULL, " ");	//Skip the number
			split = strtok(NULL, " ");
            
            
            //Quick check if title exists - If not - file does not conform to pdb standard
            //Return, just incase...
            if(mtData->Title[0] == 0){
                return;
            }
			
			//Pull out resolution if possible
			
			if (strcmp(split, "RESOLUTION.") == 0) {
				split = strtok(NULL, " ");
				while (split != NULL) {
					strcat(strResolution, split);
					strcat(strResolution, " ");
					split = strtok(NULL, " ");
				}
				cleanupString(strResolution);
				if( strResolution != NULL){
					strcpy(mtData->Resolution, strResolution);
				}
				continue;
			}else{
                continue;
            }
			
			//End REMARK tag
		}
		//End file itteration
	}
}
Ejemplo n.º 2
0
void DrasculaEngine::converse(int index) {
	debug(4, "converse(%d)", index);

	char fileName[20];
	sprintf(fileName, "op_%d.cal", index);
	Common::SeekableReadStream *stream = _archives.open(fileName);
	if (!stream)
		error("missing data file %s", fileName);

	int game1 = kDialogOptionUnselected,
		game2 = kDialogOptionUnselected,
		game3 = kDialogOptionUnselected;
	char phrase1[128], phrase2[128], phrase3[128], phrase4[128];
	char sound1[13], sound2[13], sound3[13], sound4[13];
	int phrase1_bottom, phrase2_bottom, phrase3_bottom, phrase4_bottom;
	int answer1, answer2, answer3;

	breakOut = 0;

	selectVerb(kVerbNone);

	TextResourceParser p(stream, DisposeAfterUse::YES);

	p.parseString(phrase1);
	p.parseString(phrase2);
	p.parseString(phrase3);
	p.parseString(phrase4);
	p.parseString(sound1);
	p.parseString(sound2);
	p.parseString(sound3);
	p.parseString(sound4);
	p.parseInt(answer1);
	p.parseInt(answer2);
	p.parseInt(answer3);

	// no need to delete the stream, since TextResourceParser takes ownership
	// delete stream;

	if (currentChapter == 2 && !strcmp(fileName, "op_5.cal") && flags[38] == 1 && flags[33] == 1) {
		Common::strlcpy(phrase3, _text[405], 128);
		strcpy(sound3, "405.als");
		answer3 = 31;
	}

	if (currentChapter == 6 && !strcmp(fileName, "op_12.cal") && flags[7] == 1) {
		Common::strlcpy(phrase3, _text[273], 128);
		strcpy(sound3, "273.als");
		answer3 = 14;
	}

	if (currentChapter == 6 && !strcmp(fileName, "op_12.cal") && flags[10] == 1) {
		Common::strlcpy(phrase3, _text[274], 128);
		strcpy(sound3, "274.als");
		answer3 = 15;
	}

	cleanupString(phrase1);
	cleanupString(phrase2);
	cleanupString(phrase3);
	cleanupString(phrase4);

	loadPic("car.alg", backSurface);
	// TODO code here should limit y position for mouse in dialog menu,
	// but we can't implement this as there is lack in backend functionality
	// from 1(top) to 31
	color_abc(kColorLightGreen);

	while (breakOut == 0 && !shouldQuit()) {
		updateRoom();

		if (musicStatus() == 0 && roomMusic != 0) {
			if (currentChapter == 3 || currentChapter == 5) {
				playMusic(roomMusic);
			} else {	// chapters 1, 2, 4, 6
				if (flags[11] == 0)
					playMusic(roomMusic);
			}
		}

		updateEvents();
		flushKeyBuffer();

		phrase1_bottom = 8 * print_abc_opc(phrase1, 2, game1);
		phrase2_bottom = phrase1_bottom + 8 * print_abc_opc(phrase2, phrase1_bottom + 2, game2);
		phrase3_bottom = phrase2_bottom + 8 * print_abc_opc(phrase3, phrase2_bottom + 2, game3);
		phrase4_bottom = phrase3_bottom + 8 * print_abc_opc(phrase4, phrase3_bottom + 2, kDialogOptionUnselected);

		if (_mouseY > 0 && _mouseY < phrase1_bottom) {
			if (game1 == kDialogOptionClicked && _color != kColorWhite)
				color_abc(kColorWhite);
			else if (game1 != kDialogOptionClicked && _color != kColorLightGreen)
				color_abc(kColorLightGreen);

			print_abc_opc(phrase1, 2, kDialogOptionSelected);

			if (_leftMouseButton == 1) {
				delay(100);
				game1 = kDialogOptionClicked;
				talk(phrase1, sound1);
				response(answer1);
			}
		} else if (_mouseY > phrase1_bottom && _mouseY < phrase2_bottom) {
			if (game2 == kDialogOptionClicked && _color != kColorWhite)
				color_abc(kColorWhite);
			else if (game2 != kDialogOptionClicked && _color != kColorLightGreen)
				color_abc(kColorLightGreen);

			print_abc_opc(phrase2, phrase1_bottom + 2, kDialogOptionSelected);

			if (_leftMouseButton == 1) {
				delay(100);
				game2 = kDialogOptionClicked;
				talk(phrase2, sound2);
				response(answer2);
			}
		} else if (_mouseY > phrase2_bottom && _mouseY < phrase3_bottom) {
			if (game3 == kDialogOptionClicked && _color != kColorWhite)
				color_abc(kColorWhite);
			else if (game3 != kDialogOptionClicked && _color != kColorLightGreen)
				color_abc(kColorLightGreen);

			print_abc_opc(phrase3, phrase2_bottom + 2, kDialogOptionSelected);

			if (_leftMouseButton == 1) {
				delay(100);
				game3 = kDialogOptionClicked;
				talk(phrase3, sound3);
				response(answer3);
			}
		} else if (_mouseY > phrase3_bottom && _mouseY < phrase4_bottom) {
			print_abc_opc(phrase4, phrase3_bottom + 2, kDialogOptionSelected);

			if (_leftMouseButton == 1) {
				delay(100);
				talk(phrase4, sound4);
				breakOut = 1;
			}
		} else if (_color != kColorLightGreen)
			color_abc(kColorLightGreen);

		_system->delayMillis(10);
		updateScreen();
	} // while (breakOut == 0)

	if (currentChapter == 2)
		loadPic(menuBackground, backSurface);
	else
		loadPic(99, backSurface);
}