// ---------------------------------------------------------------------------
// Searches the first message matching with the search string and requests
// a chunk of messages including the matching message and messages preceding 
// it.
// The return value tells currently only, if there are more messages, but it
// is not checked whether they are deleted. It is probably more important
// to return as fast as possible than check the remaining messages. The same
// concerns PreviousL().
// ---------------------------------------------------------------------------
//
TBool CIpsPlgMsgIterator::PreviousL(
    const TDesC&  aStartWith, 
    TUint aCount, 
    RPointerArray<CFSMailMessage>& aMessages)
    {
    FUNC_LOG;
    TBool result = EFalse;
    TInt status;
    TInt baseIndex;
    
    // Messages are sorted always before reading the messages 
    Sort();

    CMsvEntrySelection* messages = FilterMessagesL();
    CleanupStack::PushL( messages );

    status = SearchL( iMessages, aStartWith, baseIndex );
    
    if (  status == KErrNone ) 
        {
        result = PreviousL(baseIndex, iMessages, aCount, aMessages);
        }

    return result;
    }
// ---------------------------------------------------------------------------
// Searches message matching with the search string and returns a chunk of
// messages starting from the 1st matched message
// ---------------------------------------------------------------------------
//
TBool CIpsPlgMsgIterator::NextL(
    const TDesC&  aStartWith, 
    TUint aCount, 
    RPointerArray<CFSMailMessage>& aMessages)
    {
    FUNC_LOG;
    TBool result = EFalse;
    TInt status;
    TInt baseIndex;
    
    if ( !iMessages )
        {
        // Messages are sorted before first reading the messages 
        Sort();
        iMessages = FilterMessagesL();
        }

    status = SearchL( iMessages, aStartWith, baseIndex );
    
    if ( status == KErrNone )
        {
        result = NextL( baseIndex, iMessages, aCount, aMessages );
        }

    return result;
    }
Example #3
0
int main (int argc, char** argv)
{
    int a, pop, sum, k;
    int l, o, c;
    int fd, val;

    MyRecord temprec, r;
    char ch;
    char phoneno[20];
    char town[20];
    char min[20], max[20];
    char word[20];
    l = 0;
    o = 0;
    c = 0;
    char loadFile[20], opFile[20], configFile[20];

    /* Diabasma orismatwn */

    opterr = 0;

    while ((a = getopt (argc, argv, "l:o:c:")) != -1)
        switch (a)
        {
           case 'l':
             strcpy(loadFile, optarg);
             l = 1;
             break;
           case 'o':
             strcpy(opFile, optarg);
             o = 1;
             break;
           case 'c':
             strcpy(configFile, optarg);
             c = 1;
             break;
           case '?':
             if (optopt == 'p' || optopt == 'i' || optopt == 'd')
               fprintf (stderr, "Option -%c requires an argument.\n", optopt);
             else if (isprint (optopt))
               fprintf (stderr, "Unknown option `-%c'.\n", optopt);
             else
               fprintf (stderr,
                        "Unknown option character `\\x%x'.\n",
                        optopt);
             return 1;
           default:
             abort ();
        }

   InitializeI(&start_town);

   /* Xrhsh orismatwn */
    if(c == 1)
    {
        FILE* con;
        con = fopen(configFile,"r");
        if (con == NULL)
        {
            printf("Cannot open configuration file\n");
        }
        else
            while(!feof(con))
            {
                if(fscanf(con, "%s %d", word, &val) == 2)
                    if(strcmp(word, "Hash_Table_Size") == 0)
                    {
                        hashtsize = val;
                        hashtable = malloc(hashtsize*(sizeof(pnode)));
                    }
            }
    }
    if(l == 1)
    {
        Load_file(loadFile);
        l = 0;
    }
     if(o == 1)                     // An uparxei operation file tote to stdin anakateuthunetai sto arxeio ayto k diabazontai oi entoles kanonika mexri na teleiwsei
    {
        if(hashtsize == 0)
        {
            hashtsize = primes(DEFAULT_HASH_SIZE);
            hashtable = malloc(hashtsize*(sizeof(pnode)));
        }
        if( access(opFile, F_OK ) != -1 )
        {
            fd = dup(fileno(stdin));
            freopen(opFile, "r", stdin);
        }
        else
            printf("Cannot open operation file\n");

    }
    memset(max, '0', 20);
    memset(min, '0', 20);
    if(hashtsize == 0)
        {
            hashtsize = primes(DEFAULT_HASH_SIZE);
            hashtable = malloc(hashtsize*(sizeof(pnode)));
        }
    if(o == 0)
        printf("Give input\n");

    /* Epanalipsh gia thn eisagwgh entolwn. Diavasma prwtou xarakthra kai elegxos periptwsewn */
    while(1)
    {


        ch = getchar();
        if(ch == 'i')
        {
            ReadValue(&temprec);
            if(SearchL(temprec.phone, hashtable, hashtsize, &r) == 0)
                InsertL(temprec, hashtable, hashtsize, start_town);
            else
                printf("Number %s already exists. Cannot add the same number twice.\n", temprec.phone);
            //temp_town = start_town;
		}
		else if(ch == 'q')
		{
            scanf("%10s", phoneno);
            if(SearchL(phoneno, hashtable, hashtsize, &r) == 1)
                WriteValue(r);
            else
                printf("Number %s not found.\n", phoneno);
            memset(phoneno, '\0', 20);
		}
		else if(ch == 'd')
		{
            scanf("%10s", phoneno);
            DeleteL(phoneno, hashtable, hashtsize, start_town);
            memset(phoneno, '\0', 20);
		}
		else if(ch == 'l')
        {
            scanf("%s", loadFile);
            Load_file(loadFile);
        }
		else if(ch == 'e')
		{
            FreeIndex(start_town);
            free(start_town);
            free(hashtable);
            return 0;
		}
		else if(ch == 'p')
		{
            scanf("%s", town);
            pop = PopulationI(start_town, town);
            if(pop > 0)
                printf("%s: %d\n", town, pop);
            else
                printf("Town %s not found.\n", town);
            memset(town, '\0', 20);
		}
		else if(ch == 's')
		{
            scanf("%s", town);
            sum = SummaryI(start_town, town);
            if(sum > 0)
                printf("%s: %d\n", town, sum);
            else
                printf("Town %s not found.\n", town);
            memset(town, '\0', 20);
		}
		else if(ch == 't')
		{
            scanf("%d", &k);
            Top(start_town, k);
		}
		else if(ch == 'f')
		{
            ch = getchar();
            if(ch == 't')
            {
                ch = getchar();
                if(ch == ' ')
                {
                    scanf("%s %d", town, &k);
                    TopKSpenders(start_town, town, k);
                }
                else if(ch == 's')
                    TopTownSpenders(start_town);
            }
		}
		else if(ch == 'm')
		{
            ch = getchar();
            if(ch == 'a')
            {
                ch = getchar();
                if(ch == 'x')
                {
                    //if(max[0] == '0')
                        Max(start_town);
                }
            }
            else if(ch == 'i')
            {
                ch = getchar();
                if(ch == 'n')
                {
                   // if(min[0] == '0')
                        Min(start_town);
                }
            }
		}
		//scanf("%20s", junk);
		if(o == 1 && ch == EOF)     // An yparxei operation file san orisma kai exei teleiwsei h anagnwsh epanafora tou stdin.
        {
            fflush(stdin);
            dup2(fd, fileno(stdin));
            close(fd);
            clearerr(stdin);
            o = 0;
            printf("Operation file finished succesfully.\n");
        }
        fflush(stdin);
    }

    return 0;

    }
Example #4
0
void CCSMainView::HandleCommandL( TInt aCommand )
{
    TInt cc = 0;
    CDataHolder* dataHolder = 0;
    HBufC* titleText = 0;
    switch ( aCommand ) {
    case EAknSoftkeyBack:
        iHasSetCountry = EFalse;
        iWayfinderAppUi->HandleCommandL(aCommand);
        break;
    case EWayFinderCmdCSNewSearch:
        iHasSetCountry = EFalse;
        SearchL();
        //iContainer->SetMethod(ETrue);
        break;
    case EWayFinderCmdCSSwitchToCountrySelect:
        iSettingCountry = ETrue;
        iWayfinderAppUi->SetupCSCountryListL();
        iWayfinderAppUi->HandleCommandL(EWayFinderCmdCSSwitchToCountrySelect);
        titleText = StringLoader::LoadLC(R_TITLEPANE_COUNTRY_LIST_TEXT); // CS_CHANGEME
        iWayfinderAppUi->setTitleText(titleText->Des());
        CleanupStack::PopAndDestroy(titleText);
        break;
    case EWayFinderCmdCSSwitchToCategorySelect:
        iSettingCountry = EFalse;
        iWayfinderAppUi->SetupCSCategoryListL();
        iWayfinderAppUi->HandleCommandL(EWayFinderCmdCSSwitchToCategorySelect);
        titleText = StringLoader::LoadLC(R_TITLEPANE_SELECT_CATEGORY_TEXT);
        iWayfinderAppUi->setTitleText(titleText->Des());
        CleanupStack::PopAndDestroy(titleText);
        break;
    case EWayFinderCmdCSSetFromGps:
        if (iSavedData.iUseFromGps == 0 && (IsGpsConnected() || iWayfinderAppUi->GetCellCountry() >= 0))
        {
            iSavedData.iUseFromGps = 1;
            dataHolder = iWayfinderAppUi->GetDataHolder();
            if (dataHolder)
            {
                cc = iWayfinderAppUi->GetCellCountry();
                if (cc >= 0)
                {
                    iSavedData.iCountry.Copy(*dataHolder->GetCountryFromId(iWayfinderAppUi->GetCellCountry()));
                    iSavedData.iCountryId = iWayfinderAppUi->GetCellCountry();
                }
            }
            if ((iSavedData.iCountryId == -1) && (iWayfinderAppUi->GetCellCountry() != -1))
            {
                iSavedData.iCountryId = iWayfinderAppUi->GetCellCountry();
            }
        }

        iContainer->SetUpdate(ETrue);
        iContainer->InitSearchFields();
#if defined NAV2_CLIENT_SERIES60_V5
        if (iGpsButton) {
            if (IsGpsConnected() || iWayfinderAppUi->GetCellCountry() >= 0)
            {
                iGpsButton->SetCurrentState(1, ETrue);
            }
        }
#endif
        break;
    case EWayFinderCmdCSSearchHistory:
#if defined NAV2_CLIENT_SERIES60_V5
        if (iGpsButton) {
            iGpsButton->SetCurrentState(0, ETrue);
        }
#endif
        GetSearchHistory();
        break;
    default:
        iWayfinderAppUi->HandleCommandL(aCommand);
        break;
    }
}
// ==========================================================================
// FUNCTION: DoNextSearchL
// ==========================================================================
void CContainerStoreSearchHandler::DoNextSearchL()
    {
    __LOG_ENTER_SUPPRESS( "DoNextSearch" )
    
    TContainerId messageId = KContainerInvalidId;
    
    if ( iSortResultSet->HasMoreNextL() )
        {
        messageId = iSortResultSet->NextL();
        }
    else
        {
        while ( SortNextFolderL() )
            {
            if ( iSortResultSet->HasMoreNextL() )
                {
                messageId = iSortResultSet->NextL();
                break;
                }
            }
        }
    
    if( messageId != KContainerInvalidId  )
        {
        TBool found = EFalse;
        
        TRAP_IGNORE( found = SearchL( messageId ) );
        
        if( found )
            {
            // Remove the properties that are not needed.
            TPropertiesSerializer serializer( iPropertyBuf );        
            TBool moreProperties = serializer.First();        
            while( moreProperties )        
                {
                TBool found = EFalse;            
                for( TInt i = 0; !found && (i < iPropertyNames.Count()); i++ )
                    {
                    found = (iPropertyNames[i]->Compare( serializer.Name() ) == 0);
                    } // end for                               
                if( found )
                    {
                    moreProperties = serializer.Next();
                    }
                else
                    {
                    moreProperties = serializer.RemovePropertyL();
                    } // end if                
                } // end while   
            
            
            iClient.MatchFound( messageId, iSortResultSet->FolderId(), iPropertyBuf );
            } // end if
        
        // Schedule next search (yield, in case higher priority active objects have something to do).
		SetActive();
		TRequestStatus* status = &iStatus;
		User::RequestComplete( status, KErrNone );      
        }
    else
        {
        // Done!
        __LOG_WRITE_INFO( "Search complete" )
        iClient.SearchComplete( KErrNone );
        } // end if
        
    } // end DoNextSearch