195b7b453SJohn Marino /* search.c - searching subroutines using dfa, kwset and regex for grep.
2*09d4459fSDaniel Fojt Copyright 1992, 1998, 2000, 2007, 2009-2020 Free Software Foundation, Inc.
395b7b453SJohn Marino
495b7b453SJohn Marino This program is free software; you can redistribute it and/or modify
595b7b453SJohn Marino it under the terms of the GNU General Public License as published by
695b7b453SJohn Marino the Free Software Foundation; either version 3, or (at your option)
795b7b453SJohn Marino any later version.
895b7b453SJohn Marino
995b7b453SJohn Marino This program is distributed in the hope that it will be useful,
1095b7b453SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
1195b7b453SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1295b7b453SJohn Marino GNU General Public License for more details.
1395b7b453SJohn Marino
1495b7b453SJohn Marino You should have received a copy of the GNU General Public License
1595b7b453SJohn Marino along with this program; if not, write to the Free Software
1695b7b453SJohn Marino Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
1795b7b453SJohn Marino 02110-1301, USA. */
1895b7b453SJohn Marino
1995b7b453SJohn Marino #ifndef GREP_SEARCH_H
2095b7b453SJohn Marino #define GREP_SEARCH_H 1
2195b7b453SJohn Marino
2295b7b453SJohn Marino #include <config.h>
2395b7b453SJohn Marino
2495b7b453SJohn Marino #include <sys/types.h>
25a8597f6cSJohn Marino #include <stdint.h>
2695b7b453SJohn Marino #include <wchar.h>
2795b7b453SJohn Marino #include <wctype.h>
2895b7b453SJohn Marino #include <regex.h>
2995b7b453SJohn Marino
3095b7b453SJohn Marino #include "system.h"
3195b7b453SJohn Marino #include "grep.h"
32680a9cb8SJohn Marino #include "dfa.h"
3395b7b453SJohn Marino #include "kwset.h"
3495b7b453SJohn Marino #include "xalloc.h"
35*09d4459fSDaniel Fojt #include "localeinfo.h"
3695b7b453SJohn Marino
37dc7c36e4SJohn Marino _GL_INLINE_HEADER_BEGIN
38dc7c36e4SJohn Marino #ifndef SEARCH_INLINE
39dc7c36e4SJohn Marino # define SEARCH_INLINE _GL_INLINE
40dc7c36e4SJohn Marino #endif
41dc7c36e4SJohn Marino
42a8597f6cSJohn Marino /* This must be a signed type. Each value is the difference in the size
43a8597f6cSJohn Marino of a character (in bytes) induced by converting to lower case.
44a8597f6cSJohn Marino The vast majority of values are 0, but a few are 1 or -1, so
45a8597f6cSJohn Marino technically, two bits may be sufficient. */
46a8597f6cSJohn Marino typedef signed char mb_len_map_t;
47a8597f6cSJohn Marino
4895b7b453SJohn Marino /* searchutils.c */
49*09d4459fSDaniel Fojt extern void wordinit (void);
50*09d4459fSDaniel Fojt extern kwset_t kwsinit (bool);
51*09d4459fSDaniel Fojt extern size_t wordchars_size (char const *, char const *) _GL_ATTRIBUTE_PURE;
52*09d4459fSDaniel Fojt extern size_t wordchar_next (char const *, char const *) _GL_ATTRIBUTE_PURE;
53*09d4459fSDaniel Fojt extern size_t wordchar_prev (char const *, char const *, char const *)
54*09d4459fSDaniel Fojt _GL_ATTRIBUTE_PURE;
55*09d4459fSDaniel Fojt extern ptrdiff_t mb_goback (char const **, size_t *, char const *,
56*09d4459fSDaniel Fojt char const *);
5795b7b453SJohn Marino
5895b7b453SJohn Marino /* dfasearch.c */
59*09d4459fSDaniel Fojt extern void *GEAcompile (char *, size_t, reg_syntax_t);
60*09d4459fSDaniel Fojt extern size_t EGexecute (void *, char const *, size_t, size_t *, char const *);
6195b7b453SJohn Marino
6295b7b453SJohn Marino /* kwsearch.c */
63*09d4459fSDaniel Fojt extern void *Fcompile (char *, size_t, reg_syntax_t);
64*09d4459fSDaniel Fojt extern size_t Fexecute (void *, char const *, size_t, size_t *, char const *);
6595b7b453SJohn Marino
6695b7b453SJohn Marino /* pcresearch.c */
67*09d4459fSDaniel Fojt extern void *Pcompile (char *, size_t, reg_syntax_t);
68*09d4459fSDaniel Fojt extern size_t Pexecute (void *, char const *, size_t, size_t *, char const *);
69*09d4459fSDaniel Fojt
70*09d4459fSDaniel Fojt /* grep.c */
71*09d4459fSDaniel Fojt extern struct localeinfo localeinfo;
72*09d4459fSDaniel Fojt extern void fgrep_to_grep_pattern (char **, size_t *);
7395b7b453SJohn Marino
74dc7c36e4SJohn Marino /* Return the number of bytes in the character at the start of S, which
75dc7c36e4SJohn Marino is of size N. N must be positive. MBS is the conversion state.
76dc7c36e4SJohn Marino This acts like mbrlen, except it returns 1 when mbrlen would return 0,
77dc7c36e4SJohn Marino and it is typically faster because of the cache. */
78dc7c36e4SJohn Marino SEARCH_INLINE size_t
mb_clen(char const * s,size_t n,mbstate_t * mbs)79dc7c36e4SJohn Marino mb_clen (char const *s, size_t n, mbstate_t *mbs)
80dc7c36e4SJohn Marino {
81*09d4459fSDaniel Fojt size_t len = localeinfo.sbclen[to_uchar (*s)];
82dc7c36e4SJohn Marino return len == (size_t) -2 ? mbrlen (s, n, mbs) : len;
83dc7c36e4SJohn Marino }
84dc7c36e4SJohn Marino
85dc7c36e4SJohn Marino _GL_INLINE_HEADER_END
86dc7c36e4SJohn Marino
8795b7b453SJohn Marino #endif /* GREP_SEARCH_H */
88