CSPString AfxGetFilePath( CSPString strDir, CSPString strFileTitle ) { if( strDir.GetLength() > 0 && ( strDir[strDir.GetLength()-1] == '\\' || strDir[strDir.GetLength()-1] == '/' ) ) strDir = strDir.Left( strDir.GetLength()-1 ); strDir += STRING_DIRSEP; return ( strDir + strFileTitle ); }
BOOL CDomainContainer::Store( LPCTSTR lpszFileName ) { if( NULL == lpszFileName || strlen(lpszFileName) <= 0 ) return FALSE; CSPFile file; if( file.Open( lpszFileName, CSPFile::modeCreate | CSPFile::modeWrite ) ) { for( int i=0; i<GetSize(); i++ ) { CDomain & domain = ElementAt(i); CSPString strDomain = domain.m_strName; file.Write( strDomain.GetBuffer(strDomain.GetLength()+1), strDomain.GetLength() ); file.Write( STRING_CRLF, strlen(STRING_CRLF) ); for( int k=0; k<domain.GetSize(); k++ ) { CSPString strStock = domain[k]; if( strStock.GetLength() > 0 ) { file.Write( strStock.GetBuffer(strStock.GetLength()), strStock.GetLength() ); file.Write( STRING_CRLF, strlen(STRING_CRLF) ); } } file.Write( STRING_CRLF, strlen(STRING_CRLF) ); } file.Close(); return TRUE; } return FALSE; }
CSPString AfxGetFileDirectory( CSPString strPathName, CSPString strDefault ) { if( strPathName.IsEmpty() ) return strDefault; CSPString strResult = strPathName; if( strResult.GetLength() > 0 ) { int nIndex = strResult.ReverseFind( '\\' ); if( -1 == nIndex ) nIndex = strResult.ReverseFind( '/' ); if( -1 == nIndex ) strResult = strDefault; else strResult = strResult.Left( nIndex ); } if( strResult.GetLength() <= 0 ) return strDefault; int nLen = strResult.GetLength(); if( nLen > 0 && strResult[nLen-1] != '\\' && strResult[nLen-1] != '/' ) strResult += STRING_DIRSEP; return strResult; }
int CStock::PrepareBaseInfo( BOOL bReload ) { // Load From File PrepareData( CStock::dataBasetext, 0, bReload ); // Save To pText int nTextLen = m_nBaseTextLen; char * pText = NULL; if( m_pBaseText && nTextLen > 0 ) { pText = new CHAR[nTextLen+1]; if( pText ) memcpy( pText, m_pBaseText, nTextLen ); if( pText ) pText[nTextLen] = 0; } int nIntroLen = SLH_MAX * 80; if( !AllocBaseTextMem( nIntroLen + m_nBaseTextLen + 10 ) ) return 0; int nCount = 0; for( int nVariantID = SLH_MIN; nVariantID <= SLH_MAX; nVariantID ++ ) { CSPString strTemp = AfxGetVariantName( nVariantID, TRUE ); strTemp += ": \t"; strTemp += (LPCTSTR)AfxGetVariantDispString( nVariantID, m_stockinfo, NULL ); strTemp += STRING_CRLF; SP_ASSERT( nCount + strTemp.GetLength() < nIntroLen ); if( nCount + strTemp.GetLength() < nIntroLen ) { nCount += strTemp.GetLength(); strcat( m_pBaseText, (LPCTSTR)strTemp ); } } nCount += strlen(STRING_CRLF); strcat( m_pBaseText, STRING_CRLF ); nCount += strlen(STRING_CRLF); strcat( m_pBaseText, STRING_CRLF ); if( pText && nCount + nTextLen < m_nBaseTextLen ) { nCount += nTextLen; strcat( m_pBaseText, pText ); } if( pText ) delete [] pText; return nCount; }
BOOL CShenglong::GetAccurateRoot( const char * rootpath, char *accurateroot, int maxlen ) { if( 0 == rootpath || strlen(rootpath)==0 ) return FALSE; // get rootpath CSPString strRoot = rootpath; int nLen = strRoot.GetLength(); if( strRoot[nLen-1] != '\\' && strRoot[nLen-1] != '/' ) strRoot += CHAR_DIRSEP; nLen = strRoot.GetLength(); SP_ASSERT( FALSE ); return FALSE; }
////////////////////////////////////////////////////////////////////////////////// // database functions BOOL AfxInitializeDB( LPSTR lpErr, UINT nMaxSize ) { if( lpErr && nMaxSize > 0 ) memset( lpErr, 0, nMaxSize ); if( !CStDatabase::CreateSelfDB( AfxGetProfile().GetSelfDBPath() ) ) { if( lpErr ) strncpy( lpErr, db_errcreateselfdb, min(nMaxSize-1,strlen(db_errcreateselfdb)) ); return FALSE; } if( !AfxGetDB().SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB ) ) { if( lpErr ) strncpy( lpErr, db_errrootpath, min(nMaxSize-1,strlen(db_errrootpath)) ); return FALSE; } CSPString strQianlongPath = AfxGetProfile().GetQianlongPath(); if( strQianlongPath.GetLength() > 0 && !AfxGetDB().AddAssistantRootPath( strQianlongPath, IStStore::dbtypeQianlong ) ) { if( lpErr ) strncpy( lpErr, db_errqianlongpath, min(nMaxSize-1,strlen(db_errqianlongpath)) ); return FALSE; } return TRUE; }
BOOL CDomainContainer::Load( LPCTSTR lpszFileName ) { if( NULL == lpszFileName || strlen(lpszFileName) <= 0 ) return FALSE; BOOL bOK = FALSE; CSPFile file; if( file.Open( lpszFileName, CSPFile::modeRead ) ) { DWORD dwLen = file.GetLength(); if( 0 == dwLen || dwLen > SF_MAX_DOMAINFILE_LENGTH ) { file.Close(); return FALSE; } SetSize( 0, min(dwLen / 300, 20) ); CDomain domain; CSPString rString; while( file.ReadString( rString ) ) { int nIndex = rString.Find( "\r" ); if( -1 == nIndex ) nIndex = rString.Find( "\n" ); if( -1 != nIndex ) rString = rString.Left( nIndex ); rString.TrimLeft(); rString.TrimRight(); if( rString.GetLength() > 0 ) { if( domain.m_strName.IsEmpty() ) // 新版块名称 domain.m_strName = rString; else domain.AddStock( rString ); } else { // 版块结束 if( !domain.m_strName.IsEmpty() ) AddDomain( domain ); domain.m_strName.Empty(); domain.RemoveAll(); } } if( !domain.m_strName.IsEmpty() ) Add( domain ); domain.m_strName.Empty(); domain.RemoveAll(); file.Close(); bOK = TRUE; } return bOK; }
const char * CStockInfo::GetStockShortName( ) { if( strlen(m_szShortname) <= 0 ) { CSPString sName = m_szName; CSPString sTemp = AfxMakeSpellCode( sName, 0x0 ); strncpy( m_szShortname, sTemp, min(sizeof(m_szShortname)-1,sTemp.GetLength()) ); } return m_szShortname; }
int CDomain::AddFxjDomain( LPCTSTR lpszFile ) { CSPFile file; DWORD dwMagic; if( !file.Open( lpszFile, CSPFile::modeRead ) || sizeof(dwMagic) != file.Read(&dwMagic,sizeof(dwMagic)) || dwMagic != 0xFF5100A5 ) return 0; int nCount = 0; struct fxj_block_t stock; while( sizeof(stock) == file.Read(&stock,sizeof(stock)) ) { if( 0 == stock.szCode[6] ) { CSPString sCode = stock.szCode; if( sCode.GetLength() == 4 ) sCode = "00" + sCode; if( sCode.GetLength() == 6 ) AddStock( sCode ); } } return GetSize(); }
BOOL CMathParser::IsFunc(CSPString S)//{ Checks to see if the parser is about to read a function } { WORD P, SLen; CSPString FuncName; BOOL bIsFunc; P = Position; FuncName = ""; while (P < FInput.GetLength())// && (FInput[P] in ['A'..'Z', 'a'..'z', '0'..'9', '_']) { if(!((FInput.GetAt(P) <= 'Z' && FInput.GetAt(P) >= 'A') ||(FInput.GetAt(P) <= 'z' && FInput.GetAt(P) >= 'a') ||(FInput.GetAt(P) <= '9' && FInput.GetAt(P) >= '0') ||(FInput.GetAt(P) == '_'))) break; //FInput.SetAt(P, FInput.GetAt(P)); FuncName = FuncName + FInput.GetAt(P);//[P]; P++;//Inc(P); }// end; { while } FuncName.MakeUpper(); if (FuncName == S )//Uppercase(FuncName) = S { SLen = S.GetLength(); CurrToken.FuncName = FInput.Mid(Position, SLen); CurrToken.FuncName.MakeUpper(); Position += SLen; //Inc(Position, SLen); bIsFunc = TRUE; } else bIsFunc = FALSE; return bIsFunc; }
TokenTypes CMathParser::NextToken()//{ Gets the next Token from the Input stream } { CSPString NumString;// : String[80]; WORD TLen, NumLen; //, FormLen, Place; // int Check ;//: Integer; char Ch;//, FirstChar; BOOL Decimal ; TokenTypes ResultNextToken; while ((Position < FInput.GetLength()) && (FInput.GetAt(Position) == ' ')) Position++; TokenLen = Position; if (Position >= FInput.GetLength()) { ResultNextToken = EOL; TokenLen = 0; return ResultNextToken; } FInput.MakeUpper(); Ch = FInput.GetAt(Position); if (Ch== '!') { ResultNextToken = ERR; TokenLen = 0; return ResultNextToken ; } if((Ch >= '0' && Ch <= '9') || Ch == '.')// if Ch in ['0'..'9', '.'] then { NumString = ""; TLen = Position; Decimal = FALSE; while ((TLen < FInput.GetLength()) && ((FInput.GetAt(TLen) >= '0' && FInput.GetAt(TLen) <= '9' ) || ((FInput.GetAt(TLen) == '.') && (!Decimal)))) { NumString = NumString + FInput.GetAt(TLen); if (Ch == '.')// then Decimal = TRUE; TLen++;//Inc(TLen); } if ((TLen == 2) && (Ch == '.'))// then { ResultNextToken = BAD; TokenLen = 0; return ResultNextToken ; } if ((TLen < FInput.GetLength()) && ((FInput.GetAt(TLen)) == 'E'))// then { NumString = NumString + 'E'; TLen++; if( FInput.GetAt(TLen) == '+' || FInput.GetAt(TLen) == '-')// in ['+', '-'] then { NumString.SetAt(TLen, FInput.GetAt(TLen));//= NumString + FInput[TLen]; TLen++; } NumLen = 1; while ((TLen < FInput.GetLength()) && (FInput.GetAt(TLen) >= '0' && FInput.GetAt(TLen) <= '9') && (NumLen <= MP_MaxExpLen)) { NumString = NumString + FInput.GetAt(TLen); NumLen++;//Inc(NumLen); TLen++;//Inc(TLen); } } if (NumString[0] == '.')// then NumString = '0' + NumString; CurrToken.Value = atof(NumString); //Val(NumString, CurrToken.Value, Check); /*//if (Check != 0 ) {// begin ErrorCode = MP_ErrMath; ErrorCode = ErrInvalidNum; Position += Pred(Check); //Inc(Position, Pred(Check)); }// end { if } else*/ {// begin ResultNextToken = NUM; Position += NumString.GetLength(); //Inc(Position, System.Length(NumString)); TokenLen = Position - TokenLen; }// end; { else } return ResultNextToken; }//end { if } else if ((Ch>='a' && Ch <= 'z') || (Ch>='A' && Ch <= 'Z'))//in Letters then {// begin if (IsFunc("ABS") || IsFunc("ATAN") || IsFunc("COS") || IsFunc("EXP") || IsFunc("LN") || IsFunc("ROUND") || IsFunc("SIN") || IsFunc("SQRT") || IsFunc("SQR") || IsFunc("TRUNC")|| IsFunc("NOT")||// then//EXPAND IsFunc("BOOL")|| IsFunc("SGN") ) { ResultNextToken = FUNC; TokenLen = Position - TokenLen; return ResultNextToken ; } if (IsFunc("MOD")) { ResultNextToken = MODU; TokenLen = Position - TokenLen; return ResultNextToken ; } if (IsVar(CurrToken.Value)) { ResultNextToken = NUM; TokenLen = Position - TokenLen; return ResultNextToken; } else { ResultNextToken = BAD; TokenLen = 0; return ResultNextToken ; } } else {// begin switch(Ch) { case '+' : ResultNextToken = PLUS; break; case '-' : ResultNextToken = MINUS; break; case '*' : ResultNextToken = TIMES; break; case '/' : ResultNextToken = DIVIDE; break; case '^' : ResultNextToken = EXPO; break; case '(' : ResultNextToken = OPAREN; break; case ')' : ResultNextToken = CPAREN; break; default: ResultNextToken = BAD; TokenLen = 0; return ResultNextToken ; }//end; { case } Position++; TokenLen = Position - TokenLen; return ResultNextToken ; }//end; { else if } }//end; { NextToken }