bool DictViewInstance::Save() { reg.SetRegKey(reg_key.c_str(), dict_view_uid_key, reg_key.c_str()); reg.SetRegKey(reg_key.c_str(), dict_view_name_key, name.c_str()); reg.SetFarString(reg_key.c_str(), dict_view_logic_key, logic.AsString()); return true; }
void DbgMsgV( char const * const Title, char const * const Fmt, va_list argList ) { FarString Tmp; Tmp.Format( "%s\n%s", Title, Tmp.FormatV( Fmt, argList ).c_str() ); FarMessage::Show( FMSG_WARNING|FMSG_ALLINONE|FMSG_MB_OK, NULL, (LPCSTR const*)Tmp.c_str(), 0, 0 ); }
bool CMailViewTpl::View( bool bEditor, bool bLock ) { FarFileName TempFile = FarFileName::MakeTemp( "mvt" ); CreateDirectory( TempFile.GetBuffer() ); TempFile.ReleaseBuffer(); TempFile.AddEndSlash(); TempFile.SetName( FarFileName::MakeTemp( "mvt" ) ); TempFile.SetExt( ".msg" ); if ( SaveToFile( TempFile ) == false ) return false; FarString Subj = m_origMsg->GetSubject(); if ( Subj.IsEmpty() ) Subj = "<none>"; SetFileAttributes( TempFile, GetFileAttributes( TempFile )|(bLock?FILE_ATTRIBUTE_READONLY:0) ); if ( bEditor ) Far::Editor( TempFile, Subj, 0, 0, -1, -1, 0, 1, EF_DELETEONCLOSE|EF_DISABLEHISTORY|EF_ENABLE_F6|EF_NONMODAL ); else Far::Viewer( TempFile, Subj, 0, 0, -1, -1, VF_DELETEONCLOSE|VF_DISABLEHISTORY|VF_ENABLE_F6|VF_NONMODAL ); return true; }
int FarXMLScanner::ParseEntity() { FarString entityName; while (1) { char c = NextChar(); if (c == ';') break; entityName += c; } if (entityName.IsEmpty()) { ReportError ("entity name"); return -1; } if (entityName [0] == '#') return DecodeEntity (entityName); if (entityName == "quot") return '\"'; if (entityName == "apos") return '\''; if (entityName == "gt") return '<'; if (entityName == "lt") return '>'; if (entityName == "amp") return '&'; ReportError ("known entity name"); return -1; }
static FarString itoa(int i, int radix) { FarString s; itoa(i, s.GetBuffer(32), radix); s.ReleaseBuffer(); return s; }
void CMailViewPlugins::Configure() { FarMenu mnu( MMailboxes ); FarIntArray Indices; for ( int i = 0; i < m_Libs.Count(); i ++ ) { FarString Name = CMailbox::getLongName( (HINSTANCE)m_Libs[ i ] ); if ( Name.IsEmpty() ) Name = CMailbox::getShortName( (HINSTANCE)m_Libs[ i ] ); if ( Name.IsEmpty() ) Name = FarFileName( m_Names[ i ] ).GetName(); mnu.AddItem( Name )->SetData( Indices.Add( i ) ); } FarMenu::PItem Item; while ( ( Item = mnu.Show() ) != NULL ) { int nIdx = Indices[ Item->GetData() ]; FarString Default = CMailbox::getFilesMasks( (HINSTANCE)m_Libs[ nIdx ] ); FarString Current = m_Masks[ nIdx ]; if ( Current.IsEmpty() ) Current = Default; if ( ConfigureFileMasksDlg( Item->GetText(), Default, Current ) ) { m_Masks.Insert( nIdx, Current ); m_Masks.Delete( nIdx + 1 ); } mnu.SelectItem( Item ); } }
FarString ProcessSubject( const FarString& subj ) { FarString result = subj; ProcessSubject( result.GetBuffer() ); result.ReleaseBuffer(); return result; }
FarString PasteFromClipboard() { OSVERSIONINFO WinVer; WinVer.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); GetVersionEx (&WinVer); HANDLE hClipData; if (!OpenClipboard(NULL)) return(NULL); int Unicode=FALSE; int Format=0; int ReadType=CF_OEMTEXT; while ((Format=EnumClipboardFormats(Format))!=0) { if (Format==CF_UNICODETEXT && WinVer.dwPlatformId==VER_PLATFORM_WIN32_NT) { Unicode=TRUE; break; } if (Format==CF_TEXT) { ReadType=CF_TEXT; break; } if (Format==CF_OEMTEXT) break; } FarString ClipText; if ((hClipData=GetClipboardData(Unicode ? CF_UNICODETEXT:ReadType))!=NULL) { int BufferSize; char *ClipAddr=(char *)GlobalLock(hClipData); if (Unicode) BufferSize=lstrlenW((LPCWSTR)ClipAddr)+1; else BufferSize=strlen(ClipAddr)+1; if (Unicode) { ClipText.SetLength (BufferSize); WideCharToMultiByte(CP_OEMCP,0,(LPCWSTR)ClipAddr,-1,ClipText.GetBuffer(),BufferSize,NULL,FALSE); } else { ClipText.SetText (ClipAddr, BufferSize); if (ReadType==CF_TEXT) ClipText = ClipText.ToOEM(); } GlobalUnlock(hClipData); } CloseClipboard(); return ClipText; }
void CMailViewTpl::processMessageId( int len, int fill, IWriteSink & f ) { FarString s = m_origMsg->GetId(); if ( s.Length() > 2 && s[ 0 ] == '<' ) { s = s.Mid( 1 ); int pos = s.IndexOf( '>' ); if ( pos != -1 ) s = s.Left( pos ); } writeFormatted( s, len, fill, f ); }
FarXMLNode *ParseFile (const char *FileName, IFarXMLErrorSink *errorSink) { FarFile f; if (!f.OpenForRead (FileName)) return NULL; int fileSize = f.GetSize(); FarString xmlBuf; xmlBuf.SetLength (fileSize); f.Read (xmlBuf.GetBuffer(), fileSize); return ParseBuffer (xmlBuf, errorSink); }
void CMailViewPlugins::SaveSettings( CIniConfig& ini ) { FarFileName Root = FarFileName( ini.GetIniFileName() ).GetPath(); for ( int i = 0; i < m_Names.Count(); i ++ ) { FarString Key = MakeKeyName( Root, m_Names[ i ] ); FarString Def = CMailbox::getFilesMasks( (HMODULE)m_Libs[ i ] ); LPCSTR Cur = m_Masks[ i ]; if ( Def.CompareNoCase( Cur ) == 0 || *Cur == '\0' ) ini.EraseKey( INI_GENERAL, Key ); else ini.WriteString( INI_GENERAL, Key, Cur ); } }
void CMessageTemplate::writeFormatted( const FarString& str, int len, int fill, IWriteSink & f ) { if ( len > 0 ) { f.write( str.c_str(), min( len, str.Length() ) ); if ( fill != 0 ) { for ( int i = str.Length(); i < len; i ++ ) f.write( (const char*)&fill, 1 ); } } else f.write( str.c_str(), str.Length() ); }
int FarXMLScanner::DecodeEntity (const FarString &entityName) { int startPos = 1; int radix = 10; if (entityName [1] == 'x') { radix = 16; startPos++; } int value = 0; for (int pos=startPos; pos<entityName.Length(); pos++) { value *= radix; char c = entityName [pos]; if (c >= '0' && c <= '9') value += c - '0'; else if (radix == 16 && c >= 'A' && c <= 'F') value += c - 'A' + 10; else if (radix == 16 && c >= 'a' && c <= 'f') value += c - 'a' + 10; else { if (radix == 16) ReportError ("hex digit"); else ReportError ("digit"); return -1; } } return value; }
int show_assert_message( const char * FileName, const int Line, const char * Expression, bool bShowWinError, bool bDumpStack ) { FarString FN = FileName; FarMessage Msg( FMSG_LEFTALIGN|FMSG_WARNING|(bShowWinError?FMSG_ERRORTYPE:0) ); Msg.AddLine( "Debug Assertion Failed!" ); Msg.AddFmt( "Plugin : %s", FarSF::PointToName( Far::GetModuleName() ) ); Msg.AddFmt( "File : %hs, Line %d", FarSF::TruncPathStr( FN.GetBuffer(), 40 ), Line ); Msg.AddFmt( "Expression: %s", Expression ); Msg.AddSeparator(); Msg.AddButton( "&Abort" ); Msg.AddButton( "&Debug" ); Msg.AddButton( "&Ignore" ); if ( bDumpStack ) Msg.AddButton( "Dump &Stack" ); return Msg.Show(); }
void CMailViewTpl::processText( int len, IWriteSink & f ) { // TODO: check File FarFileName bodyFile = FarFileName::MakeTemp( "mvb" ); File::mkdirs( bodyFile.GetPath() ); PMsgPart TextPart = m_origMsg->GetTextPart(); if ( TextPart ) { long Encoding = GetMsgEncoding( m_origMsg, TextPart, m_defaultEncoding ); if ( len > 20 ) { FarStringArray Src; StrPtr sp = { NULL, 0, (LPSTR)TextPart->GetContentData() }; LPCSTR Last = sp.Nxt + TextPart->GetContentSize(); while ( sp.Nxt ) { GetStrPtr( sp.Nxt, &sp, Last ); Src.Add( ToOEMString( FarString( sp.Str, sp.Len ), Encoding ) ); } FarStringArray * Dst = WordWrapLines( Src, len, true ); for ( int i = 0; i < Dst->Count(); i ++ ) { f.write( Dst->At( i ), strlen( Dst->At( i ) ) ); f.write( "\r\n", 2 ); } delete Dst; } else { FarString s = (LPCSTR)TextPart->GetContentData(); s.SetLength( TextPart->GetContentSize() ); s = ToOEMString( s, Encoding ); f.write( s.c_str(), s.Length() ); } File::deleteit( bodyFile ); } }
int DictViewFactory::FindDictViewId(const FarString& id, const FarString& name, void* client_context) { FindDictViewId_Ctx* ctx = (FindDictViewId_Ctx *)client_context; if (ctx->name == name) { ctx->uid = atoi(id.c_str()+prefix_length); return 0; } else return 1; }
FarString FarStringTokenizer::GetToken (int index) const { // it is not allowed to call GetToken() for a non-attached tokenizer far_assert (fText != NULL); far_assert (index >= 0); const char *curPos = GetTokenStart (fText); for (int i=0; i<index; i++) { curPos = GetTokenEnd (curPos); curPos = GetTokenStart (curPos); if (*curPos == '\0') return FarString(); } const char *tokenEnd = GetTokenEnd (curPos); FarString result (curPos, tokenEnd-curPos); if (fIgnoreWhitespace) result.TrimRight(); return result; }
FarString CPerson::GetMailboxName() const { if ( Addr.IsEmpty() && FTNAddr.Zone == 0 ) return Name; FarString result; if ( !Addr.IsEmpty() ) result += Addr; else { far_assert( FTNAddr.Zone != BAD_FTNADDR_FIELD ); far_assert( FTNAddr.Net != BAD_FTNADDR_FIELD ); far_assert( FTNAddr.Node != BAD_FTNADDR_FIELD ); far_assert( FTNAddr.Point != BAD_FTNADDR_FIELD ); // Dennis Trachuk <*****@*****.**> FarString tmp = Name; int pos; while ( (pos = tmp.IndexOf( '\x20' )) != -1 ) tmp[ pos ] = '.'; result += tmp; result += '@'; if ( FTNAddr.Point ) result += 'p' + IntToString( FTNAddr.Point ) + '.'; if ( FTNAddr.Node ) result += 'f' + IntToString( FTNAddr.Node ); result += ".n" + IntToString( FTNAddr.Net ); result += ".z" + IntToString( FTNAddr.Zone ); result += ".fidonet.org"; } if ( !Name.IsEmpty() ) result = Name + " <" + result + '>'; return result; }
bool FarXMLScanner::ParseAttribute (FarXMLNode *node) { FarString attrName = NextName(); if (attrName.IsEmpty()) return false; SkipWhitespace(); if (!NextExpectedChar ('=')) return false; SkipWhitespace(); char valueDelimiter = NextChar(); if (valueDelimiter != '\'' && valueDelimiter != '\"') { ReportError ("\" or \'"); return false; } FarString attrValue; while (1) { char c = NextChar(); if (c == valueDelimiter) break; else if (c == '&') { int entityValue = ParseEntity(); if (entityValue == -1) return false; attrValue += (char) entityValue; } else attrValue += c; } node->AddAttr (attrName, attrValue); return true; }
FarString CMailViewPlugins::MakeKeyName( LPCSTR Root, LPCSTR FileName ) { FarString Key = ExtractRelativePath( Root, FileName ); Key.Insert( 0, "Mailbox_" ); Key.SetLength( Key.Length() - 4 ); Key += "_Masks"; int nIdx = Key.IndexOf( '\\' ); while ( nIdx != -1 ) { Key[ nIdx ] = '_'; nIdx = Key.IndexOf( '\\' ); } return Key; }
FarString FarString::ToOEM() const { FarString result (fData->fText, Length()); CharToOemBuff (fData->fText, result.GetBuffer(), Length()); return result; }
void DictViewFactory::DeleteDictView(const FarString &id) { FarString n_id = id.Mid(prefix_length); if (!n_id.IsEmpty()) reg.DeleteRegKey("", n_id.c_str()); }
void CMailViewTpl::processHeaders( IWriteSink & f ) { PKludges Kludges = m_origMsg->GetKludges(); for ( int i = 0; i < Kludges->Count(); i ++ ) { FarString kludge = Kludges->At( i ); m_origMsg->DecodeKludge( kludge.GetBuffer() ); kludge.ReleaseBuffer(); int pos = 1; while ( ( pos = kludge.IndexOf( '\t', pos ) ) != -1 ) { FarString ss = kludge.Left( pos ); if (ss.Length() > 0 && ss[ss.Length() - 1] == ':') { pos ++; continue; } f.write( ss.c_str(), ss.Length() ); f.write( "\r\n", 2 ); kludge = kludge.Right( kludge.Length() - pos ); } f.write( kludge.c_str(), kludge.Length() ); if ( i < Kludges->Count() - 1 ) f.write( "\r\n", 2 ); } }
void CMailViewTpl::processKludge( LPCSTR kludge, IWriteSink & f ) { FarString s = m_origMsg->GetDecodedKludge( kludge ); f.write( s.c_str(), s.Length() ); }
FarXMLNode *FarXMLScanner::ParseChildNode() { SkipWhitespace(); int tagStartLine = fCurLine; int tagStartCol = GetCurColumn(); if (!NextExpectedChar ('<')) return NULL; FarString tagName = NextName(); if (tagName.IsEmpty()) return NULL; FarXMLNode *theNode = new FarXMLNode(); theNode->SetTag (tagName); theNode->SetStartPosition (tagStartLine, tagStartCol); while (1) { SkipWhitespace(); char c = PeekNextChar(); if (c == '/') { NextChar(); if (!NextExpectedChar ('>')) { delete theNode; return NULL; } break; } else if (c == '>') { NextChar(); SkipWhitespace(); while (1) { if (PeekNextChar() == '<' && PeekNextChar (1) == '/') break; FarXMLNode *nextChild = ParseChildNode(); if (!nextChild) { delete theNode; return NULL; } theNode->AddChild (nextChild); SkipWhitespace(); } NextChar(); // < NextChar(); // / FarString closeTagName = NextName(); if (closeTagName != tagName) { ReportError (tagName); delete theNode; return NULL; } SkipWhitespace(); if (!NextExpectedChar ('>')) { delete theNode; return NULL; } break; } else { if (!ParseAttribute (theNode)) { delete theNode; return NULL; } } } theNode->SetEndPosition (fCurLine, GetCurColumn()); SkipWhitespace(); return theNode; }
FarString FarString::ToANSI() const { FarString result (fData->fText, Length()); OemToCharBuff (fData->fText, result.GetBuffer(), Length()); return result; }
int DictViewInstance::NextUID() { int uid = reg.GetRegKey(reg_key.c_str(), dict_view_last_uid_key, 100000) + 1; reg.SetRegKey(reg_key.c_str(), dict_view_last_uid_key, uid); return uid; }
void SetText (FarString &String) { far_assert(fItem); strncpy (fItem->Data, String.c_str(), sizeof (fItem->Data)-1); }