CAirportDatabase* CAirportDatabaseList::addNewDBEntry( const CString& _strDBName) 
{
	CString strName = _strDBName;
	int nPos = checkIfIncludeKeyWords(strName.GetBuffer());
	if (nPos != -1)
	{
		CString strLeft(_T(""));
		CString strRight(_T(""));
		strLeft = strName.Left(nPos);
		strRight = strName.Right(strName.GetLength() - nPos - 1);
		strName = strLeft + strRight;
	}

	for(int i=0;i<getDBCount();i++)
	{
		if(strName.CompareNoCase(getAirportDBByIndex(i)->getName())==0)
		{
			CString errormsg ;
			errormsg.Format(_T("%s has existed "),_strDBName) ;
			MessageBox(NULL,errormsg,"Warning",MB_OK) ;
			return NULL ;
		}
	}
	CString strSharePath(_T(""));
	CString strARCPath(_T(""));
	strSharePath.Format(_T("%s\\ImportDB\\%s.mdb"),PROJMANAGER->GetAppPath(),strName);
	strARCPath.Format(_T("%s\\%s"),PROJMANAGER->GetAppPath(),_T("Databases\\arc.mdb"));

	CShareTemplateDatabase* _pDB = new CShareTemplateDatabase(strARCPath,strSharePath);

	//setup database for new airport database
	CString strPartsSourceFile(_T(""));
	CString strPartsDestinationFile(_T(""));

	strPartsSourceFile.Format(_T("%s\\ArctermDB\\temp\\project.mdb"),PROJMANAGER->GetAppPath());
	if (!PathFileExists(strSharePath))
	{
		CopyFile(strPartsSourceFile,strSharePath,FALSE);

		AirportDatabaseConnection pConnectionPtr(strSharePath);
		CPartsAndShareTemplateUpdate shareTemplateDataBaseUpdater;
		if(!shareTemplateDataBaseUpdater.Update(&pConnectionPtr)) 
		{
			CString strError(_T(""));
			strError.Format(_T("Update the new Template DataBase error."));
			MessageBox(NULL,strError,"Warning",MB_OK);
			return NULL;
		}
	}
	_pDB->setName(strName);
	_pDB->SaveAirport();

	m_vAirportDB.push_back(_pDB) ;
	return _pDB ;
}
void CAirportDatabaseList::ReadAirportDBData()
{
	clear() ;
	CString SQL ;
    SQL.Format(_T("SELECT * FROM TB_PROJECT_AIRPORTDB")) ;
	CADORecordset recordset ;
	long count ;
	try
	{
		CADODatabase::ExecuteSQLStatement(SQL,count,recordset,DATABASESOURCE_TYPE_ACCESS_GLOBALDB) ;
	}
	catch (CADOException e)
	{
		e.ErrorMessage() ;
		return ;
	}
	CShareTemplateDatabase* _pDB = NULL; 
	int id = -1 ;
	CString _name ;

	CString strSharePath(_T(""));
	CString strARCPath(_T(""));
	strARCPath.Format(_T("%s\\%s"),PROJMANAGER->GetAppPath(),_T("Databases\\arc.mdb"));
	while(!recordset.IsEOF())
	{
	   recordset.GetFieldValue(_T("ID"),id) ;
	   recordset.GetFieldValue(_T("AIRPORTDB_NAME"),_name) ;
	  
	   int nPos = checkIfIncludeKeyWords(_name.GetBuffer());
	   if (nPos != -1)
	   {
		   CString strLeft(_T(""));
		   CString strRight(_T(""));
		   strLeft = _name.Left(nPos);
		   strRight = _name.Right(_name.GetLength() - nPos - 1);
		   _name = strLeft + strRight;
	   }

	   strSharePath.Format(_T("%s\\ImportDB\\%s.mdb"),PROJMANAGER->GetAppPath(),_name);
	   _pDB  = new CShareTemplateDatabase(strARCPath,strSharePath) ;
	   _pDB->setName(_name) ;
	   _pDB->SetID(id) ;
	   if (!getAirportDBByName(_name))
	   {
		    m_vAirportDB.push_back(_pDB) ;
	   }

	   if(recordset.GetFieldValue(_T("VERSION"),id))
		   _pDB->m_nVersion = id ;
	   else
		   _pDB->m_nVersion = 0 ;
	   recordset.MoveNextData() ;
	}
}
Esempio n. 3
0
// FIXME: strRemoveQuote, strLeft, strRight functions have a leak
char * strRemoveQuote(const char * str)
{
    char * tmp;
    tmp = sopstrdup(str);
    if(strlen(tmp) > 0)
    {
        //REMOVE LEADING QUOTE
        while (strcmp(strLeft(tmp,1),"\"") == 0)
        {
            tmp = strRight(tmp,strlen(tmp) - 1);
        }
    }
    if(strlen(tmp) > 0)
    {
        //REMOVE TRAILING QUOTE
        while (strcmp(strRight(tmp,1),"\"") == 0)
        {
            tmp = strLeft(tmp,strlen(tmp) - 1);
        }
    }
    return tmp;
}
Esempio n. 4
0
void FindReplace(Str& strContents, const char* pTag, const char* pValue)
{
  if (strcmp(pTag, pValue) == 0)
    return;
  for (int nPos = strContents.Find(pTag); nPos >= 0; nPos = strContents.Find(pTag))
  {
    int nRightLen = strContents.GetLength() - strlen(pTag) - nPos;
    Str strLeft(strContents.Left(nPos));
    Str strRight(strContents.Right(nRightLen));
    strLeft += pValue;
    strLeft += strRight;
    strContents = strLeft;
  }
}
CShareTemplateDatabase* CAirportDatabaseList::getAirportDBByName(const CString strName)
{
	CString strDBName = strName;
	int nPos = checkIfIncludeKeyWords(strDBName.GetBuffer());
	if (nPos != -1)
	{
		CString strLeft(_T(""));
		CString strRight(_T(""));
		strLeft = strDBName.Left(nPos);
		strRight = strDBName.Right(strDBName.GetLength() - nPos - 1);
		strDBName = strLeft + strRight;
	}

	int _iCount = m_vAirportDB.size();
	for( int i=0; i<_iCount; i++ )
	{
		if( (m_vAirportDB[i]->getName()).CompareNoCase(strDBName) == 0)
			return m_vAirportDB[i];
	}

	return NULL;
}
Esempio n. 6
0
void load_trace_txt ( char* fname ) 
{
	std::string str, word;
	char buf[1024];

	unsigned long totalBytes = getFileSize ( fname );
	unsigned long currBytes = 0;

	FILE* fp = fopen ( fname, "rt" );
	int c;
	std::vector<std::string> changestates;
	changestates.push_back ( "x" );			// 0 = BIN_NOTUSED
	changestates.push_back ( "c" );			// 1 = BIN_CREATE
	changestates.push_back ( "u" );			// 2 = BIN_CHANGE
	changestates.push_back ( "s" );			// 3 = BIN_SWITCH
	changestates.push_back ( "-" );			// 4 = BIN_REUSE
	changestates.push_back ( "D" );

	Call cl;
	Event e;
	int lin = 0;
	int max_lin = 5000;
	std::string szstr;
	int sz;
	unsigned long cstart = 0;
	int cnum = 0;

	while (!feof(fp) && lin < max_lin) {
		
		currBytes = getFilePos ( fp );
		printf ( "%d (%.2f%%)\n", currBytes, currBytes*100.0f/totalBytes );

		fgets ( buf, 1024, fp );
		str = buf;
		int bin = 0;		
		str = strTrim ( str );

		e.name = word;
		
		if ( str.compare (0, 2, "C:") == 0 ) {
			/*word = strSplit ( str, " " );	
			word = strSplit ( str, " " );	cl.bin_id = strToI(word);
			word = strSplit ( str, " " );	cl.size = strToI(word); 
			word = strSplit ( str, " " );	cl.obj_id = strToLI(word);
			word = strSplit ( str, " " );	cl.val_id = strToLI(word);
			word = strSplit ( str, " " );	cl.name = word;
			mCalls.push_back ( cl );*/
			cnum++;			
		} else if ( str.compare ( 0, 2, "FR" ) == 0 ) {
			e.count = 1;
			for (int n=0; n < NUM_BIN; n++ ) {
				e.bin_id[n] = -1;
				e.bin_change[n] = -1;
			}			
			mEvents.push_back ( e );
		} else if ( str.compare ( 0, 2, "Dr" ) == 0 ) {
			e.count = 1;
			int bin = 0;
			word = strLeft ( str, 8 );
			str = strTrim ( str );			
			while ( str.length() > 0 ) {
				word = strSplit ( str, " " );				
				c = strExtract ( word, changestates );
				szstr = strParse ( word, "[", "]" );
				e.bin_id[bin] = strToI ( word );
				e.bin_change[bin] = c;		
				e.bin_size[bin] = strToI ( szstr );
				bin++;				
			}	
			e.call_start = cstart;
			e.call_num = cnum;
			if ( e.bin_size[BIN_DRAW] > mMaxSize ) mMaxSize = e.bin_size[BIN_DRAW];
			mEvents.push_back ( e );			
			cstart += cnum;
		}	
		
		lin++;
	}

	fclose ( fp );
}
Esempio n. 7
0
	void CCBMFontConfiguration::parseConfigFile(const char *controlFile)
	{	
		std::string fullpath = CCFileUtils::fullPathFromRelativePath(controlFile);

        CCFileData data(fullpath.c_str(), "rb");
        unsigned long nBufSize = data.getSize();
        char* pBuffer = (char*) data.getBuffer();

        CCAssert(pBuffer, "CCBMFontConfiguration::parseConfigFile | Open file error.");

        if (!pBuffer)
        {
            return;
        }

        // parse spacing / padding
        std::string line;
        std::string strLeft(pBuffer, nBufSize);
        while (strLeft.length() > 0)
        {
            int pos = strLeft.find('\n');

            if (pos != (int)std::string::npos)
            {
                // the data is more than a line.get one line
                line = strLeft.substr(0, pos);
                strLeft = strLeft.substr(pos + 1);
            }
            else
            {
                // get the left data
                line = strLeft;
                strLeft.erase();
            }

            if(line.substr(0,strlen("info face")) == "info face") 
            {
                // XXX: info parsing is incomplete
                // Not needed for the Hiero editors, but needed for the AngelCode editor
                //			[self parseInfoArguments:line];
                this->parseInfoArguments(line);
            }
            // Check to see if the start of the line is something we are interested in
            else if(line.substr(0,strlen("common lineHeight")) == "common lineHeight")
            {
                this->parseCommonArguments(line);
            }
            else if(line.substr(0,strlen("page id")) == "page id")
            {
                this->parseImageFileName(line, controlFile);
            }
            else if(line.substr(0,strlen("chars c")) == "chars c")
            {
                // Ignore this line
            }
            else if(line.substr(0,strlen("char")) == "char")
            {
                // Parse the current line and create a new CharDef
                ccBMFontDef characterDefinition;
                this->parseCharacterDefinition(line, &characterDefinition);

                // Add the CharDef returned to the charArray
                m_pBitmapFontArray[ characterDefinition.charID ] = characterDefinition;
            }
            else if(line.substr(0,strlen("kernings count")) == "kernings count")
            {
                this->parseKerningCapacity(line);
            }
            else if(line.substr(0,strlen("kerning first")) == "kerning first")
            {
                this->parseKerningEntry(line);
            }
        }
	}
Esempio n. 8
0
void BuildFileName(	CUString strFormat,
					CUString strArray[NUMFILENAME_IDS],
					CUString& strName,CUString& strDir)
{

	CUString strTmp( strFormat );
	int		nPos = 0;
	int		i;

	for ( i=0; i<NUMFILENAME_IDS; i++ )
	{
		strArray[i] = FixFileNameString( strArray[i] );
	}

	// loop through all the tokens
	while ( (( nPos = strTmp.Find( _T( '%' ),nPos ) ) >=0 ) && ( nPos + 1 < strTmp.GetLength() ) )
	{
		ENUM_FILENAME_CONVERTS	convertType = FILENAME_CONVERT_NONE;
		int						nPercentID = 0;
		int						nSkipChars = 2;

		WCHAR chEval = strTmp.GetAt( nPos + 1 );

		if ( _W( 'l' ) == chEval )
		{
			convertType = FILENAME_CONVERT_LOWER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'u' ) == chEval )
		{
			convertType = FILENAME_CONVERT_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'c' ) == chEval )
		{
			convertType = FILENAME_CONVERT_FCEW_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'f' ) == chEval )
		{
			convertType = FILENAME_CONVERT_FC_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}

		// Get %ID number
		switch ( chEval )
		{
			case '1': nPercentID =  0; break;
			case '2': nPercentID =  1; break;
			case '3': nPercentID =  2; break;
			case '4': nPercentID =  3; break;
			case '5': nPercentID =  4; break;
			case '6': nPercentID =  5; break;
			case '7': nPercentID =  6; break;
			case '8': nPercentID =  7; break;
			case 'Y': nPercentID =  8; break;
			case 'G': nPercentID =  9; break;
			case 'A': nPercentID = 10; break;

			default:
				nPercentID = -1;
				nPos++;
			break;
		}

	
		if ( nPercentID >= 0 && nPercentID < NUMFILENAME_IDS )
		{
			CUString strLeft( strTmp.Left( nPos ) );
			CUString strMid( strArray[ nPercentID ] );
			CUString strRight( strTmp.Right( strTmp.GetLength() - nPos - nSkipChars ) );

			// do filename mangling
			strMid = FormatTrackNameString( strMid, convertType );

			strTmp = strLeft + strMid + strRight;

		}
		else
		{
			// Delete token
//			strTmp = strTmp.Left( nPos ) + strTmp.Right( strTmp.GetLength() - nPos - 1 );
		}
	}

	// Split result in a directory and file name portion
	// Search for last backslash
	nPos = strTmp.ReverseFind( _T( '\\' ) );

	if ( nPos >= 2 )
	{
		// OK, we've found the backsplash, do the split
		strDir = strTmp.Left( nPos + 1 );
		strName = strTmp.Right( strTmp.GetLength() - nPos - 1 );
	}
	else
	{
		// Only a filename, just assign the string to the filename and clear the directory
		strDir = _T( "" );
		strName = strTmp;
	}

	strDir.TrimLeft();
	strDir.TrimRight();

	// remove spaces before the directory separator and double backslashes
	INT	nIndex = 0;
	while ( nIndex < strDir.GetLength() )
	{
		if ( _T( '\\' ) == strDir[ nIndex ] )
		{
			if ( nIndex > 0 )
			{
				if ( ( _T( '\\' ) == strDir[ nIndex - 1 ] ) || 
					 ( _T( ' ' ) == strDir[ nIndex - 1 ] ))
				{
					strDir = strDir.Left( nIndex ) + strDir.Mid( nIndex + 1 );
					nIndex = 0;
					continue;
				}
			}
		}
		if ( _T( ' ' ) == strDir[ nIndex ] )
		{
			if ( nIndex > 0 )
			{
				if ( ( _T( '\\' ) == strDir[ nIndex - 1 ] ) )
				{
					strDir = strDir.Left( nIndex ) + strDir.Mid( nIndex + 1 );
					nIndex = 0;
					continue;
				}
			}
		}

		nIndex++;

	}

	strDir.TrimLeft();
	strDir.TrimRight();

	strName.TrimLeft();
	strName.TrimRight();

}