Beispiel #1
0
int SortListByTitle(const anime::Item& item1, const anime::Item& item2) {
  if (Settings.GetBool(taiga::kApp_List_DisplayEnglishTitles)) {
    return CompareStrings(item1.GetEnglishTitle(true),
                          item2.GetEnglishTitle(true));
  } else {
    return CompareStrings(item1.GetTitle(), item2.GetTitle());
  }
}
Beispiel #2
0
bool CatalogItemsComparator::operator()(int i, int j) const
{
    const CatalogItem& a = Item(i);
    const CatalogItem& b = Item(j);

    if ( m_order.untransFirst )
    {
        if ( a.GetValidity() == CatalogItem::Val_Invalid && b.GetValidity() != CatalogItem::Val_Invalid )
            return true;
        if ( a.GetValidity() != CatalogItem::Val_Invalid && b.GetValidity() == CatalogItem::Val_Invalid )
            return false;

        if ( !a.IsTranslated() && b.IsTranslated() )
            return true;
        if ( a.IsTranslated() && !b.IsTranslated() )
            return false;

        if ( a.IsFuzzy() && !b.IsFuzzy() )
            return true;
        if ( !a.IsFuzzy() && b.IsFuzzy() )
            return false;
    }

    switch ( m_order.by )
    {
        case SortOrder::By_FileOrder:
        {
            return i < j;
        }

        case SortOrder::By_Source:
        {
            int r = CompareStrings(a.GetString(), b.GetString());
            if ( r != 0 )
                return r < 0;
            break;
        }

        case SortOrder::By_Translation:
        {
            int r = CompareStrings(a.GetTranslation(), b.GetTranslation());
            if ( r != 0 )
                return r < 0;
            break;
        }
    }

    // As last resort, sort by position in file. Note that this means that
    // no two items are considered equal w.r.t. sort order; this ensures stable
    // ordering.
    return i < j;
}
void XGPopMenuView::MoveTo(short len, char *ptr)
{
	char buffer[256];
	char cptr[256];
	short i,num;
	short cur = -1;
	
	if (len == 0) return;		// Huh?
	
	/*
	 *	Find the smallest bigger than this ptr
	 */
	
	num = fList->GetNumStrings();
	for (i = 0; i < num; i++) {
		fList->GetString(i,buffer);
		if (-1 < CompareStrings(len,ptr,buffer)) {
			if (cur == -1) {
				cur = i;
				strcpy(cptr,buffer);
			} else if (-1 < CompareStrings(strlen(buffer),buffer,cptr)) {
				cur = i;
				strcpy(cptr,buffer);
			}
		}
	}
	
	if (cur == -1) {
		/*
		 *	None were bigger, so find the last in alphabetical order
		 */
		
		for (i = 0; i < num; i++) {
			fList->GetString(i,buffer);
			if (cur == -1) {
				cur = i;
				strcpy(cptr,buffer);
			} else if (-1 < CompareStrings(strlen(cptr),cptr,buffer)) {
				cur = i;
				strcpy(ptr,buffer);
			}
		}
	}
	
	/*
	 *	Now set this as the selection
	 */
	
	fDefault = cur;
	fScrollFlag = false;
	SetSelect(fDefault);
}
Beispiel #4
0
/* Text suchen und selektieten Punkt übergeben  */
BOOL SearchText (char* pszKeyStr, POINT* pPoint) {

	register int i;
	int iEnd;
	char szLine [iMaxLineLength];
	char *pszAktPos;
	int iStart = HIWORD (Edit_GetSel (hEditWnd));
	int iLineNr = Edit_LineFromChar (hEditWnd, iStart);
	int iMaxLineNr = Edit_GetLineCount (hEditWnd);
	int iLineLength = Edit_LineLength (hEditWnd, iStart);

/*  1. (akt.) Zeile untersuchen */
	if (iLineLength) {
		for (i = 0; i < sizeof (szLine); i++)
			szLine [i] = '\0';
		GetFirstLine (szLine);
		if (pszAktPos = CompareStrings (szLine, pszKeyStr)) {
			iStart += pszAktPos - szLine;
			iEnd = iStart + strlen (pszKeyStr);
			pPoint->x = iStart; pPoint->y = iEnd;
			return (TRUE);
		}
		else
		   iStart += strlen (szLine) + 2; // einschl. 0D0A
	}
	else
		iStart += 2;

/* alle restlichen Zeilen untersuchen */
	for (++iLineNr; iLineNr < iMaxLineNr; iLineNr++) {
		if (iLineLength = Edit_LineLength (hEditWnd, iStart)) {
			for (i = 0; i < sizeof (szLine); i++)
				szLine [i] = '\0';
			Edit_GetLine (hEditWnd, iLineNr, szLine, sizeof (szLine) -1);
			if (pszAktPos = CompareStrings (szLine, pszKeyStr)) {
				iStart += pszAktPos - szLine;
				iEnd = iStart + strlen (pszKeyStr);
				pPoint->x = iStart; pPoint->y = iEnd;
				return (TRUE);
			}
			else
				iStart += iLineLength + 2;
		}
		else
			iStart += 2;
	}

/* Punkt auf ungültigen Wert setzen */
	pPoint->x = -1; pPoint->y = -1;
	return (FALSE);
}
Beispiel #5
0
bool TStringList::Find(const UnicodeString & S, intptr_t & Index) const
{
  bool Result = false;
  intptr_t L = 0;
  intptr_t H = GetCount() - 1;
  while ((H != NPOS) && (L <= H))
  {
    intptr_t I = (L + H) >> 1;
    intptr_t C = CompareStrings(FStrings[I], S);
    if (C < 0)
    {
      L = I + 1;
    }
    else
    {
      H = I - 1;
      if (C == 0)
      {
        Result = true;
        if (FDuplicates != dupAccept)
        {
          L = I;
        }
      }
    }
  }
  Index = L;
  return Result;
}
Beispiel #6
0
//return given sections index in array
int CIniEx::LookupSection(CString *Section)
{
	int nRet;
	for (int i=0;i<m_Sections.GetSize();i++)
	{
		nRet=CompareStrings(&m_Sections.GetAt(i),Section);
		if (nRet==0) return i;
	}
	return -1;
}
Beispiel #7
0
intptr_t TStrings::IndexOf(const UnicodeString & S) const
{
  for (intptr_t Result = 0; Result < GetCount(); Result++)
  {
    if (CompareStrings(GetString(Result), S) == 0)
    {
      return Result;
    }
  }
  return NPOS;
}
Beispiel #8
0
//returns index of key for given section
//if no result returns -1
int CIniEx::LookupKey(int nSectionIndex,CString *Key)
{
	ASSERT(nSectionIndex<=m_SectionNo);
	int nRet;
	for (INT_PTR i=m_Keys[nSectionIndex]->GetUpperBound();i>=0;i--)
	{
		nRet=CompareStrings(&m_Keys[nSectionIndex]->GetAt(i),Key);
		if (nRet==0) 
			return (int)i;
	}
	return -1;
}
Beispiel #9
0
TEST(ParserTest, ShouldReadString)
{
	Parser parser;
	TList<char>* inputString = UnitTestsHelper::CreateInputString("defhkljahkgnfasdjnckagruibvdnmcvaslkdkwabgjsavbaslkjfnsadlkfvhadbvhnzbcalskufgjasbdjlncsxn", 90);
	char* fileName = "Tests/in.txt";
	WriteDataToFile(fileName, inputString);

	FILE* inputFile = fopen(fileName, "r");
	TList<char>* readedString = parser.ReadString(inputFile);
	fclose(inputFile);

	CompareStrings(inputString, readedString);
}
Beispiel #10
0
intptr_t TStrings::IndexOfName(const UnicodeString & Name) const
{
  for (intptr_t Index = 0; Index < GetCount(); ++Index)
  {
    UnicodeString S = GetString(Index);
    intptr_t P = ::AnsiPos(S, L'=');
    if ((P > 0) && (CompareStrings(S.SubStr(1, P - 1), Name) == 0))
    {
      return Index;
    }
  }
  return NPOS;
}
Beispiel #11
0
bool MSufSort::VerifySort()
{
  //printf("\n\nVerifying sort\n\n");
	bool error = false;
	int progressMax = m_sourceLength;
	int progressValue = 0;
	int progressUpdateStep = progressMax  / 100;
	int nextProgressUpdate = 1;

	unsigned int * suffixArray = new unsigned int[m_sourceLength];
	for (unsigned int i = 0; ((!error) && (i < m_sourceLength)); i++)
	{

		if (!(m_ISA[i] & 0x80000000))
			error = true;
		unsigned int n = (m_ISA[i] & 0x3fffffff) - 1;
		suffixArray[n] = i;
	}


	// all ok so far.
	// now compare the suffixes in lexicographically sorted order to confirm the sort was good.
	for (unsigned int suffixIndex = 0; ((!error) && (suffixIndex < (m_sourceLength - 1))); suffixIndex++)
	{
		if (++progressValue == nextProgressUpdate)
		{
			nextProgressUpdate += progressUpdateStep;
			//printf("Verify sort: %.2f%% complete%c", ((double)progressValue / progressMax) * 100, 13);
		}

		SYMBOL_TYPE * ptrA = &m_source[suffixArray[suffixIndex]];
		SYMBOL_TYPE * ptrB = &m_source[suffixArray[suffixIndex + 1]];
		int maxLen = (ptrA < ptrB) ? m_sourceLength - (ptrB - m_source) : m_sourceLength - (ptrA - m_source);
		int c = CompareStrings(ptrA, ptrB, maxLen);
		if (c > 0)
			error = true;
		else
			if ((c == 0) && (ptrB > ptrA))
				error = true;
	}

	//printf("                               %c", 13);
	delete [] suffixArray;
	return !error;
}
Beispiel #12
0
dword ELF::Private::GetSymbolAddr(dword filebase, char* symname)
{
	ELF::Private::Elf32_Ehdr* header = (ELF::Private::Elf32_Ehdr*)filebase;
	ELF::Private::Elf32_Shdr* shdrs = (ELF::Private::Elf32_Shdr*)(filebase + header->e_shoff);

	//look for symbol and string table
	ELF::Private::Elf32_Shdr* symtab_sh = 0;
	ELF::Private::Elf32_Sym* symtab = 0;
	char* strtab = 0;
	for (dword i = 0; i < header->e_shnum; i++)
	{
		if (shdrs[i].sh_type == 2)
		{
			symtab_sh = (ELF::Private::Elf32_Shdr*)&shdrs[i];
			symtab = (ELF::Private::Elf32_Sym*)(filebase + symtab_sh->sh_offset);
			strtab = (char*)(filebase + shdrs[symtab_sh->sh_link].sh_offset);
			break;
		}
	}

	if (!symtab_sh || !symtab || !strtab)
	{
		Video::Print("\nOne of symbol table section header, symbol table or string table can not be found\n");
		Keyboard::WaitForKeyDown();
		return 0;
	}

	//go through symbol table to find symbol
	for (dword i = 0; i < (symtab_sh->sh_size / sizeof(ELF::Private::Elf32_Sym)); i++)
	{
		if (symtab[i].st_name == 0) //bad name
			continue;

		//grab name
		char* ext_symname = (char*)(strtab + symtab[i].st_name);
		if (CompareStrings(symname, ext_symname) && symtab[i].st_value!= 0)
		{
			//Video::Print(ext_symname);Keyboard::WaitForKeyDown();
			return symtab[i].st_value;
		}
	}

	return 0;
}
Beispiel #13
0
//if Section Name="" -> looking up key for witout section
CString CIniEx::GetValue(CString Section,CString Key,CString DefaultValue/*=""*/)
{
	int nIndex=LookupSection(&Section);
	if (nIndex==-1) return DefaultValue;
	int nRet;
	CString retStr;
	for (INT_PTR i=m_Keys[nIndex]->GetUpperBound();i>=0;i--)
	{
		nRet=CompareStrings(&(m_Keys[nIndex]->GetAt(i)),&Key);
		if (nRet==0)
		{
			retStr=m_Values[nIndex]->GetAt(i);
			/*int nPlace=retStr.ReverseFind(';');
			if (nPlace!=-1) 
				retStr.Delete(nPlace,retStr.GetLength()-nPlace);*/
			return retStr;
		}
	}
	return DefaultValue;
}
Beispiel #14
0
stPosicion PAT_Informacion(char *c)
{
	char cVelocidad[10]={0};
	static int iElementos=0;
	stPosicion p = MistPosicion;
	
	//obtiene el indice de la velocidad
	iElementos = ListNumItems(miLista);
	
	for (int i=0;i<iElementos;i++)
	{
		ListGetItem(miLista, &p, i+1);
		
		if (CompareStrings(p.cDescripcion, 0, c, 0, 0)==0)
		{
			i=iElementos;
		}
	}
	return p;
}
Beispiel #15
0
CompareResult SemanticVersion::Compare(const SemanticVersion& version) const {
  if (major != version.major)
    return major < version.major ? kLessThan : kGreaterThan;
  if (minor != version.minor)
    return minor < version.minor ? kLessThan : kGreaterThan;
  if (patch != version.patch)
    return patch < version.patch ? kLessThan : kGreaterThan;

  if (prerelease_identifiers != version.prerelease_identifiers) {
    if (prerelease_identifiers.empty() &&
        !version.prerelease_identifiers.empty())
      return kGreaterThan;
    if (!prerelease_identifiers.empty() &&
        version.prerelease_identifiers.empty())
      return kLessThan;

    std::vector<string_t> identifiers_, identifiers;
    Split(prerelease_identifiers, L".", identifiers_);
    Split(version.prerelease_identifiers, L".", identifiers);

    size_t min_size = min(identifiers_.size(), identifiers.size());
    for (size_t i = 0; i < min_size; ++i) {
      if (IsNumeric(identifiers_.at(i)) && IsNumeric(identifiers.at(i))) {
        int lhs = ToInt(identifiers_.at(i));
        int rhs = ToInt(identifiers.at(i));
        if (lhs != rhs)
          return lhs < rhs ? kLessThan : kGreaterThan;
      } else {
        int result = CompareStrings(identifiers_.at(i), identifiers.at(i));
        if (result != 0)
          return result < 0 ? kLessThan : kGreaterThan;
      }
    }

    if (identifiers_.size() != identifiers.size())
      return identifiers_.size() < identifiers.size() ?
          kLessThan : kGreaterThan;
  }

  return kEqualTo;
}
Beispiel #16
0
//writes Key=value given section
void CIniEx::SetValue(CString Section,CString Key,CString Value)
{
	//file opened?
	ASSERT(!m_FileName.IsEmpty());

	//if given key already existing, overwrite it
	int nIndex=LookupSection(&Section);
	int nKeyIndex;
	if (nIndex==-1)
	{
		//if key not exist grow arrays (if necessary)
		m_Changed=TRUE;
		m_SectionNo++;
		GrowIfNecessary();
		m_Keys[m_SectionNo-1]=new CStringArray;
		m_Values[m_SectionNo-1]=new CStringArray;
		nIndex=m_SectionNo-1;
		m_Sections.SetAtGrow(m_SectionNo-1,Section);
	}

	
	//looking up keys for section
	nKeyIndex=LookupKey(nIndex,&Key);
	
	//if key exist -> overwrite it
	//if not add to end of array
	if (nKeyIndex!=-1) 
	{
		if (CompareStrings(&m_Values[nIndex]->GetAt(nKeyIndex),&Value)!=0)
			m_Changed=TRUE;
		m_Values[nIndex]->SetAt(nKeyIndex,Value);
	}
	else	//if not exist
	{
		m_Changed=TRUE;
		m_Keys[nIndex]->Add(Key);
		m_Values[nIndex]->Add(Value);
	}
}
Beispiel #17
0
void FeedConditionDialog::ChooseElement(int element_index) {
  // Operator
  LPARAM op_data = operator_combo_.GetItemData(operator_combo_.GetCurSel());
  operator_combo_.ResetContent();

  #define ADD_OPERATOR(op) \
    operator_combo_.AddItem(Aggregator.filter_manager.TranslateOperator(op).c_str(), op);

  switch (element_index) {
    case FEED_FILTER_ELEMENT_META_ID:
    case FEED_FILTER_ELEMENT_EPISODE_NUMBER:
    case FEED_FILTER_ELEMENT_META_DATE_START:
    case FEED_FILTER_ELEMENT_META_DATE_END:
    case FEED_FILTER_ELEMENT_META_EPISODES:
      ADD_OPERATOR(FEED_FILTER_OPERATOR_EQUALS);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_NOTEQUALS);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_ISGREATERTHAN);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_ISGREATERTHANOREQUALTO);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_ISLESSTHAN);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_ISLESSTHANOREQUALTO);
      break;
    case FEED_FILTER_ELEMENT_LOCAL_EPISODE_AVAILABLE:
    case FEED_FILTER_ELEMENT_META_STATUS:
    case FEED_FILTER_ELEMENT_META_TYPE:
    case FEED_FILTER_ELEMENT_USER_STATUS:
      ADD_OPERATOR(FEED_FILTER_OPERATOR_EQUALS);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_NOTEQUALS);
      break;
    case FEED_FILTER_ELEMENT_EPISODE_TITLE:
    case FEED_FILTER_ELEMENT_EPISODE_GROUP:
    case FEED_FILTER_ELEMENT_EPISODE_VIDEO_TYPE:
    case FEED_FILTER_ELEMENT_FILE_TITLE:
    case FEED_FILTER_ELEMENT_FILE_CATEGORY:
    case FEED_FILTER_ELEMENT_FILE_DESCRIPTION:
    case FEED_FILTER_ELEMENT_FILE_LINK:
      ADD_OPERATOR(FEED_FILTER_OPERATOR_EQUALS);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_NOTEQUALS);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_BEGINSWITH);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_ENDSWITH);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_CONTAINS);
      ADD_OPERATOR(FEED_FILTER_OPERATOR_NOTCONTAINS);
      break;
    default:
      for (int i = 0; i < FEED_FILTER_OPERATOR_COUNT; i++) {
        ADD_OPERATOR(i);
      }
  }

  #undef ADD_OPERATOR

  int op_index = operator_combo_.FindItemData(op_data);
  if (op_index == CB_ERR)
    op_index = 0;
  operator_combo_.SetCurSel(op_index);
  
  // ===========================================================================
  
  // Value
  value_combo_.ResetContent();

  RECT rect;
  value_combo_.GetWindowRect(&rect);
  int width = rect.right - rect.left;
  int height = rect.bottom - rect.top;
  ::ScreenToClient(m_hWindow, reinterpret_cast<LPPOINT>(&rect));

  #define RECREATE_COMBO(style) \
    value_combo_.Create(0, WC_COMBOBOX, nullptr, \
      style | CBS_AUTOHSCROLL | WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_VSCROLL, \
      rect.left, rect.top, width, height * 2, \
      m_hWindow, nullptr, nullptr);

  switch (element_index) {
    case FEED_FILTER_ELEMENT_FILE_CATEGORY:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"Anime");
      value_combo_.AddString(L"Batch");
      value_combo_.AddString(L"Hentai");
      value_combo_.AddString(L"Non-English");
      value_combo_.AddString(L"Other");
      value_combo_.AddString(L"Raws");
      break;
    case FEED_FILTER_ELEMENT_META_ID:
    case FEED_FILTER_ELEMENT_EPISODE_TITLE: {
      RECREATE_COMBO((element_index == FEED_FILTER_ELEMENT_META_ID ? CBS_DROPDOWNLIST : CBS_DROPDOWN));
      typedef std::pair<int, wstring> anime_pair;
      vector<anime_pair> title_list;
      for (auto it = AnimeDatabase.items.begin(); it != AnimeDatabase.items.end(); ++it) {
        switch (it->second.GetMyStatus()) {
          case mal::MYSTATUS_NOTINLIST:
          case mal::MYSTATUS_COMPLETED:
          case mal::MYSTATUS_DROPPED:
            continue;
          default:
            title_list.push_back(std::make_pair(it->second.GetId(), 
              AnimeDatabase.FindItem(it->second.GetId())->GetTitle()));
        }
      }
      std::sort(title_list.begin(), title_list.end(), 
        [](const anime_pair& a1, const anime_pair& a2) {
          return CompareStrings(a1.second, a2.second) < 0;
        });
      if (element_index == FEED_FILTER_ELEMENT_META_ID) {
        value_combo_.AddString(L"(Unknown)");
      }
      for (auto it = title_list.begin(); it != title_list.end(); ++it) {
        value_combo_.AddItem(it->second.c_str(), it->first);
      }
      break;
    }
    case FEED_FILTER_ELEMENT_META_DATE_START:
    case FEED_FILTER_ELEMENT_META_DATE_END:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(static_cast<wstring>(GetDate()).c_str());
      value_combo_.SetCueBannerText(L"YYYY-MM-DD");
      break;
    case FEED_FILTER_ELEMENT_META_STATUS:
      RECREATE_COMBO(CBS_DROPDOWNLIST);
      value_combo_.AddItem(mal::TranslateStatus(mal::STATUS_AIRING).c_str(), mal::STATUS_AIRING);
      value_combo_.AddItem(mal::TranslateStatus(mal::STATUS_FINISHED).c_str(), mal::STATUS_FINISHED);
      value_combo_.AddItem(mal::TranslateStatus(mal::STATUS_NOTYETAIRED).c_str(), mal::STATUS_NOTYETAIRED);
      break;
    case FEED_FILTER_ELEMENT_META_TYPE:
      RECREATE_COMBO(CBS_DROPDOWNLIST);
      value_combo_.AddItem(mal::TranslateType(mal::TYPE_TV).c_str(), mal::TYPE_TV);
      value_combo_.AddItem(mal::TranslateType(mal::TYPE_OVA).c_str(), mal::TYPE_OVA);
      value_combo_.AddItem(mal::TranslateType(mal::TYPE_MOVIE).c_str(), mal::TYPE_MOVIE);
      value_combo_.AddItem(mal::TranslateType(mal::TYPE_SPECIAL).c_str(), mal::TYPE_SPECIAL);
      value_combo_.AddItem(mal::TranslateType(mal::TYPE_ONA).c_str(), mal::TYPE_ONA);
      value_combo_.AddItem(mal::TranslateType(mal::TYPE_MUSIC).c_str(), mal::TYPE_MUSIC);
      break;
    case FEED_FILTER_ELEMENT_USER_STATUS:
      RECREATE_COMBO(CBS_DROPDOWNLIST);
      value_combo_.AddItem(mal::TranslateMyStatus(mal::MYSTATUS_NOTINLIST, false).c_str(), mal::MYSTATUS_NOTINLIST);
      value_combo_.AddItem(mal::TranslateMyStatus(mal::MYSTATUS_WATCHING, false).c_str(), mal::MYSTATUS_WATCHING);
      value_combo_.AddItem(mal::TranslateMyStatus(mal::MYSTATUS_COMPLETED, false).c_str(), mal::MYSTATUS_COMPLETED);
      value_combo_.AddItem(mal::TranslateMyStatus(mal::MYSTATUS_ONHOLD, false).c_str(), mal::MYSTATUS_ONHOLD);
      value_combo_.AddItem(mal::TranslateMyStatus(mal::MYSTATUS_DROPPED, false).c_str(), mal::MYSTATUS_DROPPED);
      value_combo_.AddItem(mal::TranslateMyStatus(mal::MYSTATUS_PLANTOWATCH, false).c_str(), mal::MYSTATUS_PLANTOWATCH);
      break;
    case FEED_FILTER_ELEMENT_EPISODE_NUMBER:
    case FEED_FILTER_ELEMENT_META_EPISODES:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"%watched%");
      value_combo_.AddString(L"%total%");
      break;
    case FEED_FILTER_ELEMENT_EPISODE_VERSION:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"2");
      value_combo_.AddString(L"3");
      value_combo_.AddString(L"4");
      value_combo_.AddString(L"0");
      break;
    case FEED_FILTER_ELEMENT_LOCAL_EPISODE_AVAILABLE:
      RECREATE_COMBO(CBS_DROPDOWNLIST);
      value_combo_.AddString(L"False");
      value_combo_.AddString(L"True");
      break;
    case FEED_FILTER_ELEMENT_EPISODE_VIDEO_RESOLUTION:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"1080p");
      value_combo_.AddString(L"720p");
      value_combo_.AddString(L"480p");
      value_combo_.AddString(L"400p");
      break;
    case FEED_FILTER_ELEMENT_EPISODE_VIDEO_TYPE:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"h264");
      value_combo_.AddString(L"x264");
      value_combo_.AddString(L"XviD");
      break;
    default:
      RECREATE_COMBO(CBS_DROPDOWN);
      break;
  }

  #undef RECREATE_COMBO
  value_combo_.SetCurSel(0);
}
void FeedConditionDialog::ChooseElement(int element_index) {
  // Operator
  LPARAM op_data = operator_combo_.GetItemData(operator_combo_.GetCurSel());
  operator_combo_.ResetContent();

  #define ADD_OPERATOR(op) \
    operator_combo_.AddItem(Aggregator.filter_manager.TranslateOperator(op).c_str(), op);

  switch (element_index) {
    case kFeedFilterElement_Meta_Id:
    case kFeedFilterElement_Episode_Number:
    case kFeedFilterElement_Meta_DateStart:
    case kFeedFilterElement_Meta_DateEnd:
    case kFeedFilterElement_Meta_Episodes:
      ADD_OPERATOR(kFeedFilterOperator_Equals);
      ADD_OPERATOR(kFeedFilterOperator_NotEquals);
      ADD_OPERATOR(kFeedFilterOperator_IsGreaterThan);
      ADD_OPERATOR(kFeedFilterOperator_IsGreaterThanOrEqualTo);
      ADD_OPERATOR(kFeedFilterOperator_IsLessThan);
      ADD_OPERATOR(kFeedFilterOperator_IsLessThanOrEqualTo);
      break;
    case kFeedFilterElement_Local_EpisodeAvailable:
    case kFeedFilterElement_Meta_Status:
    case kFeedFilterElement_Meta_Type:
    case kFeedFilterElement_User_Status:
      ADD_OPERATOR(kFeedFilterOperator_Equals);
      ADD_OPERATOR(kFeedFilterOperator_NotEquals);
      break;
    case kFeedFilterElement_Episode_Title:
    case kFeedFilterElement_Episode_Group:
    case kFeedFilterElement_Episode_VideoType:
    case kFeedFilterElement_File_Title:
    case kFeedFilterElement_File_Category:
    case kFeedFilterElement_File_Description:
    case kFeedFilterElement_File_Link:
      ADD_OPERATOR(kFeedFilterOperator_Equals);
      ADD_OPERATOR(kFeedFilterOperator_NotEquals);
      ADD_OPERATOR(kFeedFilterOperator_BeginsWith);
      ADD_OPERATOR(kFeedFilterOperator_EndsWith);
      ADD_OPERATOR(kFeedFilterOperator_Contains);
      ADD_OPERATOR(kFeedFilterOperator_NotContains);
      break;
    default:
      for (int i = 0; i < kFeedFilterOperator_Count; i++) {
        ADD_OPERATOR(i);
      }
  }

  #undef ADD_OPERATOR

  int op_index = operator_combo_.FindItemData(op_data);
  if (op_index == CB_ERR)
    op_index = 0;
  operator_combo_.SetCurSel(op_index);

  //////////////////////////////////////////////////////////////////////////////
  // Value

  value_combo_.ResetContent();

  RECT rect;
  value_combo_.GetWindowRect(&rect);
  int width = rect.right - rect.left;
  int height = rect.bottom - rect.top;
  ::ScreenToClient(GetWindowHandle(), reinterpret_cast<LPPOINT>(&rect));

  #define RECREATE_COMBO(style) \
    value_combo_.Create(0, WC_COMBOBOX, nullptr, \
        style | CBS_AUTOHSCROLL | WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_VSCROLL, \
        rect.left, rect.top, width, height * 2, \
        GetWindowHandle(), nullptr, nullptr);

  switch (element_index) {
    case kFeedFilterElement_File_Category:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"Anime");
      value_combo_.AddString(L"Batch");
      value_combo_.AddString(L"Hentai");
      value_combo_.AddString(L"Non-English");
      value_combo_.AddString(L"Other");
      value_combo_.AddString(L"Raws");
      break;
    case kFeedFilterElement_Meta_Id:
    case kFeedFilterElement_Episode_Title: {
      RECREATE_COMBO((element_index == kFeedFilterElement_Meta_Id ? CBS_DROPDOWNLIST : CBS_DROPDOWN));
      typedef std::pair<int, std::wstring> anime_pair;
      std::vector<anime_pair> title_list;
      for (auto it = AnimeDatabase.items.begin(); it != AnimeDatabase.items.end(); ++it) {
        switch (it->second.GetMyStatus()) {
          case anime::kNotInList:
          case anime::kCompleted:
          case anime::kDropped:
            continue;
          default:
            title_list.push_back(std::make_pair(
                it->second.GetId(),
                AnimeDatabase.FindItem(it->second.GetId())->GetTitle()));
        }
      }
      std::sort(title_list.begin(), title_list.end(),
        [](const anime_pair& a1, const anime_pair& a2) {
          return CompareStrings(a1.second, a2.second) < 0;
        });
      if (element_index == kFeedFilterElement_Meta_Id)
        value_combo_.AddString(L"(Unknown)");
      foreach_(it, title_list)
        value_combo_.AddItem(it->second.c_str(), it->first);
      break;
    }
    case kFeedFilterElement_Meta_DateStart:
    case kFeedFilterElement_Meta_DateEnd:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(static_cast<std::wstring>(GetDate()).c_str());
      value_combo_.SetCueBannerText(L"YYYY-MM-DD");
      break;
    case kFeedFilterElement_Meta_Status:
      RECREATE_COMBO(CBS_DROPDOWNLIST);
      value_combo_.AddItem(anime::TranslateStatus(anime::kAiring).c_str(), anime::kAiring);
      value_combo_.AddItem(anime::TranslateStatus(anime::kFinishedAiring).c_str(), anime::kFinishedAiring);
      value_combo_.AddItem(anime::TranslateStatus(anime::kNotYetAired).c_str(), anime::kNotYetAired);
      break;
    case kFeedFilterElement_Meta_Type:
      RECREATE_COMBO(CBS_DROPDOWNLIST);
      value_combo_.AddItem(anime::TranslateType(anime::kTv).c_str(), anime::kTv);
      value_combo_.AddItem(anime::TranslateType(anime::kOva).c_str(), anime::kOva);
      value_combo_.AddItem(anime::TranslateType(anime::kMovie).c_str(), anime::kMovie);
      value_combo_.AddItem(anime::TranslateType(anime::kSpecial).c_str(), anime::kSpecial);
      value_combo_.AddItem(anime::TranslateType(anime::kOna).c_str(), anime::kOna);
      value_combo_.AddItem(anime::TranslateType(anime::kMusic).c_str(), anime::kMusic);
      break;
    case kFeedFilterElement_User_Status:
      RECREATE_COMBO(CBS_DROPDOWNLIST);
      value_combo_.AddItem(anime::TranslateMyStatus(anime::kNotInList, false).c_str(), anime::kNotInList);
      value_combo_.AddItem(anime::TranslateMyStatus(anime::kWatching, false).c_str(), anime::kWatching);
      value_combo_.AddItem(anime::TranslateMyStatus(anime::kCompleted, false).c_str(), anime::kCompleted);
      value_combo_.AddItem(anime::TranslateMyStatus(anime::kOnHold, false).c_str(), anime::kOnHold);
      value_combo_.AddItem(anime::TranslateMyStatus(anime::kDropped, false).c_str(), anime::kDropped);
      value_combo_.AddItem(anime::TranslateMyStatus(anime::kPlanToWatch, false).c_str(), anime::kPlanToWatch);
      break;
    case kFeedFilterElement_Episode_Number:
    case kFeedFilterElement_Meta_Episodes:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"%watched%");
      value_combo_.AddString(L"%total%");
      break;
    case kFeedFilterElement_Episode_Version:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"2");
      value_combo_.AddString(L"3");
      value_combo_.AddString(L"4");
      value_combo_.AddString(L"0");
      break;
    case kFeedFilterElement_Local_EpisodeAvailable:
      RECREATE_COMBO(CBS_DROPDOWNLIST);
      value_combo_.AddString(L"False");
      value_combo_.AddString(L"True");
      break;
    case kFeedFilterElement_Episode_VideoResolution:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"1080p");
      value_combo_.AddString(L"720p");
      value_combo_.AddString(L"480p");
      value_combo_.AddString(L"400p");
      break;
    case kFeedFilterElement_Episode_VideoType:
      RECREATE_COMBO(CBS_DROPDOWN);
      value_combo_.AddString(L"h264");
      value_combo_.AddString(L"x264");
      value_combo_.AddString(L"XviD");
      break;
    default:
      RECREATE_COMBO(CBS_DROPDOWN);
      break;
  }

  #undef RECREATE_COMBO
  value_combo_.SetCurSel(0);
}
Beispiel #19
0
bool EvaluateCondition(const FeedFilterCondition& condition,
                       const FeedItem& item) {
  bool is_numeric = false;
  std::wstring element;
  std::wstring value = ReplaceVariables(condition.value, item.episode_data);
  auto anime = AnimeDatabase.FindItem(item.episode_data.anime_id);

  switch (condition.element) {
    case kFeedFilterElement_File_Title:
      element = item.title;
      break;
    case kFeedFilterElement_File_Category:
      element = item.category;
      break;
    case kFeedFilterElement_File_Description:
      element = item.description;
      break;
    case kFeedFilterElement_File_Link:
      element = item.link;
      break;
    case kFeedFilterElement_Meta_Id:
      if (anime)
        element = ToWstr(anime->GetId());
      is_numeric = true;
      break;
    case kFeedFilterElement_Episode_Title:
      element = item.episode_data.title;
      break;
    case kFeedFilterElement_Meta_DateStart:
      if (anime)
        element = anime->GetDateStart();
      break;
    case kFeedFilterElement_Meta_DateEnd:
      if (anime)
        element = anime->GetDateEnd();
      break;
    case kFeedFilterElement_Meta_Episodes:
      if (anime)
        element = ToWstr(anime->GetEpisodeCount());
      is_numeric = true;
      break;
    case kFeedFilterElement_Meta_Status:
      if (anime)
        element = ToWstr(anime->GetAiringStatus());
      is_numeric = true;
      break;
    case kFeedFilterElement_Meta_Type:
      if (anime)
        element = ToWstr(anime->GetType());
      is_numeric = true;
      break;
    case kFeedFilterElement_User_Status:
      if (anime)
        element = ToWstr(anime->GetMyStatus());
      is_numeric = true;
      break;
    case kFeedFilterElement_Episode_Number:
      element = ToWstr(anime::GetEpisodeHigh(item.episode_data.number));
      is_numeric = true;
      break;
    case kFeedFilterElement_Episode_Version:
      element = item.episode_data.version;
      if (element.empty())
        element = L"1";
      is_numeric = true;
      break;
    case kFeedFilterElement_Local_EpisodeAvailable:
      if (anime)
        element = ToWstr(anime->IsEpisodeAvailable(
            anime::GetEpisodeHigh(item.episode_data.number)));
      is_numeric = true;
      break;
    case kFeedFilterElement_Episode_Group:
      element = item.episode_data.group;
      break;
    case kFeedFilterElement_Episode_VideoResolution:
      element = item.episode_data.resolution;
      break;
    case kFeedFilterElement_Episode_VideoType:
      element = item.episode_data.video_type;
      break;
  }

  switch (condition.op) {
    case kFeedFilterOperator_Equals:
      if (is_numeric) {
        if (IsEqual(value, L"True"))
          return ToInt(element) == TRUE;
        return ToInt(element) == ToInt(value);
      } else {
        if (condition.element == kFeedFilterElement_Episode_VideoResolution) {
          return anime::TranslateResolution(element) == anime::TranslateResolution(condition.value);
        } else {
          return IsEqual(element, value);
        }
      }
    case kFeedFilterOperator_NotEquals:
      if (is_numeric) {
        if (IsEqual(value, L"True"))
          return ToInt(element) == TRUE;
        return ToInt(element) != ToInt(value);
      } else {
        if (condition.element == kFeedFilterElement_Episode_VideoResolution) {
          return anime::TranslateResolution(element) != anime::TranslateResolution(condition.value);
        } else {
          return !IsEqual(element, value);
        }
      }
    case kFeedFilterOperator_IsGreaterThan:
      if (is_numeric) {
        return ToInt(element) > ToInt(value);
      } else {
        if (condition.element == kFeedFilterElement_Episode_VideoResolution) {
          return anime::TranslateResolution(element) > anime::TranslateResolution(condition.value);
        } else {
          return CompareStrings(element, condition.value) > 0;
        }
      }
    case kFeedFilterOperator_IsGreaterThanOrEqualTo:
      if (is_numeric) {
        return ToInt(element) >= ToInt(value);
      } else {
        if (condition.element == kFeedFilterElement_Episode_VideoResolution) {
          return anime::TranslateResolution(element) >= anime::TranslateResolution(condition.value);
        } else {
          return CompareStrings(element, condition.value) >= 0;
        }
      }
    case kFeedFilterOperator_IsLessThan:
      if (is_numeric) {
        return ToInt(element) < ToInt(value);
      } else {
        if (condition.element == kFeedFilterElement_Episode_VideoResolution) {
          return anime::TranslateResolution(element) < anime::TranslateResolution(condition.value);
        } else {
          return CompareStrings(element, condition.value) < 0;
        }
      }
    case kFeedFilterOperator_IsLessThanOrEqualTo:
      if (is_numeric) {
        return ToInt(element) <= ToInt(value);
      } else {
        if (condition.element == kFeedFilterElement_Episode_VideoResolution) {
          return anime::TranslateResolution(element) <= anime::TranslateResolution(condition.value);
        } else {
          return CompareStrings(element, condition.value) <= 0;
        }
      }
    case kFeedFilterOperator_BeginsWith:
      return StartsWith(element, value);
    case kFeedFilterOperator_EndsWith:
      return EndsWith(element, value);
    case kFeedFilterOperator_Contains:
      return InStr(element, value, 0, true) > -1;
    case kFeedFilterOperator_NotContains:
      return InStr(element, value, 0, true) == -1;
  }

  return false;
}
int main(int argc, char** argv)
{
    bool32 FlagActivated = 0;
    
    for(int i=0;
        i < argc;
        i++)
    {
        char Flag[MAX_FLAG_CHAR];  

        // NOTE: '-' Indicate that a flag name is what comes next
        if(argv[i][0] == '-')
        {
            int IndexArray = 0;
            for(argv[i][1];
                *argv[i];
                argv[i]++)
            {
                if (IndexArray < (MAX_FLAG_CHAR - 1))
                {
                    Flag[IndexArray] = *argv[i];
                    IndexArray++;
                }
            }

            if (CompareStrings(Flag, "-h", 2) == 0)
            {
                FlagActivated = FlagActivated|HELP_FLAG; //0x00      
                ShowHelpPage();
            }

            else if (CompareStrings(Flag, "-cc", 3) == 0)
            {
                FlagActivated = FlagActivated|CHANGE_TARGET_DIRECTORY_FLAG; // 0x01
            }

            else if (CompareStrings(Flag, "-s", 2) == 0)
            {
                FlagActivated = FlagActivated|SOURCE_FILE_FLAG; // 0x02
            }

            else
            {
                // logging
            }
        }

        // NOTE: '@' represents char that indicates that what comes next is an diretory
        else if(argv[i][0] == '@')
        {
                                    
        }
        
        else
        {
            // logging
        }
        
    }

    bool Running = true;
    bool ProjectAssigned = false;
    tree_directory *TreeRootDirectory;
    tree_directory *TreeActualDirectory;
    char PathToPrepend[MAX_PATH_SIZE]; 
    
    WelcomeMessage();

    while(Running)
    {

        char CommandLine[MAX_LINE_SIZE];
        char CLineLowerCase[MAX_LINE_SIZE];
        char CommandName[MAX_LINE_SIZE];
        char CommandAction[MAX_LINE_SIZE];
        
        printf("\nC-environment Shell> ");

        // TODO: Make space before first world do not count for the string comparisons
        gets_s(CommandLine, MAX_LINE_SIZE); 

        IgnoreSpaces(CommandLine, CharArrayCount(CommandLine));
        printf("CommandLine without spaces before: '%s'", CommandLine);

        
        BreakString(CommandLine, CharArrayCount(CLineLowerCase), CommandName,
                    CommandAction, SPACE_CHAR);
        ToLowerCase(CommandName, CLineLowerCase, MAX_LINE_SIZE);

#if 0
        // NOTE: Debug Lines
        printf("CommandLine: %s\tCLineLowerCase: %s\nCommandAction: %s",CommandLine,
               CLineLowerCase, CommandAction);
#endif


        // TODO: Program still have some problems with parsing the input with spaces before command 
        if(CompareStrings(CLineLowerCase, "setprojectname", sizeof("setprojectname")) == 0)
        {
            if (IS_EMPTY_STRING(CommandAction))
            {
                printf("\nAction for command '%s' not found\n Usage:\t'%s [Project Name]'\n",
                       CLineLowerCase, CLineLowerCase);
            }
            TreeRootDirectory = TreeDirectoryCreate(CommandAction);
            TreeActualDirectory = TreeRootDirectory;
            StringCopy(PathToPrepend, CommandAction, CharArrayCount(CommandAction));
            AppendString(PathToPrepend, "/");
            ProjectAssigned = true;
        }
        
        else if(CompareStrings(CLineLowerCase, "createdir", sizeof("createdir")) == 0)
        {
            char ActualPath[MAX_PATH_SIZE];
            StringCopy(ActualPath, PathToPrepend, CharArrayCount(PathToPrepend));
            
            if (ProjectAssigned && !IS_EMPTY_STRING(CommandAction))
            {
                // TODO: Parse if the directory name is valid
                
                // TODO: Prevent PathToPrepend to grow 
                AppendString(PathToPrepend, CommandAction);
                AppendString(PathToPrepend, "/");
                
                // TODO: Virtual file system structured in a tree   
                tree_directory *TreeDirectory = TreeDirectoryCreate(ActualPath);

                // NOTE: More debug lines
                printf("Path: %s", ActualPath);
                printf("Path2: %s", TreeDirectory->PathName);
                
                TreeDirectoryAddNode(TreeActualDirectory, TreeDirectory);
            }

            else if (!ProjectAssigned)
            {
                // TODO: logging system
            }

            else if (IS_EMPTY_STRING(CommandAction))
            {
                // TODO: Logging system
            }
            StringCopy(PathToPrepend, ActualPath, CharArrayCount(ActualPath));
        }

        // TODO: Not sure how to do pathfinder right now!
        else if(CompareStrings(CLineLowerCase, "setdir", sizeof("setdir")) == 0)
        {
            char *DirName = CommandAction;
            if (!IS_EMPTY_STRING(CommandAction))
            {
                if (TreeDirSearchBrother(TreeActualDirectory, DirName))
                {
                    AppendString(PathToPrepend, CommandAction);
                    AppendString(PathToPrepend, "/");

                    TreeDirGoToDirectory(TreeActualDirectory, DirName);
                }
            }
        }

        else if(CompareStrings(CLineLowerCase, "saveconfig", sizeof("saveconfig")) == 0)
        {
            // TODO: Save settings to a file, that can be evoked lately, or in any other
            // instance of the program
        }
        
        else if(CompareStrings(CLineLowerCase, "exit", sizeof("exit")) == 0)
        {
            Running = false;
        }

        else
        {
            printf("\nCommand not found. Type '-h' for help. Command 'exit' is self explanatory.\n");
        }
    }
    return 0;
}
Beispiel #21
0
//CLEAR SCREEN (ACCEPTS COLOUR AS PARAMETER)
void Commands::ClearScreen()
{
	byte foreground = 0;
	byte background = 0;
	byte blinking = 0;
	Video::ClearScreen();
	Video::Print("Background Colour Options:");
	Video::NewLine();
	//Background
BackGround:
	Video::Print("Black     Blue      Green     Red       Aqua      Violet    Orange    White     ");
	Video::Print("          ", 0);
	Video::Print("          ", 16);
	Video::Print("          ", 32);
	Video::Print("          ", 64);
	Video::Print("          ", 48);
	Video::Print("          ", 80);
	Video::Print("          ", 96);
	Video::Print("          ", 112);

	Video::Print("Type in the name of the colour: ");
	static char colour[10];
	byte colourCounter = 0;
	while (true)
	{
		Keyboard::AsciiKey key = Keyboard::GetAsciiKey();
		if (key.IsBreak == true)
			continue;

		if (key.Data != 0)
		{
			if (key.Data == 19)
			{
				if (colourCounter == 0)
					continue;
				Video::BackSpace();
				colourCounter--;
				colour[colourCounter] = 0;
			}
			if (key.Data == 2)
			{
				colour[colourCounter] = 0;
				Video::NewLine();
				break;
			}
			continue;
		}
		char keyPrint[2] = {0};
		keyPrint[0] = key.Char;
		Video::Print(keyPrint);
		colour[colourCounter] = key.Char;
		colourCounter++;
		if (colourCounter == 9)
		{
			Video::NewLine();
			Video::Print("Invalid Colour, Enter Proper Value");
			Video::NewLine();
			goto BackGround;
		}

	}

	if (CompareStrings(colour, "Black"))
	{
		background = 0;
	}
	else if (CompareStrings(colour, "Blue"))
	{
		background = 16;
	}
	else if (CompareStrings(colour, "Green"))
	{
		background = 32;
	}
	else if (CompareStrings(colour, "Red"))
	{
		background = 64;
	}
	else if (CompareStrings(colour, "Aqua"))
	{
		background = 48;
	}	
	else if (CompareStrings(colour, "Violet"))
	{
		background = 80;
	}
	else if (CompareStrings(colour, "Orange"))
	{
		background = 96;
	}
	else if (CompareStrings(colour, "White"))
	{
		background = 112;
	}
	else 
	{
		Video::Print("Invalid Colour");
		Video::NewLine();
		goto BackGround;
	}

	//ForGround
ForeGround:
	Video::NewLine();
	Video::Print("Foreground Colour Options:");
	Video::NewLine();
	Video::Print("Black     Blue      Green     Red       Aqua      Violet    Orange    White     ");
	Video::Print("Foreground", 0 | background);
	Video::Print("Foreground", 1 | background);
	Video::Print("Foreground", 2 | background);
	Video::Print("Foreground", 4 | background);
	Video::Print("Foreground", 3 | background);
	Video::Print("Foreground", 5 | background);
	Video::Print("Foreground", 6 | background);
	Video::Print("Foreground", 7 | background);
	

	Video::Print("Type in the name of the colour: ");
	static char colourf[10];
	byte colourCounterf = 0;
	while (true)
	{
		Keyboard::AsciiKey key = Keyboard::GetAsciiKey();
		if (key.IsBreak == true)
			continue;

		if (key.Data != 0)
		{
			if (key.Data == 19)
			{
				if (colourCounterf == 0)
					continue;
				Video::BackSpace();
				colourCounterf--;
				colourf[colourCounterf] = 0;
			}
			if (key.Data == 2)
			{
				colourf[colourCounterf] = 0;
				Video::NewLine();
				break;
			}
			continue;
		}
		char keyPrint[2] = {0};
		keyPrint[0] = key.Char;
		Video::Print(keyPrint);
		colourf[colourCounterf] = key.Char;
		colourCounterf++;
		if (colourCounterf == 9)
		{
			Video::NewLine();
			Video::Print("Invalid Colour, Enter Proper Value");
			Video::NewLine();
			goto ForeGround;
		}

	}

	if (CompareStrings(colourf, "Black"))
	{
		foreground = 0;
	}
	else if (CompareStrings(colourf, "Blue"))
	{
		foreground = 1;
	}
	else if (CompareStrings(colourf, "Green"))
	{
		foreground = 2;
	}
	else if (CompareStrings(colourf, "Red"))
	{
		foreground = 4;
	}
	else if (CompareStrings(colourf, "Aqua"))
	{
		foreground = 3;
	}	
	else if (CompareStrings(colourf, "Violet"))
	{
		foreground = 5;
	}
	else if (CompareStrings(colourf, "Orange"))
	{
		foreground = 6;
	}
	else if (CompareStrings(colourf, "White"))
	{
		foreground = 7;
	}
	else 
	{
		Video::Print("Invalid Colour");
		Video::NewLine();
		goto ForeGround;
	}

	//Light
	Video::NewLine();
	Video::Print("Do you wish to have a light foreground colour? (y/n): ");
	while (true)
	{
		Keyboard::AsciiKey key = Keyboard::GetAsciiKey();
		if (key.IsBreak == true)
		{
			continue;
		}

		if (key.Char == 'y')
		{
			Video::Print("y");
			foreground |= 8;
			break;
		}
		if (key.Char == 'n')
		{
			Video::Print("n");
			break;
		}
	}
	Video::NewLine();

	//Blinking
	Video::Print("Do you wish to have the foreground blinking? (y/n): ");
	while (true)
	{
		Keyboard::AsciiKey key = Keyboard::GetAsciiKey();
		if (key.IsBreak == true)
		{
			continue;
		}

		if (key.Char == 'y')
		{
			Video::Print("y");
			foreground |= 128;
			break;
		}
		if (key.Char == 'n')
		{
			Video::Print("n");
			break;
		}
	}

	DefaultColour = (background | foreground | blinking);
	Video::ClearScreen((background | foreground | blinking));
}
Beispiel #22
0
//Pauses Operating System
void Commands::Sleep()
{
	char password[200];
	byte passwordCounter = 0;
	Video::Print("Please enter your desired password: "******" ");
				password[passwordCounter] = 0;
				break;
			}
			continue;
		}

		char keychar[2] = {0};
		keychar[0] = key.Char;
		Video::Print(keychar);
		password[passwordCounter] = key.Char;
		passwordCounter++;

		if (passwordCounter == 200)
		{
			break;
		}
	}

	Video::Print("Saving...");
	PIT::StartSystemTimer(1);
	passwordCounter += 10;
	for (word i = 0; i < passwordCounter; i++)
	{
		Video::BackSpace();
	}
	Video::NewLine();

	Video::Print("How many seconds do you want to sleep? ");
	dword numbers[10] = {0};
	byte numberCounter = 0;
	dword number = GetNumber();
	
	char colourholder = Video::CurrentColour();
	Video::ChangeColour(00);

	PIT::StartSystemTimer(number);
	Video::ChangeColour(colourholder);

Password:
	char password2[200];
	byte passwordCounter2 = 0;
	Video::Print("Please enter your password: "******"Password Approved.");
		Video::NewLine();
	}
	else
	{
		Video::Print("Invalid Password.");
		Video::NewLine();
		goto Password;
	}
}
// Public method for computing the combiner features. The agreement
// output parameter will be true if both answers are identical,
// and false otherwise.
bool TesseractCubeCombiner::ComputeCombinerFeatures(const string &tess_str,
                                                    int tess_confidence,
                                                    CubeObject *cube_obj,
                                                    WordAltList *cube_alt_list,
                                                    vector<double> *features,
                                                    bool *agreement) {
  features->clear();
  *agreement = false;
  if (cube_alt_list == NULL || cube_alt_list->AltCount() <= 0)
    return false;

  // Get Cube's best string; return false if empty
  char_32 *cube_best_str32 = cube_alt_list->Alt(0);
  if (cube_best_str32 == NULL || CubeUtils::StrLen(cube_best_str32) < 1)
    return false;
  string cube_best_str;
  int cube_best_cost = cube_alt_list->AltCost(0);
  int cube_best_bigram_cost = 0;
  bool cube_best_bigram_cost_valid = true;
  if (cube_cntxt_->Bigrams())
    cube_best_bigram_cost = cube_cntxt_->Bigrams()->
        Cost(cube_best_str32, cube_cntxt_->CharacterSet());
  else
    cube_best_bigram_cost_valid = false;
  CubeUtils::UTF32ToUTF8(cube_best_str32, &cube_best_str);

  // Get Tesseract's UTF32 string
  string_32 tess_str32;
  CubeUtils::UTF8ToUTF32(tess_str.c_str(), &tess_str32);

  // Compute agreement flag
  *agreement = (tess_str.compare(cube_best_str) == 0);

  // Get Cube's second best string; if empty, return false
  char_32 *cube_next_best_str32;
  string cube_next_best_str;
  int cube_next_best_cost = WORST_COST;
  if (cube_alt_list->AltCount() > 1) {
    cube_next_best_str32 = cube_alt_list->Alt(1);
    if (cube_next_best_str32 == NULL ||
        CubeUtils::StrLen(cube_next_best_str32) == 0) {
      return false;
    }
    cube_next_best_cost = cube_alt_list->AltCost(1);
    CubeUtils::UTF32ToUTF8(cube_next_best_str32, &cube_next_best_str);
  }
  // Rank of Tesseract's top result in Cube's alternate list
  int tess_rank = 0;
  for (tess_rank = 0; tess_rank < cube_alt_list->AltCount(); tess_rank++) {
    string alt_str;
    CubeUtils::UTF32ToUTF8(cube_alt_list->Alt(tess_rank), &alt_str);
    if (alt_str == tess_str)
      break;
  }

  // Cube's cost for tesseract's result. Note that this modifies the
  // state of cube_obj, including its alternate list by calling RecognizeWord()
  int tess_cost = cube_obj->WordCost(tess_str.c_str());
  // Cube's bigram cost of Tesseract's string
  int tess_bigram_cost = 0;
  int tess_bigram_cost_valid = true;
  if (cube_cntxt_->Bigrams())
    tess_bigram_cost = cube_cntxt_->Bigrams()->
        Cost(tess_str32.c_str(), cube_cntxt_->CharacterSet());
  else
    tess_bigram_cost_valid = false;

  // Tesseract confidence
  features->push_back(tess_confidence);
  // Cube cost of Tesseract string
  features->push_back(tess_cost);
  // Cube Rank of Tesseract string
  features->push_back(tess_rank);
  // length of Tesseract OCR string
  features->push_back(tess_str.length());
  // Tesseract OCR string in dictionary
  features->push_back(ValidWord(tess_str));
  if (tess_bigram_cost_valid) {
    // bigram cost of Tesseract string
    features->push_back(tess_bigram_cost);
  }
  // Cube tess_cost of Cube best string
  features->push_back(cube_best_cost);
  // Cube tess_cost of Cube next best string
  features->push_back(cube_next_best_cost);
  // length of Cube string
  features->push_back(cube_best_str.length());
  // Cube string in dictionary
  features->push_back(ValidWord(cube_best_str));
  if (cube_best_bigram_cost_valid) {
    // bigram cost of Cube string
    features->push_back(cube_best_bigram_cost);
  }
  // case-insensitive string comparison, including punctuation
  int compare_nocase_punc = CompareStrings(cube_best_str.c_str(),
                                           tess_str.c_str(), false, true);
  features->push_back(compare_nocase_punc == 0);
  // case-sensitive string comparison, ignoring punctuation
  int compare_case_nopunc = CompareStrings(cube_best_str.c_str(),
                                           tess_str.c_str(), true, false);
  features->push_back(compare_case_nopunc == 0);
  // case-insensitive string comparison, ignoring punctuation
  int compare_nocase_nopunc = CompareStrings(cube_best_str.c_str(),
                                             tess_str.c_str(), true, true);
  features->push_back(compare_nocase_nopunc == 0);
  return true;
}
// ================================================================================
// FUNCTION		: CompareContact
// DESCRIPTION	: return true if two contacts equels.
// ================================================================================
bool CContactInfo::CompareContact(CContactInfo *pContact)
{
	if ( m_nContactId != pContact->m_nContactId )
		return false;

	if ( !CompareStrings(m_psFName, pContact->m_psFName) ) return false;
	
	if ( !CompareStrings(m_psLName, pContact->m_psLName) ) return false;

	if ( !CompareStrings(m_psCompany, pContact->m_psCompany) ) return false;

	if ( !CompareStrings(m_psJTitle, pContact->m_psJTitle) ) return false;

	if ( !CompareStrings(m_psFax, pContact->m_psFax) ) return false;

	if ( !CompareStrings(m_psFaxH, pContact->m_psFaxH) ) return false;

	if ( !CompareStrings(m_psFaxW, pContact->m_psFaxW) ) return false;

	if ( !CompareStrings(m_psMobile, pContact->m_psMobile) ) return false;

	if ( !CompareStrings(m_psMobileH, pContact->m_psMobileH) ) return false;

	if ( !CompareStrings(m_psMobileW, pContact->m_psMobileW) ) return false;

	if ( !CompareStrings(m_psTelephone, pContact->m_psTelephone) ) return false;

	if ( !CompareStrings(m_psTelephoneH, pContact->m_psTelephoneH) ) return false;

	if ( !CompareStrings(m_psTelephoneW, pContact->m_psTelephoneW) ) return false;

	if ( !CompareStrings(m_psEmail, pContact->m_psEmail) ) return false;

	if ( !CompareStrings(m_psEmailH, pContact->m_psEmailH) ) return false;

	if ( !CompareStrings(m_psEmailW, pContact->m_psEmailW) ) return false;

	return true;
}
    void ReplicaManagerWrapper::CheckState(
        wstring const & expectedActiveReplicas,
        wstring const & expectedPreviousActiveReplicas,
        wstring const & expectedIdleReplicas,
        bool expectedQuorumAchieved,
        FABRIC_SEQUENCE_NUMBER expectedCommittedLSN,
        FABRIC_SEQUENCE_NUMBER expectedCompletedLSN)
    {
        wstring activeReplicas;
        wstring previousActiveReplicas;
        wstring idleReplicas;
        FABRIC_SEQUENCE_NUMBER committedLSN;
        FABRIC_SEQUENCE_NUMBER completedLSN;
        bool quorumAchieved;

        for (int count = 1; ; count++)
        {
            bool replicationAckProcessingInProgress = false;
            quorumAchieved = replicaManagerSPtr_->Test_TryGetProgress(
                activeReplicas, 
                previousActiveReplicas, 
                idleReplicas,
                committedLSN, 
                completedLSN,
                replicationAckProcessingInProgress);
            
            if (!replicationAckProcessingInProgress)
            {
                bool reachedDesiredState = CompareStrings(activeReplicas, expectedActiveReplicas, false);
                reachedDesiredState &= CompareStrings(previousActiveReplicas, expectedPreviousActiveReplicas, false);
                reachedDesiredState &= CompareStrings(idleReplicas, expectedIdleReplicas, false);

                if (!reachedDesiredState)
                {
                    Sleep(100);
                }
                else if (count >= 100)
                {
                    break;
                }
            }
            else
            {
                Sleep(100);
            }
        }

        VERIFY_ARE_EQUAL_FMT(
            quorumAchieved,
            expectedQuorumAchieved,
            // wait for the ack to be completely processed
                "Expected quorum status = {0}, achieved = {1}", expectedQuorumAchieved, quorumAchieved);

        if (!expectedQuorumAchieved)
        {
            return;
        }

        VERIFY_ARE_EQUAL_FMT(
            expectedCommittedLSN, 
            committedLSN, 
            "Expected committedLSN {0} = committedLSN {1}", expectedCommittedLSN, committedLSN);

        VERIFY_ARE_EQUAL_FMT(
            expectedCompletedLSN, 
            completedLSN, 
            "Expected completedLSN {0} = completedLSN {1}", expectedCompletedLSN, completedLSN);
    }
Beispiel #26
0
int main(int argc, char *argv[ ]){
	ClearPrints();
	chdir(CombineStrings("/home/", GetUser()));
	DelFile(output_log);
	DebugLog("--- Begin Android Dev Tools ARGS");
	for(tick = 1; tick < argc; tick++) DebugLog(CombineStrings("ARG: ", argv[tick]));
	DebugLog("");
	DebugLog("--- Begin Android Dev Tools");
	CmdOut("aDev_adb devices > tmp.txt");
	if(IsFileEmpty("tmp.txt")){
		ClearPrints();
		PrintText("--- Proprietary Files Not Found! ---");
		PrintText("Run: \'aDev config\'");
		LineSkip();
		exit(-1);		
	}
	DelFile("tmp.txt");
	if(argc <= 1){
		PrintText("--- Invalid parameters! ---");
		PrintText("Run: \'aDev --help\'");
		LineSkip();
		exit(-1);
	}
	for(tick = 1; tick < argc; tick++){
		if(IsStringEmpty(argv[tick])) continue;
		if(CompareStrings(argv[tick], "--help") || CompareStrings(argv[tick], "-h")){
			PrintHelp();
			exit(0);
		}
		if(CompareStrings(argv[tick], "--version") || CompareStrings(argv[tick], "-v")){
			PrintVersion();
			exit(0);
		}
		else if(CompareStrings(argv[tick], "test")){
			PrintText("aDev was properly installed, enjoy!");
			LineSkip();
			exit(0);
		}
		else if(CompareStrings(argv[tick], "logcat")){
			DevLog(1);
			exit(0);
		}
		else if(CompareStrings(argv[tick], "dmesg")){
			DevLog(2);
			exit(0);
		}
		else if(CompareStrings(argv[tick], "kmsg")){
			DevLog(3);
			exit(0);
		}
		else if(CompareStrings(argv[tick], "screenshot")){
			ScreenShot();
			exit(0);
		}
		else if(CompareStrings(argv[tick], "info")){
			Info();
			exit(0);
		}
		else if(CompareStrings(argv[tick], "adb")){
			text = "aDev_adb ";
			for(tick2 = 1; tick2 < argc; tick2++) if(!CompareStrings(argv[tick2], "adb")) text = CombineStrings(text, CombineStrings(argv[tick2], " "));
			CmdOut(text);
			exit(0);
		}
		else if(CompareStrings(argv[tick], "fastboot")){
			text = "aDev_fastboot ";
			for(tick2 = 1; tick2 < argc; tick2++) if(!CompareStrings(argv[tick2], "fastboot")) text = CombineStrings(text, CombineStrings(argv[tick2], " "));
			CmdOut(text);
			exit(0);
		}
		else{
			for(tick2 = (argc - 1); tick2 < 0; tick2--){
				if(!IsValidArg(argv[tick2])) break;
				if(tick2 == 1) quit();
			}
			if(IsValidArg(argv[tick2])) tick2--;
			if(IsValidArg(argv[tick2])) quit();
			PrintText(CombineStrings("Unknown Parameter: ", argv[tick2]));
			quit();
		}
	}
	return 0;
}
Beispiel #27
0
int PAT_Acercar(char *cRuta)
{
	char cPatron[100]={0};
	char cInicio[20]={0};
	char cDestino[20]={0};
	char *c;
	int iControl=0;
	long iRotacional;
	long iLineal;
	
	//GetCtrlVal (panelHandle, PANEL_strDetalle, cPatron);
	//GetCtrlVal (panelHandle, PANEL_strCerca, cInicio);
	//Fmt(cPatron,"%s<%s",ENT_LeerDesplazamientoPrueba());		<-------------
	Fmt(cPatron,"%s<%s",cRuta);								//	<-------------
	
	ENT_ColocaMensaje("PAT_Acercar()");
	ENT_ColocaMensaje(GRA_Strcat(2,"cPatron -> ", cPatron));
	
	DelayWithEventProcessing(2.0);
		
	MOT_PosicionActual(&iRotacional, &iLineal);
	Fmt(cInicio,"%s<%s",PAT_PosicionCercaDe(600, miLista, iRotacional, iLineal));
	
	ENT_ColocaMensaje(GRA_Strcat(2,"cInicio -> ", cInicio));
	
	if (strlen(cPatron)>0)
	{
		char cLista[30][30]={0};
		int iTotal=0;
		
		UTL_Split(cPatron, "->", cLista, &iTotal);
		
		Fmt(cPatron,"%s<%s%s%s",cInicio,"->",cLista[0]);
		Fmt(cDestino,"%s<%s",cLista[0]);
		
		ENT_ColocaMensaje(GRA_Strcat(2,"El movimiento de acercamiento es de ", cPatron));
		
		//verifica que la palanca se encuentre en una poscion diferente al inicio
		if (CompareStrings(cInicio,0,cDestino,0,0) != 0)
		{
			UTL_Split(cPatron, "->", cLista, &iTotal);
		
			c=PAT_AnalizarMovimientoLista2(cLista);
			
			ENT_ColocaMensaje(GRA_Strcat(2,"c -> ", c));
			
		
			UTL_Split(c, "->", cLista, &iTotal);
		
		
			for (int i=0;i<iTotal;i++)
			{
				if (iControl==0)
				{
					//Busca la primer coincidencia
					if (CompareStrings(cLista[i],0,cInicio,0,0)==0)
					{
						Fmt(cPatron,"%s<%s",cInicio);
						strcat(cPatron,"->");
						iControl++;
					}
				}
				else
				{
					//espera hasta encontrar cDestino
					if (CompareStrings(cLista[i],0,cDestino,0,0)==0)
					{
						strcat(cPatron,cDestino);
						strcat(cPatron,"->");
						i=iTotal;
					
					}
					else
					{
						strcat(cPatron,cLista[i]);
						strcat(cPatron,"->");
					}
				}
		
			}
		
			//SetCtrlVal (panelHandle, PANEL_strRutaAcercar, cPatron);
		
			ENT_ColocaMensaje(GRA_Strcat(2,"Se va a ejecutar --> ", cPatron));
			ENT_LeeEsperaBoton();
			
			PAT_EjecucionPorPatron2(cPatron);
		}
	}
	
	return 0;
}