Changeset 8312577 in mainline for uspace/app/edit/search.c


Ignore:
Timestamp:
2012-08-17T11:44:43Z (12 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1d5a540
Parents:
2f136e4
Message:

Add backwards search functionality to edit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/edit/search.c

    r2f136e4 r8312577  
    4141#include "search_impl.h"
    4242
    43 search_t *search_init(const char *pattern, void *client_data, search_ops_t ops)
     43search_t *search_init(const char *pattern, void *client_data, search_ops_t ops,
     44    bool reverse)
    4445{
    4546        search_t *search = calloc(1, sizeof(search_t));
     
    4748                return NULL;
    4849       
    49         search->pattern = str_to_awstr(pattern);
    50         if (search->pattern == NULL) {
     50        wchar_t *p = str_to_awstr(pattern);
     51        if (p == NULL) {
    5152                free(search);
    5253                return NULL;
    5354        }
    5455       
     56        search->pattern_length = wstr_length(p);
     57       
     58        if (reverse) {
     59                /* Reverse the pattern */
     60                size_t pos, half;
     61                half = search->pattern_length / 2;
     62                for (pos = 0; pos < half; pos++) {
     63                        wchar_t tmp = p[pos];
     64                        p[pos] = p[search->pattern_length - pos - 1];
     65                        p[search->pattern_length - pos - 1] = tmp;
     66                }
     67        }
     68       
     69        search->pattern = p;
     70       
    5571        search->client_data = client_data;
    5672        search->ops = ops;
    57         search->pattern_length = wstr_length(search->pattern);
    5873        search->back_table = calloc(search->pattern_length, sizeof(ssize_t));
    5974        if (search->back_table == NULL) {
Note: See TracChangeset for help on using the changeset viewer.