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 ); }
CSPString AfxFaintlyChsToEnu( const char * szCh ) { static CHS_ENU_PAIR chs_enu_pairs[] = { { "中国", " China " }, { "指数", " Index " }, { "上证", " Shanghai " }, { "深证", " Shenzhen " }, { "基金", " Fund " }, { "国债", " Bond " }, { "债券", " Bond " }, { "转债", " Convertible Bond " }, { "银行", " Bank " }, { "其他", " Other " }, { "银行业", " Bank " }, { "", "" }, }; CSPString sResult = szCh; int i = 0; while( * chs_enu_pairs[i].chs ) { sResult.Replace( chs_enu_pairs[i].chs, chs_enu_pairs[i].enu ); i ++; } sResult.TrimLeft(); sResult.TrimRight(); return sResult; }
////////////////////////////////////////////////////////////////////////////////// // 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; }
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; }
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; }
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; }
void CMathParser::AddVar(MPExtended Value, LPCTSTR lpszVarName) { if( NULL == lpszVarName || strlen(lpszVarName) == 0 ) return; VARSTRU *pvar = new VARSTRU; CSPString VarName = lpszVarName; VarName.MakeUpper(); pvar->Value = Value; strncpy( pvar->VarName, VarName.GetBuffer(MP_MaxVarNameLen-1), MP_MaxVarNameLen-1 ); m_VarMap.SetAt( VarName, pvar ); }
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; }
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; }
BOOL CMathParser::GetVar( LPCTSTR lpszVarName, MPExtended &Value) { if( m_VarMap.IsEmpty() || NULL == lpszVarName || strlen(lpszVarName) == 0 ) return FALSE; CSPString VarName = lpszVarName; VarName.MakeUpper(); void * pvar = NULL; if( m_VarMap.Lookup( VarName, pvar ) ) { Value = ((VARSTRU *)pvar)->Value; return TRUE; } return FALSE; }
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; }
void CSListView::OnDblclkItem( int nStockIndex ) { CStockContainer & container = AfxGetSListStockContainer(); int nType; CSPString strDomain; DWORD dwDate = -1; if( nStockIndex >= 0 ) { container.GetCurrentType( &nType, &strDomain, &dwDate ); if( ( nType == CStockContainer::typeDomain && strDomain.IsEmpty() ) || ( nType == CStockContainer::typeGroup && strDomain.IsEmpty() ) ) { CStockInfo & info = container.GetStockInfoByID( nStockIndex ); AfxShowSlist( nType, CString(info.GetStockName()), dwDate ); } else AfxShowStockGraph( nStockIndex, TRUE ); } }
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; }
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(); }
int CStkUIApp::OpenLastOpenedStrategy( ) { CSPStringArray & astrStrategyToOpen = AfxGetProfile().GetLastOpenedStrategy( ); CSPString strLastActive = AfxGetProfile().GetLastActiveStrategy( ); if( 0 != access(strLastActive,0) ) strLastActive.Empty(); int nCount = 0; for( int i=0; i<astrStrategyToOpen.GetSize(); i++ ) { if( 0 != access(astrStrategyToOpen.ElementAt(i),0) ) continue; if( NULL != OpenStrategyFile(astrStrategyToOpen.ElementAt(i)) ) { nCount ++; if( strLastActive.IsEmpty() ) strLastActive = astrStrategyToOpen.ElementAt(i); } } if( !strLastActive.IsEmpty() ) OpenStrategyFile(strLastActive); return nCount; }
////////////////////////////////////////////////////////////////////////////////// // 快捷键 // 给定快捷键唯一编号,返回快捷键及其中文名称 CSPString AfxGetAccelerator( UINT nAcce, int nCharLeft ) { static CSPString acce_names[ACCE_MAX+1]; SP_ASSERT( ACCE_MAX >= 0 ); if( acce_names[0].GetLength() <= 0 ) { // acce_names acce_names[0] = "ACCENames"; #ifdef CLKLAN_ENGLISH_US // 快捷键 acce_names[ACCE_01] = "01 Hot Key F1"; acce_names[ACCE_02] = "02 Hot Key F2"; acce_names[ACCE_03] = "03 Hot Key F3"; acce_names[ACCE_04] = "04 Hot Key F4"; acce_names[ACCE_05] = "05 Hot Key F5"; acce_names[ACCE_06] = "06 Hot Key F6"; acce_names[ACCE_07] = "07 Hot Key F7"; acce_names[ACCE_08] = "08 Hot Key F8"; acce_names[ACCE_09] = "09 Hot Key F9"; acce_names[ACCE_10] = "10 Hot Key F10"; acce_names[ACCE_1] = "1 Shanghai A Shares List"; acce_names[ACCE_2] = "2 Shanghai B Shares List"; acce_names[ACCE_3] = "3 Shenzhen A Shares List"; acce_names[ACCE_4] = "4 Shenzhen B Shares List"; acce_names[ACCE_5] = "5 Shanghai Bond List"; acce_names[ACCE_6] = "6 Shenzhen Bond List"; acce_names[ACCE_61] = "61 Shanghai A Shares Change"; acce_names[ACCE_62] = "62 Shanghai B Shares Change"; acce_names[ACCE_63] = "63 Shenzhen A Shares Change"; acce_names[ACCE_64] = "64 Shenzhen B Shares Change"; acce_names[ACCE_65] = "65 Shanghai Bond Change"; acce_names[ACCE_66] = "66 Shenzhen Bond Change"; acce_names[ACCE_71] = "71 Shanghai Info."; acce_names[ACCE_72] = "72 Shenzhen Info."; acce_names[ACCE_73] = "73 Stockjobber Info."; acce_names[ACCE_81] = "81 Shanghai A Shares Sort"; acce_names[ACCE_82] = "82 Shanghai B Shares Sort"; acce_names[ACCE_83] = "83 Shenzhen A Shares Sort"; acce_names[ACCE_84] = "84 Shenzhen B Shares Sort"; acce_names[ACCE_85] = "85 Shanghai Bond Sort"; acce_names[ACCE_86] = "86 Shenzhen Bond Sort"; acce_names[ACCE_LBDK] = "LBDK Volume Ratio"; acce_names[ACCE_MMLD] = "MMLD Consign Ratio"; #else // 快捷键 acce_names[ACCE_01] = "01 热键F1"; acce_names[ACCE_02] = "02 热键F2"; acce_names[ACCE_03] = "03 热键F3"; acce_names[ACCE_04] = "04 热键F4"; acce_names[ACCE_05] = "05 热键F5"; acce_names[ACCE_06] = "06 热键F6"; acce_names[ACCE_07] = "07 热键F7"; acce_names[ACCE_08] = "08 热键F8"; acce_names[ACCE_09] = "09 热键F9"; acce_names[ACCE_10] = "10 热键F10"; acce_names[ACCE_1] = "1 上A报价"; acce_names[ACCE_2] = "2 上B报价"; acce_names[ACCE_3] = "3 深A报价"; acce_names[ACCE_4] = "4 深B报价"; acce_names[ACCE_5] = "5 上债报价"; acce_names[ACCE_6] = "6 深债报价"; acce_names[ACCE_61] = "61 上A涨跌"; acce_names[ACCE_62] = "62 上B涨跌"; acce_names[ACCE_63] = "63 深A涨跌"; acce_names[ACCE_64] = "64 深B涨跌"; acce_names[ACCE_65] = "65 上债涨跌"; acce_names[ACCE_66] = "66 深债涨跌"; acce_names[ACCE_71] = "71 上证信息"; acce_names[ACCE_72] = "72 深证信息"; acce_names[ACCE_73] = "73 券商信息"; acce_names[ACCE_81] = "81 上A综合"; acce_names[ACCE_82] = "82 上B综合"; acce_names[ACCE_83] = "83 深A综合"; acce_names[ACCE_84] = "84 深B综合"; acce_names[ACCE_85] = "85 上债综合"; acce_names[ACCE_86] = "86 深债综合"; acce_names[ACCE_LBDK] = "LBDK 量比(多空)"; acce_names[ACCE_MMLD] = "MMLD 买卖力道(涨跌率)"; #endif } if( nAcce >= ACCE_MIN && nAcce <= ACCE_MAX ) { if( 8 == nCharLeft ) return acce_names[nAcce]; CSPString strResult = acce_names[nAcce]; int nIndex = strResult.Find( ' ' ); if( -1 != nIndex ) strResult = strResult.Left(nIndex) + strResult.Mid(8); return strResult; } return ""; }
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 }