Ejemplo n.º 1
0
AST* ParseLoad(ParserState* parser) {
	Match(parser, TOKEN_LOAD);
	return CreateASTNode(SEM_LOAD, Match(parser, TOKEN_STRING));
}
Ejemplo n.º 2
0
void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent )
{
	CBNETProtocol :: IncomingChatEvent Event = chatEvent->GetChatEvent( );
	string User = chatEvent->GetUser( ), lowerUser = chatEvent->GetUser( ), Message = chatEvent->GetMessage( );
	transform( lowerUser.begin( ), lowerUser.end( ), lowerUser.begin( ), (int(*)(int))tolower );
	
	unsigned char Access = m_CCBot->m_DB->AccessCheck( m_Server, lowerUser );
	
	if( Access == 255 )
		Access = 0;
	
	bool Output = ( Event == CBNETProtocol :: CONSOLE_INPUT );			
	bool Whisper = ( Event == CBNETProtocol :: EID_WHISPER );
        bool ClanMember = IsClanMember( m_UserName );

	if( Event == CBNETProtocol :: EID_TALK )
			CONSOLE_Print( "[LOCAL: " + m_ServerAlias + ":" + m_CurrentChannel + "][" + User + "] " + Message );
	else if( Event == CBNETProtocol :: EID_WHISPER )
			CONSOLE_Print( "[WHISPER: " + m_ServerAlias + "][" + User + "] " + Message );
	else if( Event == CBNETProtocol :: EID_EMOTE )
			CONSOLE_Print( "[EMOTE: " + m_ServerAlias + ":" + m_CurrentChannel + "][" + User + "] " + Message );

	if( Event == CBNETProtocol :: EID_TALK || Event == CBNETProtocol :: EID_WHISPER  || Event == CBNETProtocol :: EID_EMOTE || Event == CBNETProtocol :: CONSOLE_INPUT )
	{
		// Anti-Spam
		// TODO: improve this to be more robust and efficient

		if( m_AntiSpam && !Message.empty( ) && Message[0] != m_CommandTrigger[0] && Access < 5 && IsInChannel( User ) && User != m_UserName )
		{
			string message = Message;
			transform( message.begin( ), message.end( ), message.begin( ), (int(*)(int))tolower );
			uint32_t SpamCacheSize = m_Channel.size( ) * 3;

			if( m_SpamCache.size( ) > SpamCacheSize )
				m_SpamCache.erase( m_SpamCache.begin( ) );

			m_SpamCache.insert( pair<string, string>( lowerUser, message ) );

			int mesgmatches = 0, nickmatches = 0;

			for( multimap<string, string> :: iterator i = m_SpamCache.begin( ); i != m_SpamCache.end( ); ++i )
			{
				if( (*i).first == lowerUser )
					++nickmatches;

				if( (*i).second.find( message ) )
					++mesgmatches;
			}

			if( mesgmatches > 2 || nickmatches > 3 )
				SendChatCommand( "/kick " + User + " Anti-Spam", Output );
		}

		// Swearing kick

		if ( m_SwearingKick && !Message.empty( ) && !Match( User, m_HostbotName ) && !m_CCBot->m_DB->SafelistCheck( m_Server, User ) && IsInChannel( User ) && Access < 5 ) 
		{
			string message = Message;
			transform( message.begin( ), message.end( ), message.begin( ), (int(*)(int))tolower );

			for( uint32_t i = 0; i < m_CCBot->m_SwearList.size( ); ++i )
			{
				if( message.find( m_CCBot->m_SwearList[i] ) != string :: npos )
					QueueChatCommand( m_CCBot->m_Language->SwearKick( User, m_CCBot->m_SwearList[i] ), Output );
			}
		}
		
		// ?TRIGGER
		
		if( Match( Message, "?trigger" ) )
		{
			QueueChatCommand( m_CCBot->m_Language->CommandTrigger( m_CommandTrigger ), User, Whisper, Output );	
		}		
		else if( !Message.empty( ) && Message[0] == m_CommandTrigger[0] && Event != CBNETProtocol :: EID_EMOTE )
		{
			// extract the command trigger, the command, and the payload
			// e.g. "!say hello world" -> command: "say", payload: "hello world"

			string Command, Payload;
			string :: size_type PayloadStart = Message.find( " " );

			if( PayloadStart != string :: npos )
			{
				Command = Message.substr( 1, PayloadStart - 1 );
				Payload = Message.substr( PayloadStart + 1 );
			}
			else
				Command = Message.substr( 1 );

			transform( Command.begin( ), Command.end( ), Command.begin( ), (int(*)(int))tolower );
			

			/********************************
			************ COMMANDS ***********
			********************************/

			//
			// !ACCEPT
			//

			if( Command == "accept" && Payload.empty( ) && Access >= m_CCBot->m_DB->CommandAccess( "accept" ) && m_ActiveInvitation )
			{
				m_Socket->PutBytes( m_Protocol->SEND_SID_CLANINVITATIONRESPONSE( m_Protocol->GetClanTag( ), m_Protocol->GetInviter( ), true ) );
				QueueChatCommand( m_CCBot->m_Language->InvitationAccepted( ), User, Whisper, Output );
				SendGetClanList( );
				m_ActiveInvitation = false;
			}

			//
			// !ACCESS
			//

			else if( Command == "access" && Payload.empty( ) && Access >= m_CCBot->m_DB->CommandAccess( "access" ) )
			{
				SendChatCommand( "/w " + User + " " + m_CCBot->m_Language->HasFollowingAccess( UTIL_ToString( Access ) ), Output );
				
				for( unsigned char n = 0; n <= Access; ++n )
				{
					string Commands;

					vector<string> m_CommandList = m_CCBot->m_DB->CommandList( n );

					for( vector<string> :: iterator i = m_CommandList.begin( ); i != m_CommandList.end( ); ++i )
						Commands = Commands + m_CommandTrigger + (*i) + ", ";

					Commands = Commands.substr( 0, Commands.size( ) -2 );

					if( m_CommandList.size ( ) )
						SendChatCommand( "/w " + User + " [" + UTIL_ToString( n ) + "]: " + Commands, Output );
					else
						break;
				}
			}

			//
			// !ADDSAFELIST
			// !ADDS
			//
				
			else if( ( Command == "addsafelist" || Command == "adds" ) && !Payload.empty( ) && Access >= m_CCBot->m_DB->CommandAccess( "addsafelist" ) )
			{					
				if( m_CCBot->m_DB->SafelistCheck( m_Server, Payload ) )
					QueueChatCommand( m_CCBot->m_Language->UserAlreadySafelisted( Payload ), User, Whisper, Output );
				else
				{
					if( m_CCBot->m_DB->SafelistAdd( m_Server, Payload ) )
						QueueChatCommand( m_CCBot->m_Language->UserSafelisted( Payload ), User, Whisper, Output );
					else
						QueueChatCommand( m_CCBot->m_Language->ErrorSafelisting( Payload ), User, Whisper, Output );
				}					
			}
				
			//
			// !ANNOUNCE
			//

			else if( Command == "announce" && !Payload.empty( ) && Access >= m_CCBot->m_DB->CommandAccess( "announce" ) )
			{					
				string Interval, AnnounceMessage;
				stringstream SS;
				SS << Payload;
				SS >> Interval;
				if( !SS.eof( ) )
				{
					getline( SS, AnnounceMessage );
					string :: size_type Start = AnnounceMessage.find_first_not_of( " " );

					if( Start != string :: npos )
						AnnounceMessage = AnnounceMessage.substr( Start );
				}

				if( ( UTIL_ToInt32( Interval ) > 0 ) && AnnounceMessage.size( ) )
				{
					m_Announce = true;
					m_AnnounceMsg = AnnounceMessage;
					m_AnnounceInterval = UTIL_ToInt32( Interval );

					if( m_AnnounceInterval < 3 )
						m_AnnounceInterval = 4;

					QueueChatCommand( m_CCBot->m_Language->AnnounceEnabled( Interval ), User, Whisper, Output );				
				}
				else if( Interval == "off" && m_Announce == true )
				{
					m_Announce = false;
					QueueChatCommand( m_CCBot->m_Language->AnnounceDisabled( ), User, Whisper, Output );
				}
			}

			//
			// !BAN
			// !ADDBAN
			//

			else if( ( Command == "ban" || Command == "addban" ) && !Payload.empty( ) && Access >= m_CCBot->m_DB->CommandAccess( "ban" ) )
Ejemplo n.º 3
0
/**

  Set the boot order based on configuration retrieved from QEMU.

  Attempt to retrieve the "bootorder" fw_cfg file from QEMU. Translate the
  OpenFirmware device paths therein to UEFI device path fragments. Match the
  translated fragments against BootOptionList, and rewrite the BootOrder NvVar
  so that it corresponds to the order described in fw_cfg.

  @param[in] BootOptionList  A boot option list, created with
                             BdsLibEnumerateAllBootOption ().


  @retval RETURN_SUCCESS            BootOrder NvVar rewritten.

  @retval RETURN_UNSUPPORTED        QEMU's fw_cfg is not supported.

  @retval RETURN_NOT_FOUND          Empty or nonexistent "bootorder" fw_cfg
                                    file, or no match found between the
                                    "bootorder" fw_cfg file and BootOptionList.

  @retval RETURN_INVALID_PARAMETER  Parse error in the "bootorder" fw_cfg file.

  @retval RETURN_OUT_OF_RESOURCES   Memory allocation failed.

  @return                           Values returned by gBS->LocateProtocol ()
                                    or gRT->SetVariable ().

**/
RETURN_STATUS
SetBootOrderFromQemu (
  IN  CONST LIST_ENTRY *BootOptionList
  )
{
  RETURN_STATUS                    Status;
  FIRMWARE_CONFIG_ITEM             FwCfgItem;
  UINTN                            FwCfgSize;
  CHAR8                            *FwCfg;
  CONST CHAR8                      *FwCfgPtr;

  BOOT_ORDER                       BootOrder;
  ACTIVE_OPTION                    *ActiveOption;
  UINTN                            ActiveCount;

  UINTN                            TranslatedSize;
  CHAR16                           Translated[TRANSLATION_OUTPUT_SIZE];

  Status = QemuFwCfgFindFile ("bootorder", &FwCfgItem, &FwCfgSize);
  if (Status != RETURN_SUCCESS) {
    return Status;
  }

  if (FwCfgSize == 0) {
    return RETURN_NOT_FOUND;
  }

  FwCfg = AllocatePool (FwCfgSize);
  if (FwCfg == NULL) {
    return RETURN_OUT_OF_RESOURCES;
  }

  QemuFwCfgSelectItem (FwCfgItem);
  QemuFwCfgReadBytes (FwCfgSize, FwCfg);
  if (FwCfg[FwCfgSize - 1] != '\0') {
    Status = RETURN_INVALID_PARAMETER;
    goto ErrorFreeFwCfg;
  }

  DEBUG ((DEBUG_VERBOSE, "%a: FwCfg:\n", __FUNCTION__));
  DEBUG ((DEBUG_VERBOSE, "%a\n", FwCfg));
  DEBUG ((DEBUG_VERBOSE, "%a: FwCfg: <end>\n", __FUNCTION__));
  FwCfgPtr = FwCfg;

  BootOrder.Produced  = 0;
  BootOrder.Allocated = 1;
  BootOrder.Data = AllocatePool (
                     BootOrder.Allocated * sizeof (*BootOrder.Data)
                     );
  if (BootOrder.Data == NULL) {
    Status = RETURN_OUT_OF_RESOURCES;
    goto ErrorFreeFwCfg;
  }

  Status = CollectActiveOptions (BootOptionList, &ActiveOption, &ActiveCount);
  if (RETURN_ERROR (Status)) {
    goto ErrorFreeBootOrder;
  }

  //
  // translate each OpenFirmware path
  //
  TranslatedSize = sizeof (Translated) / sizeof (Translated[0]);
  Status = TranslateOfwPath (&FwCfgPtr, Translated, &TranslatedSize);
  while (Status == RETURN_SUCCESS ||
         Status == RETURN_UNSUPPORTED ||
         Status == RETURN_BUFFER_TOO_SMALL) {
    if (Status == RETURN_SUCCESS) {
      UINTN Idx;

      //
      // match translated OpenFirmware path against all active boot options
      //
      for (Idx = 0; Idx < ActiveCount; ++Idx) {
        if (Match (
              Translated,
              TranslatedSize, // contains length, not size, in CHAR16's here
              ActiveOption[Idx].BootOption->DevicePath
              )
            ) {
          //
          // match found, store ID and continue with next OpenFirmware path
          //
          Status = BootOrderAppend (&BootOrder, &ActiveOption[Idx]);
          if (Status != RETURN_SUCCESS) {
            goto ErrorFreeActiveOption;
          }
          break;
        }
      } // scanned all active boot options
    }   // translation successful

    TranslatedSize = sizeof (Translated) / sizeof (Translated[0]);
    Status = TranslateOfwPath (&FwCfgPtr, Translated, &TranslatedSize);
  } // scanning of OpenFirmware paths done

  if (Status == RETURN_NOT_FOUND && BootOrder.Produced > 0) {
    //
    // No more OpenFirmware paths, some matches found: rewrite BootOrder NvVar.
    // Some of the active boot options that have not been selected over fw_cfg
    // should be preserved at the end of the boot order.
    //
    Status = BootOrderComplete (&BootOrder, ActiveOption, ActiveCount);
    if (RETURN_ERROR (Status)) {
      goto ErrorFreeActiveOption;
    }

    //
    // See Table 10 in the UEFI Spec 2.3.1 with Errata C for the required
    // attributes.
    //
    Status = gRT->SetVariable (
                    L"BootOrder",
                    &gEfiGlobalVariableGuid,
                    EFI_VARIABLE_NON_VOLATILE |
                      EFI_VARIABLE_BOOTSERVICE_ACCESS |
                      EFI_VARIABLE_RUNTIME_ACCESS,
                    BootOrder.Produced * sizeof (*BootOrder.Data),
                    BootOrder.Data
                    );
    if (EFI_ERROR (Status)) {
      DEBUG ((DEBUG_ERROR, "%a: setting BootOrder: %r\n", __FUNCTION__, Status));
      goto ErrorFreeActiveOption;
    }

    DEBUG ((DEBUG_INFO, "%a: setting BootOrder: success\n", __FUNCTION__));
    PruneBootVariables (ActiveOption, ActiveCount);
  }

ErrorFreeActiveOption:
  FreePool (ActiveOption);

ErrorFreeBootOrder:
  FreePool (BootOrder.Data);

ErrorFreeFwCfg:
  FreePool (FwCfg);

  return Status;
}
Ejemplo n.º 4
0
 bool Match(const std::string& s, match_flag_type flags = match_default) { return Match(s.c_str(), flags); }
Ejemplo n.º 5
0
/*
*   Search Text or Binary Data for Pattern matches
*/ 
int
acsmSearch (ACSM_STRUCT * acsm, unsigned char *Tx, int n,
#ifdef DETECTION_OPTION_TREE
            int (*Match)(void * id, void *tree, int index, void *data),
#else
            int (*Match) (void *  id, int index, void *data),
#endif
            void *data, int* current_state ) 
{

    unsigned char Tc[64*1024];
    int state = 0;
    ACSM_PATTERN * mlist;
    unsigned char *Tend;
    ACSM_STATETABLE * StateTable = acsm->acsmStateTable;
    int nfound = 0;
    unsigned char *T;
    int index;
    /* Case conversion */ 
    ConvertCaseEx (Tc, Tx, n);
    T = Tc;
    Tend = T + n;

    if ( !current_state )
    {
        return 0;
    }

    state = *current_state;

    for (; T < Tend; T++)
    {
        state = StateTable[state].NextState[*T];

        if( StateTable[state].MatchList != NULL )
        {
#ifdef DETECTION_OPTION_TREE
            mlist = StateTable[state].MatchList;
            index = T - mlist->n + 1 - Tc;
            nfound++;
            if (Match (mlist->id, mlist->rule_option_tree, index, data) > 0)
            {
                *current_state = state;
                return nfound;
            }
#else
            for( mlist=StateTable[state].MatchList; mlist!=NULL;
                 mlist=mlist->next )
            {
                index = T - mlist->n + 1 - Tc;
                if( mlist->nocase )
                {
                    nfound++;
                    if (Match (mlist->id, index, data) > 0)
                    {
                        *current_state = state;
                        return nfound;
                    }
                }
                else
                {
                    if( memcmp (mlist->casepatrn, Tx + index, mlist->n) == 0 )
                    {
                        nfound++;
                        if (Match (mlist->id, index, data) > 0)
                        {
                            *current_state = state;
                            return nfound;
                        }
                    }
                }
            }
#endif
        }
    }
    *current_state = state;
    return nfound;
}
Ejemplo n.º 6
0
// static
bool Cddb::Query(Matches& res, const Toc& toc)
{
    if (toc.size() < 2)
        return false;
    const unsigned totalTracks = toc.size() - 1;

    unsigned secs = 0;
    const discid_t discID = Discid(secs, toc.data(), totalTracks);

    // Is it cached?
    if (Dbase::Search(res, discID))
        return res.matches.size() > 0;

    // Construct query
    // cddb query discid ntrks off1 off2 ... nsecs
    QString URL2 = URL + QString("cddb+query+%1+%2+").arg(discID,0,16).arg(totalTracks);

    for (unsigned t = 0; t < totalTracks; ++t)
        URL2 += QString("%1+").arg(msf2lsn(toc[t]));

    URL2 += QString::number(secs);

    // Send the request
    URL2 += "&hello=" + helloID() + "&proto=5";
    LOG(VB_MEDIA, LOG_INFO, "CDDB lookup: " + URL2);

    QString cddb;
    QByteArray data;
    if (!GetMythDownloadManager()->download(URL2, &data))
        return false;
    cddb = data;

    // Check returned status
    const uint stat = cddb.left(3).toUInt(); // Extract 3 digit status:
    cddb = cddb.mid(4);
    switch (stat)
    {
    case 200: // Unique match
        LOG(VB_MEDIA, LOG_INFO, "CDDB match: " + cddb.trimmed());
        // e.g. "200 rock 960b5e0c Nichole Nordeman / Woven & Spun"
        res.discID = discID;
        res.isExact = true;
        res.matches.push_back(Match(
            cddb.section(' ', 0, 0), // genre
            cddb.section(' ', 1, 1).toUInt(nullptr,16), // discID
            cddb.section(' ', 2).section(" / ", 0, 0), // artist
            cddb.section(' ', 2).section(" / ", 1) // title
        ));
        break;

    case 202: // No match for disc ID...
        LOG(VB_MEDIA, LOG_INFO, "CDDB no match");
        Dbase::New(discID, toc); // Stop future lookups
        return false;

    case 210:  // Multiple exact matches
    case 211:  // Multiple inexact matches
        // 210 Found exact matches, list follows (until terminating `.')
        // 211 Found inexact matches, list follows (until terminating `.')
        res.discID = discID;
        res.isExact = 210 == stat;

        // Remove status line
        cddb = cddb.section('\n', 1);

        // Append all matches
        while (!cddb.isEmpty() && !cddb.startsWith("."))
        {
            LOG(VB_MEDIA, LOG_INFO, QString("CDDB %1 match: %2").
                arg(210 == stat ? "exact" : "inexact").
                arg(cddb.section('\n',0,0)));
            res.matches.push_back(Match(
                cddb.section(' ', 0, 0), // genre
                cddb.section(' ', 1, 1).toUInt(nullptr,16), // discID
                cddb.section(' ', 2).section(" / ", 0, 0), // artist
                cddb.section(' ', 2).section(" / ", 1) // title
            ));
            cddb = cddb.section('\n', 1);
        }
        if (res.matches.size() <= 0)
            Dbase::New(discID, toc); // Stop future lookups
        break;

    default:
        // TODO try a (telnet 8880) CDDB lookup
        LOG(VB_GENERAL, LOG_INFO, QString("CDDB query error: %1").arg(stat) +
            cddb.trimmed());
        return false;
    }
    return true;
}
Ejemplo n.º 7
0
void MatchEditor::Init () {
    SetClassName("MatchEditor");
    Match("%[]", true);
}
 // Use Traverse, not Visit, to check that data recursion optimization isn't
 // bypassing the call of this function.
 bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *CE) {
   Match(getOperatorSpelling(CE->getOperator()), CE->getExprLoc());
   return ExpectedLocationVisitor<CXXOperatorCallExprTraverser>::
       TraverseCXXOperatorCallExpr(CE);
 }
 bool VisitParenExpr(ParenExpr *Parens) {
   Match("", Parens->getExprLoc());
   return true;
 }
 bool VisitVarDecl(VarDecl *Variable) {
   Match(Variable->getNameAsString(), Variable->getLocStart());
   return true;
 }
 bool VisitCXXMemberCallExpr(CXXMemberCallExpr *Call) {
   Match(Call->getMethodDecl()->getQualifiedNameAsString(),
         Call->getLocStart());
   return true;
 }
 bool VisitDeclRefExpr(DeclRefExpr *Reference) {
   Match(Reference->getNameInfo().getAsString(), Reference->getLocation());
   return true;
 }
 bool VisitTypeLoc(TypeLoc TypeLocation) {
   Match(TypeLocation.getType().getAsString(), TypeLocation.getBeginLoc());
   return true;
 }
Ejemplo n.º 14
0
Match Match::flip() const {
  return Match(second, first);
}
Ejemplo n.º 15
0
void Constants(){
    Match('c');
}
Ejemplo n.º 16
0
  AdminRegionVisitor::Action LocationService::AdminRegionMatchVisitor::Visit(const AdminRegion& region)
  {
    bool atLeastOneAliasMatch=false;

    bool regionMatch;
    bool regionCandidate;

    Match(region.name,
          regionMatch,
          regionCandidate);

    if (!regionMatch) {
      for (const auto& alias : region.aliases) {
        bool match;
        bool candidate;

        Match(alias.name,
              match,
              candidate);

        if (match || candidate) {
          AdminRegionResult result;

          result.adminRegion=std::make_shared<AdminRegion>(region);
          result.isMatch=match;

          result.adminRegion->aliasName=alias.name;
          result.adminRegion->aliasObject.Set(alias.objectOffset,refNode);

          //std::cout << pattern << " => (alias) " << result.adminRegion->aliasName << " " << match << " " << regionCandidate << " " << std::endl;

          results.push_back(result);

          if (match) {
            atLeastOneAliasMatch=true;
          }

          limitReached=results.size()>=limit;
        }
      }
    }

    // If we have a perfect match for an alias, we not not try to regionMatch
    // the region name itself
    if (!atLeastOneAliasMatch) {
      if (regionMatch || regionCandidate) {
        AdminRegionResult result;

        result.adminRegion=std::make_shared<AdminRegion>(region);
        result.isMatch=regionMatch;

        //std::cout << pattern << " => (region) " << result.adminRegion->name << " " << regionMatch << " " << regionCandidate << std::endl;

        results.push_back(result);
      }
    }

    if (limitReached) {
      return stop;
    }
    else {
      return visitChildren;
    }
  }
Ejemplo n.º 17
0
void Types(){
    Match('t');
}
Ejemplo n.º 18
0
void GetProperty (){
        Match('"');
        while ( Look!='"' )
                GetChar();
        Match('"');
}
Ejemplo n.º 19
0
void DocumentCatalog::queryChanged()
{
	int newStatus = 0;
	if(query() == "")
	{
		// reset query
		dir = QDir::home();
		currentPath = "";
		queryMatched = 0;
		refreshFolders();
	} else {
		if(query().length() >= minQueryLen())
		{
			QString path = query().lower().remove(0, queryMatched);
			
			int index;
			while((index = path.find('/')) != -1) {
				QString folderQuery = path.left(index);
				QString guess = QString::null;
				
				for(QStringList::Iterator it = folders.begin(); it != folders.end(); ++it) {
					QString folderName = *it;
					if(folderName.lower().startsWith(folderQuery) && (guess.isNull() || folderName.length() < guess.length()))
						guess = folderName;
				}
				
				if(guess == QString::null) {
					path = QString::null;
					break;
				}
				
				if(!dir.cd(guess)) {
					path = QString::null;
					break;
				}
				refreshFolders();
				
				queryMatched += folderQuery.length() + 1;
				currentPath += guess + "/";
				path = path.remove(0, index+1);
			}
			
			Match newBestMatch;
			
			if(path.isNull()) {
				files.clear();
			} else {
				if(!filesListed) {
					refreshFiles();
				}
				if(!path.isEmpty()) {
					if(currentDirDoc != 0) {
						files.removeRef(currentDirDoc);
						currentDirDoc = 0;
					}
					QPtrListIterator<Document> it(files);
					Document *document;
					while((document = it.current()) != 0) {
						++it;
						if(document->name().lower().startsWith(path)) {
							int rank = 100*query().length()/document->text().length();
							if(newBestMatch.isNull() || rank > newBestMatch.rank())
								newBestMatch = Match(document, rank, currentPath.length() + path.length());
						} else {
							files.removeRef(document);
						}
					}
				}
			}
			
			if(currentDirDoc != 0 && path.isEmpty())
				newBestMatch = Match(currentDirDoc, 100, currentPath.length());

			newStatus |= S_Active;
			if(files.count() > 0)
			{
				newStatus |= S_HasResults;
				if(files.count() > 1 || files.at(0)->className() == "Directory")
					newStatus |= S_Multiple;
			} else
				newStatus |= S_NoResults;
				
 			setBestMatch(newBestMatch);
		} else {
			setBestMatch(Match());
		}
	}
	setStatus(newStatus);
}
Ejemplo n.º 20
0
void Variables(){
    Match('v');
}
Ejemplo n.º 21
0
BOOL GBlend::BlendMtoN()
{
    UINT32 t ;
    while ( IsntEnd(Type0) || IsntEnd(Type1) )
    {
        if ( LPtr1==EndLengthPtr1-1 )
            MatchLast( LPtr0, EndLengthPtr0, *LPtr1+Length1-Length0, Match0, Total0 ) ;
        else
            Match    ( LPtr0, EndLengthPtr0, *LPtr1+Length1-Length0, Match0, Total0 ) ;
        if ( LPtr0==EndLengthPtr0-1 )
            MatchLast( LPtr1, EndLengthPtr1, *LPtr0+Length0-Length1, Match1, Total1 ) ;
        else
            Match    ( LPtr1, EndLengthPtr1, *LPtr0+Length0-Length1, Match1, Total1 ) ;
        if ( abs(Match0)<abs(Match1) )
        {
            if ( Total0!=1 )
            {
                Match0 += *LPtr1+Length1-Length0 ;
                if ( IsntCurve(Type1) )
                {
                    P11.x = (2*P10.x+P13.x)/3 ;
                    P12.x = (P10.x+2*P13.x)/3 ;
                    P11.y = (2*P10.y+P13.y)/3 ;
                    P12.y = (P10.y+2*P13.y)/3 ;
                }
                for ( t=2 ; t<=Total0 ; t++ )
                {
                    if ( IsCurve(Type0) || IsCurve(Type1) )
                    {
                        if ( IsntCurve(Type0) )
                        {
                            P01.x = (2*P00.x+P03.x)/3 ;
                            P02.x = (P00.x+2*P03.x)/3 ;
                            P01.y = (2*P00.y+P03.y)/3 ;
                            P02.y = (P00.y+2*P03.y)/3 ;
                        }
                        Split( P10,P11,P12,P13, *LPtr0,Match0 ) ;
                        if ( !BlendCurve( P01,P02,P03, L1,L2,M ) )
                            return FALSE ;
                        P10 = M ;
                        P11 = R1 ;
                        P12 = R2 ;
                    }
                    else
                    {
                        P10.x += MulDiv(P13.x-P10.x,*LPtr0,Match0) ;
                        P10.y += MulDiv(P13.y-P10.y,*LPtr0,Match0) ;
                        if ( !BlendPoint( PT_LINETO, P03, P10 ) )
                            return FALSE ;
                    }
                    P00 = P03 ;
                    Match0 -= *LPtr0 ;
                    ReadPath0() ;
                }
            }
        }
        else
        {
            if ( Total1!=1 )
            {
                Match1 += *LPtr0+Length0-Length1 ;
                if ( IsntCurve(Type0) )
                {
                    P01.x = (2*P00.x+P03.x)/3 ;
                    P02.x = (P00.x+2*P03.x)/3 ;
                    P01.y = (2*P00.y+P03.y)/3 ;
                    P02.y = (P00.y+2*P03.y)/3 ;
                }
                for ( t=2 ; t<=Total1 ; t++ )
                {
                    if ( IsCurve(Type0) || IsCurve(Type1) )
                    {
                        if ( IsntCurve(Type1) )
                        {
                            P11.x = (2*P10.x+P13.x)/3 ;
                            P12.x = (P10.x+2*P13.x)/3 ;
                            P11.y = (2*P10.y+P13.y)/3 ;
                            P12.y = (P10.y+2*P13.y)/3 ;
                        }
                        Split( P00,P01,P02,P03, *LPtr1,Match1 ) ;
                        if ( !BlendCurve( L1,L2,M, P11,P12,P13 ) )
                            return FALSE ;
                        P00 = M ;
                        P01 = R1 ;
                        P02 = R2 ;
                    }
                    else
                    {
                        P00.x += MulDiv(P03.x-P00.x,*LPtr1,Match1) ;
                        P00.y += MulDiv(P03.y-P00.y,*LPtr1,Match1) ;
                        if ( !BlendPoint( PT_LINETO, P00, P13 ) )
                            return FALSE ;
                    }
                    P10 = P13 ;
                    Match1 -= *LPtr1 ;
                    ReadPath1()	;
                }
            }
        }
        if ( !Blend1to1() )
            return FALSE ;
    } /* while */
    return TRUE ;
}
Ejemplo n.º 22
0
void DoProcedure(){
    Match('p');
}
Ejemplo n.º 23
0
 bool Match(const std::string& s, unsigned int flags = match_default) { return Match(s.c_str(), flags); }
Ejemplo n.º 24
0
void DoFunction(){
    Match('f');
}
Ejemplo n.º 25
0
TEST(TypeManager, LookupType) {
  const std::string text = R"(
%void = OpTypeVoid
%uint = OpTypeInt 32 0
%int  = OpTypeInt 32 1
%vec2 = OpTypeVector %int 2
)";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  EXPECT_NE(context, nullptr);
  TypeManager manager(nullptr, context.get());

  Void voidTy;
  EXPECT_EQ(manager.GetId(&voidTy), 1u);

  Integer uintTy(32, false);
  EXPECT_EQ(manager.GetId(&uintTy), 2u);

  Integer intTy(32, true);
  EXPECT_EQ(manager.GetId(&intTy), 3u);

  Integer intTy2(32, true);
  Vector vecTy(&intTy2, 2u);
  EXPECT_EQ(manager.GetId(&vecTy), 4u);
}

TEST(TypeManager, RemoveId) {
  const std::string text = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
%2 = OpTypeInt 32 1
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  context->get_type_mgr()->RemoveId(1u);
  ASSERT_EQ(context->get_type_mgr()->GetType(1u), nullptr);
  ASSERT_NE(context->get_type_mgr()->GetType(2u), nullptr);

  context->get_type_mgr()->RemoveId(2u);
  ASSERT_EQ(context->get_type_mgr()->GetType(1u), nullptr);
  ASSERT_EQ(context->get_type_mgr()->GetType(2u), nullptr);
}

TEST(TypeManager, RemoveIdNonDuplicateAmbiguousType) {
  const std::string text = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
%2 = OpTypeStruct %1
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  Integer u32(32, false);
  Struct st({&u32});
  ASSERT_EQ(context->get_type_mgr()->GetId(&st), 2u);
  context->get_type_mgr()->RemoveId(2u);
  ASSERT_EQ(context->get_type_mgr()->GetType(2u), nullptr);
  ASSERT_EQ(context->get_type_mgr()->GetId(&st), 0u);
}

TEST(TypeManager, RemoveIdDuplicateAmbiguousType) {
  const std::string text = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
%2 = OpTypeStruct %1
%3 = OpTypeStruct %1
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  Integer u32(32, false);
  Struct st({&u32});
  uint32_t id = context->get_type_mgr()->GetId(&st);
  ASSERT_NE(id, 0u);
  uint32_t toRemove = id == 2u ? 2u : 3u;
  uint32_t toStay = id == 2u ? 3u : 2u;
  context->get_type_mgr()->RemoveId(toRemove);
  ASSERT_EQ(context->get_type_mgr()->GetType(toRemove), nullptr);
  ASSERT_EQ(context->get_type_mgr()->GetId(&st), toStay);
}

TEST(TypeManager, RemoveIdDoesntUnmapOtherTypes) {
  const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
%2 = OpTypeStruct %1
%3 = OpTypeStruct %1
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  Integer u32(32, false);
  Struct st({&u32});

  EXPECT_EQ(1u, context->get_type_mgr()->GetId(&u32));
  uint32_t id = context->get_type_mgr()->GetId(&st);
  ASSERT_NE(id, 0u);
  uint32_t toRemove = id == 2u ? 3u : 2u;
  uint32_t toStay = id == 2u ? 2u : 3u;
  context->get_type_mgr()->RemoveId(toRemove);
  ASSERT_EQ(context->get_type_mgr()->GetType(toRemove), nullptr);
  ASSERT_EQ(context->get_type_mgr()->GetId(&st), toStay);
}

TEST(TypeManager, GetTypeAndPointerType) {
  const std::string text = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
%2 = OpTypeStruct %1
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  Integer u32(32, false);
  Pointer u32Ptr(&u32, SpvStorageClassFunction);
  Struct st({&u32});
  Pointer stPtr(&st, SpvStorageClassInput);

  auto pair = context->get_type_mgr()->GetTypeAndPointerType(
      3u, SpvStorageClassFunction);
  ASSERT_EQ(nullptr, pair.first);
  ASSERT_EQ(nullptr, pair.second);

  pair = context->get_type_mgr()->GetTypeAndPointerType(
      1u, SpvStorageClassFunction);
  ASSERT_TRUE(pair.first->IsSame(&u32));
  ASSERT_TRUE(pair.second->IsSame(&u32Ptr));

  pair =
      context->get_type_mgr()->GetTypeAndPointerType(2u, SpvStorageClassInput);
  ASSERT_TRUE(pair.first->IsSame(&st));
  ASSERT_TRUE(pair.second->IsSame(&stPtr));
}

TEST(TypeManager, DuplicateType) {
  const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
%2 = OpTypeInt 32 0
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  const Type* type1 = context->get_type_mgr()->GetType(1u);
  const Type* type2 = context->get_type_mgr()->GetType(2u);
  EXPECT_NE(type1, nullptr);
  EXPECT_NE(type2, nullptr);
  EXPECT_EQ(*type1, *type2);
}

TEST(TypeManager, MultipleStructs) {
  const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpDecorate %3 Constant
%1 = OpTypeInt 32 0
%2 = OpTypeStruct %1
%3 = OpTypeStruct %1
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  const Type* type1 = context->get_type_mgr()->GetType(2u);
  const Type* type2 = context->get_type_mgr()->GetType(3u);
  EXPECT_NE(type1, nullptr);
  EXPECT_NE(type2, nullptr);
  EXPECT_FALSE(type1->IsSame(type2));
}

TEST(TypeManager, RemovingIdAvoidsUseAfterFree) {
  const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
%2 = OpTypeStruct %1
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  Integer u32(32, false);
  Struct st({&u32});
  const Type* type = context->get_type_mgr()->GetType(2u);
  EXPECT_NE(type, nullptr);
  context->get_type_mgr()->RemoveId(1u);
  EXPECT_TRUE(type->IsSame(&st));
}

TEST(TypeManager, RegisterAndRemoveId) {
  const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
)";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  uint32_t id = 2u;
  {
    // Ensure that u32 goes out of scope.
    Integer u32(32, false);
    Struct st({&u32});
    context->get_type_mgr()->RegisterType(id, st);
  }

  context->get_type_mgr()->RemoveId(id);
  EXPECT_EQ(nullptr, context->get_type_mgr()->GetType(id));
}

TEST(TypeManager, RegisterAndRemoveIdAllTypes) {
  const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
)";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  std::vector<std::unique_ptr<Type>> types = GenerateAllTypes();
  uint32_t id = 1u;
  for (auto& t : types) {
    context->get_type_mgr()->RegisterType(id, *t);
    EXPECT_EQ(*t, *context->get_type_mgr()->GetType(id));
  }
  types.clear();

  for (; id > 0; --id) {
    context->get_type_mgr()->RemoveId(id);
    EXPECT_EQ(nullptr, context->get_type_mgr()->GetType(id));
  }
}

TEST(TypeManager, RegisterAndRemoveIdWithDecorations) {
  const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
%1 = OpTypeInt 32 0
)";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  uint32_t id = 2u;
  {
    Integer u32(32, false);
    Struct st({&u32, &u32});
    st.AddDecoration({10});
    st.AddDecoration({11});
    st.AddMemberDecoration(0, {{35, 4}});
    st.AddMemberDecoration(1, {{35, 4}});
    st.AddMemberDecoration(1, {{36, 5}});
    context->get_type_mgr()->RegisterType(id, st);
    EXPECT_EQ(st, *context->get_type_mgr()->GetType(id));
  }

  context->get_type_mgr()->RemoveId(id);
  EXPECT_EQ(nullptr, context->get_type_mgr()->GetType(id));
}

#ifdef SPIRV_EFFCEE
TEST(TypeManager, GetTypeInstructionInt) {
  const std::string text = R"(
; CHECK: OpTypeInt 32 0
; CHECK: OpTypeInt 16 1
OpCapability Shader
OpCapability Int16
OpCapability Linkage
OpMemoryModel Logical GLSL450
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  EXPECT_NE(context, nullptr);

  Integer uint_32(32, false);
  context->get_type_mgr()->GetTypeInstruction(&uint_32);

  Integer int_16(16, true);
  context->get_type_mgr()->GetTypeInstruction(&int_16);

  Match(text, context.get());
}

TEST(TypeManager, GetTypeInstructionDuplicateInts) {
  const std::string text = R"(
; CHECK: OpTypeInt 32 0
; CHECK-NOT: OpType
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  EXPECT_NE(context, nullptr);

  Integer uint_32(32, false);
  uint32_t id = context->get_type_mgr()->GetTypeInstruction(&uint_32);

  Integer other(32, false);
  EXPECT_EQ(context->get_type_mgr()->GetTypeInstruction(&other), id);

  Match(text, context.get());
}

TEST(TypeManager, GetTypeInstructionAllTypes) {
  const std::string text = R"(
; CHECK: [[uint:%\w+]] = OpTypeInt 32 0
; CHECK: [[input_ptr:%\w+]] = OpTypePointer Input [[uint]]
; CHECK: [[uniform_ptr:%\w+]] = OpTypePointer Uniform [[uint]]
; CHECK: [[uint24:%\w+]] = OpConstant [[uint]] 24
; CHECK: [[uint42:%\w+]] = OpConstant [[uint]] 42
; CHECK: [[uint100:%\w+]] = OpConstant [[uint]] 100
; CHECK: [[void:%\w+]] = OpTypeVoid
; CHECK: [[bool:%\w+]] = OpTypeBool
; CHECK: [[s32:%\w+]] = OpTypeInt 32 1
; CHECK: OpTypeInt 64 1
; CHECK: [[u64:%\w+]] = OpTypeInt 64 0
; CHECK: [[f32:%\w+]] = OpTypeFloat 32
; CHECK: OpTypeFloat 64
; CHECK: OpTypeVector [[s32]] 2
; CHECK: [[v3s32:%\w+]] = OpTypeVector [[s32]] 3
; CHECK: OpTypeVector [[u64]] 4
; CHECK: [[v3f32:%\w+]] = OpTypeVector [[f32]] 3
; CHECK: OpTypeMatrix [[v3s32]] 3
; CHECK: OpTypeMatrix [[v3s32]] 4
; CHECK: OpTypeMatrix [[v3f32]] 4
; CHECK: [[image1:%\w+]] = OpTypeImage [[s32]] 2D 0 0 0 0 Rg8 ReadOnly
; CHECK: OpTypeImage [[s32]] 2D 0 1 0 0 Rg8 ReadOnly
; CHECK: OpTypeImage [[s32]] 3D 0 1 0 0 Rg8 ReadOnly
; CHECK: [[image2:%\w+]] = OpTypeImage [[void]] 3D 0 1 0 1 Rg8 ReadWrite
; CHECK: OpTypeSampler
; CHECK: OpTypeSampledImage [[image1]]
; CHECK: OpTypeSampledImage [[image2]]
; CHECK: OpTypeArray [[f32]] [[uint100]]
; CHECK: [[a42f32:%\w+]] = OpTypeArray [[f32]] [[uint42]]
; CHECK: OpTypeArray [[u64]] [[uint24]]
; CHECK: OpTypeRuntimeArray [[v3f32]]
; CHECK: [[rav3s32:%\w+]] = OpTypeRuntimeArray [[v3s32]]
; CHECK: OpTypeStruct [[s32]]
; CHECK: [[sts32f32:%\w+]] = OpTypeStruct [[s32]] [[f32]]
; CHECK: OpTypeStruct [[u64]] [[a42f32]] [[rav3s32]]
; CHECK: OpTypeOpaque ""
; CHECK: OpTypeOpaque "hello"
; CHECK: OpTypeOpaque "world"
; CHECK: OpTypePointer Input [[f32]]
; CHECK: OpTypePointer Function [[sts32f32]]
; CHECK: OpTypePointer Function [[a42f32]]
; CHECK: OpTypeFunction [[void]]
; CHECK: OpTypeFunction [[void]] [[bool]]
; CHECK: OpTypeFunction [[void]] [[bool]] [[s32]]
; CHECK: OpTypeFunction [[s32]] [[bool]] [[s32]]
; CHECK: OpTypeEvent
; CHECK: OpTypeDeviceEvent
; CHECK: OpTypeReserveId
; CHECK: OpTypeQueue
; CHECK: OpTypePipe ReadWrite
; CHECK: OpTypePipe ReadOnly
; CHECK: OpTypeForwardPointer [[input_ptr]] Input
; CHECK: OpTypeForwardPointer [[uniform_ptr]] Input
; CHECK: OpTypeForwardPointer [[uniform_ptr]] Uniform
; CHECK: OpTypePipeStorage
; CHECK: OpTypeNamedBarrier
OpCapability Shader
OpCapability Int64
OpCapability Linkage
OpMemoryModel Logical GLSL450
%uint = OpTypeInt 32 0
%1 = OpTypePointer Input %uint
%2 = OpTypePointer Uniform %uint
%24 = OpConstant %uint 24
%42 = OpConstant %uint 42
%100 = OpConstant %uint 100
  )";

  std::unique_ptr<IRContext> context =
      BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text,
                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  EXPECT_NE(context, nullptr);

  std::vector<std::unique_ptr<Type>> types = GenerateAllTypes();
  for (auto& t : types) {
    context->get_type_mgr()->GetTypeInstruction(t.get());
  }

  Match(text, context.get(), false);
}
Ejemplo n.º 26
0
void Statements(){
    Match('b');
    while(Look != 'e')
        GetChar();
    Match('e');
}
Ejemplo n.º 27
0
bool CLogDlgFilter::operator() (const CLogEntryData& entry) const
{
    // quick checks

    if (entry.GetRevision() == revToKeep)
        return true;

    __time64_t date = entry.GetDate();
    if (attributeSelector & LOGFILTER_DATERANGE)
    {
        if ((date < from) || (date > to))
            return false;
    }

    if (patterns.empty() && subStringConditions.empty())
        return !negate;

    if (hideNonMergeable && mergedrevs && !mergedrevs->empty())
    {
        if (mergedrevs->find(entry.GetRevision()) != mergedrevs->end())
            return false;
        if (entry.GetRevision() < minrev)
            return false;
    }
    // we need to perform expensive string / pattern matching

    scratch.Clear();
    if (attributeSelector & LOGFILTER_BUGID)
        AppendString (scratch, entry.GetBugIDs());

    if (attributeSelector & LOGFILTER_MESSAGES)
        AppendString (scratch, entry.GetMessage());

    if (attributeSelector & LOGFILTER_PATHS)
    {
        const CLogChangedPathArray& paths = entry.GetChangedPaths();
        for ( size_t cpPathIndex = 0, pathCount = paths.GetCount()
            ; cpPathIndex < pathCount
            ; ++cpPathIndex)
        {
            const CLogChangedPath& cpath = paths[cpPathIndex];
            if (!scanRelevantPathsOnly || cpath.IsRelevantForStartPath())
            {
                GetPath (cpath.GetCachedPath(), scratch);
                scratch.Append ('|');
                scratch.Append (cpath.GetActionString());

                if (cpath.GetCopyFromRev() > 0)
                {
                    GetPath (cpath.GetCachedCopyFromPath(), scratch);

                    scratch.Append ('|');

                    char buffer[10];
                    _itoa_s (cpath.GetCopyFromRev(), buffer, 10);
                    scratch.Append (buffer);
                }
            }
        }
    }

    if (attributeSelector & LOGFILTER_AUTHORS)
        AppendString (scratch, entry.GetAuthor());
    if (attributeSelector & LOGFILTER_DATE)
        AppendString (scratch, entry.GetDateString());

    if (attributeSelector & LOGFILTER_REVS)
    {
        scratch.Append (' ');

        char buffer[10];
        _itoa_s (entry.GetRevision(), buffer, 10);
        scratch.Append (buffer);
    }

    return Match (scratch, scratch.GetSize()) ^ negate;
}
Ejemplo n.º 28
0
void Labels(){
    Match('l');
}
Ejemplo n.º 29
0
float scoreCandidate(vector<Segment> targetSegmentation, vector<Segment> candidateSegmentation)
{

	map<Segment*, Match> bestMatchByTarget;
	float totalTargetArea = 0.0;
	for(int targetSegmentIndex = 0; targetSegmentIndex < targetSegmentation.size(); targetSegmentIndex++)
	{
		Segment* targetSegment = & targetSegmentation[targetSegmentIndex];
		cerr << "target segment " << targetSegment << " area " << area(targetSegment->polygon) << endl;
		totalTargetArea += area(targetSegment->polygon);
	}

	// assign each candidate segment to the target segment it most intersects with
	// pair each target segment with the best candidate segment match (most intersects)
	for(int candidateSegmentIndex = 0; candidateSegmentIndex < candidateSegmentation.size(); candidateSegmentIndex++)
	{
		Segment* candidateSegment = & candidateSegmentation[candidateSegmentIndex];
		Segment* bestMatchTargetSegment = NULL;
		float bestTargetScore = -1;
		
		for(int targetSegmentIndex = 0; targetSegmentIndex < targetSegmentation.size(); targetSegmentIndex++)
		{
			Segment* targetSegment = & targetSegmentation[targetSegmentIndex];
			float pairOverlap = candidateSegment->areaOfIntersectionWith(*targetSegment);
			//cerr << "area(intersect(" << area(targetSegment->polygon) << ", " << area(candidateSegment->polygon) << ")) = " << pairOverlap << endl;

			if(pairOverlap > bestTargetScore)
			{
				bestTargetScore = pairOverlap;
				bestMatchTargetSegment = targetSegment;
			}
		}
		if(bestMatchTargetSegment != NULL)
		{
			if(!contains(bestMatchByTarget, bestMatchTargetSegment))
				bestMatchByTarget[bestMatchTargetSegment] = Match(candidateSegment, bestTargetScore);
			else if(bestTargetScore > bestMatchByTarget[bestMatchTargetSegment].intersectionArea)
				bestMatchByTarget[bestMatchTargetSegment] = Match(candidateSegment, bestTargetScore);
		}
	}

	// sum intersection areas of all pairs
	float totalMatchArea = 0.0;
	float sumOfColorScoresWeightedByIntersectionArea = 0.0;
	for(map<Segment*, Match>::iterator match = bestMatchByTarget.begin(); match != bestMatchByTarget.end(); match++)
	{
		Segment* targetSegment    = (*match).first;
		Segment* candidateSegment = (*match).second.segment;
		float matchArea = (*match).second.intersectionArea;

		totalMatchArea += matchArea;
		cerr << "match (target - area, candidate - area) = (" << targetSegment << " - " << area(targetSegment->polygon) << ", " << candidateSegment << " - " << area(candidateSegment->polygon) << ") score: " << (*match).second.intersectionArea << endl;

		float colorScore = 1.0 - Color::distance(targetSegment->color, candidateSegment->color) / sqrtf((255*255) + (255*255) + (255*255));
		sumOfColorScoresWeightedByIntersectionArea += matchArea * colorScore;
	}

	// divide total intersection area by total target polygon area
	cerr << "totalMatchArea: " << totalMatchArea << " totalTargetArea: " << totalTargetArea << endl;
	float areaScore = totalMatchArea / totalTargetArea;

	// divide weighted color match sum by total intersection area
	float colorScore = sumOfColorScoresWeightedByIntersectionArea / totalMatchArea;
	cerr << "colorScore: " << colorScore << endl;

	float match = areaScore * colorScore;
	cerr << "MATCH: " << match << endl;

	return match;
}
Ejemplo n.º 30
0
AST* ParseInclude(ParserState* parser) {
	Match(parser, TOKEN_INCLUDE);
	return CreateASTNode(SEM_INCLUDE, Match(parser, TOKEN_STRING));
}