void DictViewInstance::RemoveDict(DictParams *instance)
{
  int index = logic.GetConditionNumber(instance);
  far_assert(index >= 0);
  far_assert(index < logic.GetConditionsCount());
  RemoveDict(index);
}
示例#2
0
FarString FarString::Mid (int nFirst, int nCount) const
{
  if (nFirst < 0)
    nFirst = 0;

  if (nCount < 0)
    nCount = 0;

  if (nFirst + nCount > fData->fLength)
  {
    nCount = fData->fLength - nFirst;
  }
  if (nFirst > fData->fLength)
  {
    nCount = 0;
  }

  far_assert (nFirst >= 0 );
  far_assert (nFirst + nCount <= fData->fLength);

  if (nFirst == 0 && nFirst + nCount == fData->fLength)
    return *this;

  return FarString (fData->fText + nFirst, nCount);
}
DictViewInstance::WordList *DictViewInstance::WordSuggestion(FarStringW &word)
{
  WordList *wl = new WordList();
  _current_color = -1;
  _current_word = word;
  DecisionTable::action_inst_t act_inst = logic.Execute();
  Action *action = static_cast<Action *>(act_inst->client_context);
  far_assert(action);
  FarString suggestion_order = action->suggestions;
  if (suggestion_order.IsEmpty()) 
    for (int i = 0; i<DictCount(); i++)
      suggestion_order += GetDict(i)->dict + ';';
  if (suggestion_order.IsEmpty())
    return wl;
  FarStringTokenizer dicts(suggestion_order, ';');
  for (int i = 0; i < DictCount() && dicts.HasNext(); i++) 
  {
    const FarString &dict(dicts.NextToken());
    for (int j = 0; j < DictCount(); j++)
      if (GetDict(j)->dict == dict) {
        far_assert(spell_factory);
        SpellInstance *dict_inst = spell_factory->GetDictInstance(dict);
        far_assert(dict_inst);
        wl->Add(dict_inst->Suggest(word));
      }
  }
  return wl;
}
示例#4
0
void BaseFarArray::BaseRemove (int index)
{
	far_assert(index >= 0);
	far_assert(index < fCount);
	memmove(fItems + index * fItemSize, 
	        fItems + (index+1) * fItemSize, 
	        (fCount - index - 1) * fItemSize);
	fCount--;
}
void DictViewInstance::DictParams::GetWordChars(FarStringW &wc)
{
  if (word_chars.IsEmpty()) 
  {
    far_assert(spell_factory);
    SpellInstance *dict_inst = spell_factory->GetDictInstance(dict);
    far_assert(dict_inst);
    wc = dict_inst->GetWordChars();
  } else 
    wc = word_chars;
}
DictViewInstance::DictParams *DictViewInstance::GetDict(int index)
{
  DecisionTable::condition_inst_t cond_inst;

  far_assert(index >= 0);
  far_assert(index < logic.GetConditionsCount());
  cond_inst = logic.GetConditionInst(index);
  far_assert(cond_inst);
  DictViewInstance::DictParams *params = 
    static_cast<DictParams *>(cond_inst->client_context);
  far_assert(params);
  return params;
}
DictViewInstance::Action *DictViewInstance::GetRuleAction(int index)
{
  far_assert(index >= 0);
  far_assert(index < logic.GetRulesCount());

  DecisionTable::action_inst_t act_inst = logic.GetActionInst(index);
  far_assert(act_inst);

  Action *action = static_cast<Action *>(act_inst->client_context);
  far_assert(action);

  return action;
}
bool DictViewInstance::DictParams::Execute(const FarStringW &in_word)
{
  far_assert(spell_factory);
  SpellInstance *dict_inst = spell_factory->GetDictInstance(dict);
  far_assert(dict_inst);
  if (transliteration_enabled) {
    FarStringW word = in_word;
    const bool transliterated = Transliterate(word);
    if (transliterated && transliteration_is_error)
      return false;
    return dict_inst->Check(word);
  } else 
    return dict_inst->Check(in_word);
}
示例#9
0
int FarString::Insert (int nIndex, const char * Str, size_t nLength)
{
  far_assert (nIndex >= 0);

  if (nLength > 0)
  {
    int newLength = fData->fLength;
    UniqueString();

    if (nIndex > newLength)
      nIndex = newLength;

    newLength += nLength;

    fData->SetCapacity (newLength);

    memmove (fData->fText + nIndex + nLength,
      fData->fText + nIndex,
      newLength - nIndex - nLength + 1 );

    memmove (fData->fText + nIndex, Str, nLength);

    fData->fLength = newLength;
  }

  return nLength;
}
示例#10
0
// BaseAdd() можно (или нужно) заменить на:
// int BaseFarArray::BaseAdd (const void *item)
// {
//	BaseInsert( fCount, item );
// }
int BaseFarArray::BaseInsert( int nIndex, const void * item )
{
	far_assert( nIndex >=0 && nIndex <= fCount );

	if ( fCount + 1 > fAllocCount )
	{
		fAllocCount += fResizeDelta;
		fItems = (char*)realloc( fItems, fAllocCount * fItemSize );
		memset( fItems + ( fCount + 1 ) * fItemSize, 0, ( fAllocCount - fCount - 1 ) * fItemSize );
	}

	if ( nIndex == fCount )
	{
		memcpy( fItems + fCount * fItemSize, item, fItemSize );
	}
	else
	{
		memmove( fItems + ( nIndex + 1 ) * fItemSize, fItems + nIndex * fItemSize,
			( fCount - nIndex ) * fItemSize );

		memcpy( fItems + nIndex * fItemSize, item, fItemSize );
	}

	return fCount++;
}
bool CFarInetMessage::DecodeKludge( LPSTR Data )
{
  far_assert( Data != NULL );
  if ( *Data != '\0')
    strcpy( Data, UnMimeHeader( Data, GetEncoding() ) );
  return true;
}
DictViewFactory::DictViewFactory(const FarString &init_reg_root,
 SpellFactory *init_spell_factory)
: reg(init_reg_root+"\\DictView\\")
{
  far_assert(init_spell_factory);
  spell_factory = init_spell_factory;
}
示例#13
0
void WINAPI FreeFindData( HANDLE hPlugin, PluginPanelItem * pPanelItem, int ItemsNumber )
{
  far_assert( Plugin != NULL );
  if ( pPanelItem )
  {
    FarPluginPanelItems items( pPanelItem, ItemsNumber, true );
    Plugin->FreeFindData( hPlugin, &items );
  }
}
示例#14
0
CMailViewTpl::CMailViewTpl( const FarFileName& TplFileName, PMessage Msg, long defaultEncoding )
  : CMessageTemplate()
  , m_origMsg( Msg )
  , m_origDel( false )
  , m_fileName( TplFileName )
  , m_defaultEncoding( defaultEncoding )
{
  far_assert( m_origMsg );
}
示例#15
0
FarString FarStringTokenizer::NextToken()
{
  // it is not allowed to call NextToken() for a non-attached tokenizer
  far_assert (fText != NULL);
  const char *tokenEnd = GetTokenEnd (fCurPos);
  FarString token (fCurPos, tokenEnd-fCurPos);
  fCurPos = GetTokenStart (tokenEnd);
  fCurIndex++;
  return token;
}
示例#16
0
int WINAPI SetFindList( HANDLE hPlugin, PluginPanelItem * PanelItems, int ItemsNumber )
{
  far_assert( Plugin != NULL );

  FarPluginPanelItems Items( PanelItems, ItemsNumber );

  bool Result = Plugin->SetFindList( hPlugin, &Items );

  return Result ? TRUE : FALSE;
}
示例#17
0
// CP-1251
// для сортированного массива эту операцию можно значительно ускорить,
// но придется вводить дополнительный член класса (fSorted).
// плюс если fSorted == true, то Insert делать сразу в нужную позицию.
int FarStringArray::IndexOf( const char * item )
{
	far_assert( item != NULL );
	int len = strlen( item );
	for ( int i = 0; i < fCount; i++ )
	{
		if ( CompareString( LOCALE_USER_DEFAULT, 0, At( i ), -1, item, len ) == CSTR_EQUAL )
			return i;
	}
	return -1;
}
示例#18
0
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;
}
int DictViewInstance::WordColor(FarStringW &word, int default_color)
{
  _current_color = -1;
  _current_word = word;
  DecisionTable::action_inst_t act = logic.Execute();
  if (act) {
    far_assert(_current_color!=-1);
    return _current_color;
  } else
    return default_color;
}
示例#20
0
int WINAPI GetVirtualFindData( HANDLE hPlugin, PluginPanelItem ** ppPanelItems, PINT pItemsNumber, LPCSTR Path )
{
  far_assert( Plugin != NULL );
  FarPluginPanelItems Items( 16 );

  bool Result = Plugin->GetVirtualFindData( hPlugin, &Items, Path );

  *pItemsNumber = Items.Count();
  *ppPanelItems = Items.Detach();

  return Result ? TRUE : FALSE;
}
示例#21
0
FarString& FarString::Format( const char * Fmt, ... )
{
  far_assert( Fmt != NULL );

  va_list argList;
  va_start( argList, Fmt );

  FormatV( Fmt, argList );

  va_end( argList );

  return * this;
}
FarStringW& DictViewInstance::WordList::operator[](int index)
{
  far_assert(word_lists.Count()>0);
  far_assert(index>=0);
  far_assert(index<words_count);
  unsigned i = 0; // сквозной номер
  unsigned j = 0; // номер в списке слов SpellInstance::WordList wl 
  unsigned k = 0; // номер списка слов в word_lists.
  SpellInstance::WordList *wl = word_lists[k];
  while (i!=index) {
    i++;
    j++;
    if (j == wl->Count()) {
      j = 0;
      k++;
      far_assert(k<word_lists.Count());
      wl = word_lists[k];
    }
  }
  far_assert(j<wl->Count());
  return (*wl)[j];
}
示例#23
0
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;
}
DictViewInstance::DictViewInstance(FarRegistry &init_reg, const FarString &init_reg_key,
  SpellFactory *init_spell_factory )
: reg(init_reg)
, reg_key(init_reg_key)
{
  far_assert(init_spell_factory);
  spell_factory = init_spell_factory;
  name = reg.GetRegStr(reg_key.c_str(), dict_view_name_key, 
   FarString(reg_key + ": <noname>").c_str() );
  logic.SetContext(this);
  FarString dt(reg.GetFarString(reg_key.c_str(), dict_view_logic_key, 
    FarString("")));
  if (!dt.IsEmpty())
    logic.FromString(dt);
}
示例#25
0
void BaseFarArray::Delete( int nIndex, int nCount )
{
	far_assert( nIndex >= 0 && nIndex < fCount );

	if ( nIndex + nCount > fCount )
		nCount = fCount - nIndex;

	if ( nCount <= 0 )
		return;

	char * Dst = fItems + nIndex * fItemSize;
	char * Src = Dst + nCount * fItemSize;

	fCount -= nCount;

	memmove( Dst, Src, ( fCount - nIndex ) * fItemSize );
}
示例#26
0
int FarString::Delete (int nIndex, int nCount /* = 1 */)
{
  far_assert (nIndex >= 0);

  int nNewLength = fData->fLength;
  if (nIndex + nCount > nNewLength)
    nCount = nNewLength - nIndex;

  if (nCount > 0 && nIndex < nNewLength)
  {
    UniqueString();

    int nBytesToCopy = nNewLength - (nIndex + nCount) + 1;
    memmove (fData->fText + nIndex, fData->fText + nIndex + nCount, nBytesToCopy);

    fData->fLength = nNewLength - nCount;
  }

  return fData->fLength;
}
示例#27
0
int WINAPI DeleteFiles( HANDLE hPlugin, PluginPanelItem * PanelItem, int ItemsNumber, int OpMode )
{
  far_assert( Plugin != NULL );
  FarPluginPanelItems items( PanelItem, ItemsNumber );
  return Plugin->DeleteFiles( hPlugin, &items, OpMode );
}
void DictViewInstance::WordList::Add(SpellInstance::WordList *wl)
{
  far_assert(wl);
  word_lists.Add(wl);
  words_count += wl->Count();
}
示例#29
0
int WINAPI Compare( HANDLE hPlugin, const PluginPanelItem * Item1, const PluginPanelItem * Item2, UINT Mode )
{
  far_assert( Plugin != NULL );
  return Plugin->Compare( hPlugin, Item1, Item2, Mode );
}
void DictViewInstance::RemoveDict(int index)
{
  far_assert(index >= 0);
  far_assert(index < logic.GetConditionsCount());
  logic.DeleteCondition(index);
}