예제 #1
0
const wchar_t *history_prev_match( const wchar_t *needle )
{
    if( current_mode )
    {
        if( current_mode->pos > 0 )
        {
            for( current_mode->pos--; current_mode->pos>=0; current_mode->pos-- )
            {
                item_t *i = item_get( current_mode, al_get( &current_mode->item, current_mode->pos ) );
                wchar_t *haystack = (wchar_t *)i->data;

                if( history_test( needle, haystack ) )
                {
                    int is_used;

                    /*
                      This is ugly.  Whenever we call item_get(),
                      there is a chance that the return value of any
                      previous call to item_get will become
                      invalid. The history_is_used function uses the
                      item_get() function. Therefore, we must create
                      a copy of the haystack string, and if the string
                      is unused, we must call item_get anew.
                    */

                    haystack = wcsdup(haystack );

                    is_used = history_is_used( haystack );

                    free( haystack );

                    if( !is_used )
                    {
                        i = item_get( current_mode, al_get( &current_mode->item, current_mode->pos ) );
                        al_push_long( &current_mode->used, current_mode->pos );
                        return i->data;
                    }
                }
            }
        }

        if( !current_mode->has_loaded )
        {
            /*
              We found no match in the list, try loading the history
              file and continue the search
            */
            history_load( current_mode );
            return history_prev_match( needle );
        }
        else
        {
            /*
              We found no match in the list, and the file is already
              loaded. Set poition before first element and return
              original search string.
            */
            current_mode->pos=-1;
            if( al_peek_long( &current_mode->used ) != -1 )
                al_push_long( &current_mode->used, -1 );
        }

    }

    return needle;
}
예제 #2
0
int main (  G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
{
    history_test ();

    return 0;
}