1 /* search.h -- Structure used to search large bodies of text, with bounds.
2
3 Copyright 1993-2023 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 Originally written by Brian Fox. */
19
20 /* The search functions take two arguments:
21
22 1) a string to search for, and
23
24 2) a pointer to a SEARCH_BINDING which contains the buffer, start,
25 and end of the search.
26
27 They return a long, which is the offset from the start of the buffer
28 at which the match was found. An offset of -1 indicates failure. */
29
30 #ifndef INFO_SEARCH_H
31 #define INFO_SEARCH_H
32
33 #include "window.h"
34
35 typedef struct {
36 char *buffer; /* The buffer of text to search. */
37 long start; /* Offset of the start of the search. */
38 long end; /* Offset of the end of the searh. */
39 int flags; /* Flags controlling the type of search. */
40 } SEARCH_BINDING;
41
42 #define S_FoldCase 0x01 /* Set means fold case in searches. */
43 #define S_SkipDest 0x02 /* Set means return pointing after the dest. */
44
45 enum search_result
46 {
47 search_success,
48 search_not_found,
49 search_invalid
50 };
51
52 enum search_result search_forward (char *string,
53 SEARCH_BINDING *binding, long *poff);
54 enum search_result search_backward (char *input_string,
55 SEARCH_BINDING *binding,
56 long *poff);
57 enum search_result search (char *string, SEARCH_BINDING *binding,
58 long *poff);
59 enum search_result regexp_search (char *regexp,
60 int is_literal, int is_insensitive,
61 char *buffer, size_t buflen,
62 MATCH_STATE *match_state);
63 int looking_at (char *string, SEARCH_BINDING *binding);
64 int looking_at_line (char *string, char *pointer);
65
66 /* Note that STRING_IN_LINE () always returns the offset of the 1st character
67 after the string. */
68 int string_in_line (char *string, char *line);
69
70 /* Function names that start with "skip" are passed a string, and return
71 an offset from the start of that string. Function names that start
72 with "find" are passed a SEARCH_BINDING, and return an absolute position
73 marker of the item being searched for. "Find" functions return a value
74 of -1 if the item being looked for couldn't be found. */
75 int skip_whitespace (char *string);
76 int skip_non_whitespace (char *string);
77 int skip_whitespace_and_newlines (char *string);
78 int skip_node_separator (char *body);
79
80 long find_node_separator (SEARCH_BINDING *binding);
81 long find_file_section (SEARCH_BINDING *binding, char *label);
82 long find_node_in_binding (char *nodename, SEARCH_BINDING *binding);
83
84 regmatch_t match_by_index (MATCH_STATE *state, int index);
85 enum search_result match_in_match_list (MATCH_STATE *state,
86 long start, long end, int dir, int *match_index);
87
88 void free_matches (MATCH_STATE *state);
89 int matches_ready (MATCH_STATE *state);
90 int at_end_of_matches (MATCH_STATE *state, int index);
91 void decide_if_in_match (long off, int *in_match, MATCH_STATE *matches,
92 size_t *match_index);
93
94 #endif /* not INFO_SEARCH_H */