コード例 #1
0
ファイル: sdlsnake.c プロジェクト: jorjuato/IORExperiments
//------------------------------------------------------------  OnExit()
//
void OnExit() {
	
	fclose(data);
   	WacomClose();
	CloseErrorLog();
	SDL_Quit();
    exit(APPSUCCESS);
}
コード例 #2
0
bool ErrorLog::WriteErrorString(char* ErrorString)
{
	if(!ErrorString){
		return false;
	}
	if(mFileBeingAccessed){
		return false;
	}
	if(!OpenErrorLog()){
		return false;
	}

	fputs(ErrorString, mFilePointer);
	fputc('\n', mFilePointer); //NEW LINE CHARACTER IS REQUIRED.
	CloseErrorLog();
	return true;
}
コード例 #3
0
void ErrorLog::AddFinalErrorLogString()
{
		time_t OurTime = time(NULL);
	tm* timestruct = localtime(&OurTime); //LOCAL TIME IS REQUIRED.
	char InitialString[500];
	
	if(!OpenErrorLog()){
		return;
	}
	
	sprintf(InitialString, "--------------------------------------------");
	fputs(InitialString, mFilePointer);
	fputc('\n', mFilePointer);
	sprintf(InitialString, "Logging Ended %d/%d/%d - %2.2d:%2.2d", timestruct->tm_mon + 1, timestruct->tm_mday, 1900 + timestruct->tm_year, timestruct->tm_hour, timestruct->tm_min);
	fputs(InitialString, mFilePointer);
	fputc('\n', mFilePointer);
	
	CloseErrorLog();
}
コード例 #4
0
void ErrorLog::AddInitialErrorLogString()
{
	time_t OurTime = time(NULL);
	tm* timestruct = localtime(&OurTime); //LOCAL TIME IS REQUIRED.
	char InitialString[500];
	sprintf(InitialString, "Charles Cox's Error Log and Reporting Dynamic (C2ELRD) (c)2001 Charles Cox - Log #%d", mErrorLogID); //LET US NOT FORGET WHO WROTE THIS THING.
	if(!OpenErrorLog()){
		return;
	}
	fputs(InitialString, mFilePointer);
	fputc('\n', mFilePointer);
	sprintf(InitialString, "Logging Started %d/%d/%d - %2.2d:%2.2d", timestruct->tm_mon + 1, timestruct->tm_mday, 1900 + timestruct->tm_year, timestruct->tm_hour, timestruct->tm_min);
	fputs(InitialString, mFilePointer);
	fputc('\n', mFilePointer);
	sprintf(InitialString, "--------------------------------------------");
	fputs(InitialString, mFilePointer);
	fputc('\n', mFilePointer);
	CloseErrorLog();
}
コード例 #5
0
bool ErrorLog::GetInternalErrorInf(int ErrorNumber)
{
	//RIGHT. OKAY. THIS FILLS THE TEMPORARY ERROR INFORMATION STRUCTURE WITH STUFF.
	//WE CANNOT INITIALIZE AN INSTANCE OF AN ERRORINFO UNTIL WE HAVE THE STRING AND THE ID.
	long FirstAsterixPoint;
	long OurErrorFrontAsterixPoint;
	long OurErrorBackAsterixPoint;
	long CurrentPos = 0;
	long NumToMalloc;
	char * TempBuf;
	char * PureString;
	int StringPos;
	int PureStringStartPos;
	int PureStringEndPos;
	int PureStringLen;
	int StringLen;
	
	int CurrentError;
	//FIRST, ELIMINATE WRONG CASES.
	if(ErrorNumber < 0 || ErrorNumber >= mNumberOfErrors || !mErrorFileName || mErrorLogID < 0){
		return false;
	}

	//NOW, WE UTILIZE AN ALGORITHM TO SEARCH THROUGH FILE. START BY MOVING TO THE FIRST ASTERIX.
	if(!OpenErrorLog()){
		return false;
	}
	fseek(mFilePointer, 0, SEEK_SET);

	FirstAsterixPoint = SeekToNextAsterix();
	if(FirstAsterixPoint == -1){
		CloseErrorLog();
		return false;
	} //WE CAN NOW USE THIS FIRST ASTERIX POINT AS AN OFFSET.

	OurErrorFrontAsterixPoint = FirstAsterixPoint;

	for(CurrentError = -1; CurrentError < ErrorNumber - 1; CurrentError++){
		SeekToNextAsterix();
		OurErrorFrontAsterixPoint = SeekToNextAsterix();
	}

	//WE NOW SHOULD BE AT THE FIRST ASTERIX OF OUR DESIRED LINE.
	//RUN TO THE NEXT ASTERIX, RETRIEVE THE DIFFERENCE, AND THAT'S OUR MALLOC AMOUNT... ADD 3 FOR NEWLINE, ENDCHAR, AND LF WACKINESS.
	OurErrorBackAsterixPoint = SeekToNextAsterix();
	if(OurErrorFrontAsterixPoint == -1 || OurErrorBackAsterixPoint == -1){
		CloseErrorLog();
		return false;
	}
	NumToMalloc = OurErrorBackAsterixPoint - OurErrorFrontAsterixPoint;
	TempBuf = new char[NumToMalloc + 3];
	//SHOULD BE ABLE TO SET BACK TO THE LAST ASTERIX, THEN DO AN FGETS, STRIP NEW LINE.
	fseek(mFilePointer, OurErrorFrontAsterixPoint, SEEK_SET);
	fgets(TempBuf, NumToMalloc, mFilePointer);
	//THAT HAD OUGHT TO BE ALL WE NEED WITH THE FILE.
	CloseErrorLog();
	StripStringNewLine(TempBuf);
	StringLen = strlen(TempBuf); //WE HAD BETTER BE SURE.


	//TADA. NOW PARSE THE STRING.
	for(StringPos = 0; StringPos < StringLen;  StringPos++){
		if(TempBuf[StringPos] == '-' && TempBuf[StringPos + 1] == ' ' && TempBuf[StringPos - 1] == ' '){ //THIS LOOKS LIKE OUR START POINT.
			PureStringStartPos = StringPos + 2;
			break;
		}
	}
	if(PureStringStartPos == -1){
		delete [] TempBuf;
		return false;
	}
	PureStringEndPos = StringLen - 3; //ONE FOR '\0', ONE FOR *, AND ONE FOR ZERO-BASED COUNTING SYSTEM
	PureStringLen = PureStringEndPos - PureStringStartPos;
	PureString = new char[StringLen + 2];
	for(int i = 0, k = PureStringStartPos; i < StringLen; i++, k++){
		PureString[i] = TempBuf[k];
	}
	PureString[i] = '\0';
	//WE GOT IT.
	delete [] TempBuf;
	ErrorInformation EInfo(ErrorNumber, PureString);
	mTemporaryInfo = EInfo;
	delete [] PureString;
	return true;
}