search.h 3.8 KB

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