summaryrefslogtreecommitdiff
path: root/src/search.h
blob: 529e7e2372036ad410501c0e9438964307ec3c27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* search.c - searching subroutines using dfa, kwset and regex for grep.
   Copyright 1992, 1998, 2000, 2007, 2009-2012 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */

#ifndef GREP_SEARCH_H
#define GREP_SEARCH_H 1

#include <config.h>

#include <sys/types.h>

#include "mbsupport.h"

#include <wchar.h>
#include <wctype.h>
#include <regex.h>

#include "system.h"
#include "error.h"
#include "grep.h"
#include "kwset.h"
#include "xalloc.h"

/* searchutils.c */
extern void kwsinit (kwset_t *);

extern char *mbtolower (const char *, size_t *, unsigned char **);
extern bool is_mb_middle (const char **, const char *, const char *, size_t);

/* dfasearch.c */
extern void GEAcompile (char const *, size_t, reg_syntax_t);
extern size_t EGexecute (char const *, size_t, size_t *, char const *);

/* kwsearch.c */
extern void Fcompile (char const *, size_t);
extern size_t Fexecute (char const *, size_t, size_t *, char const *);

/* pcresearch.c */
extern void Pcompile (char const *, size_t);
extern size_t Pexecute (char const *, size_t, size_t *, char const *);

/* Apply a non-NULL MAP from mbtolower to the lowercase-buffer-relative
   *OFF and *LEN, converting them to be relative to the original buffer.  */
static inline void
mb_case_map_apply (unsigned char const *map, size_t *off, size_t *len)
{
  if (map)
    {
      size_t off_incr = 0;
      size_t len_incr = 0;
      size_t k;
      for (k = 0; k < *off; k++)
        off_incr += map[k];
      for (k = *off; k < *off + *len; k++)
        len_incr += map[k];
      *off += off_incr;
      *len += len_incr;
    }
}

#endif /* GREP_SEARCH_H */