[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[5745] regexp_search - don't take WINDOW argument
From: |
Gavin D. Smith |
Subject: |
[5745] regexp_search - don't take WINDOW argument |
Date: |
Sun, 10 Aug 2014 14:00:12 +0000 |
Revision: 5745
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5745
Author: gavin
Date: 2014-08-10 14:00:03 +0000 (Sun, 10 Aug 2014)
Log Message:
-----------
regexp_search - don't take WINDOW argument
Modified Paths:
--------------
trunk/ChangeLog
trunk/info/info-utils.c
trunk/info/search.c
trunk/info/search.h
trunk/info/session.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2014-08-09 10:46:16 UTC (rev 5744)
+++ trunk/ChangeLog 2014-08-10 14:00:03 UTC (rev 5745)
@@ -1,3 +1,13 @@
+2014-08-10 Gavin Smith <address@hidden>
+
+ * info/search.c (regexp_search): Arguments changed. Don't take
+ WINDOW argument.
+ * info/info-utils.c (scan_node_contents)
+ * info/session.c (info_search_in_node_internal)
+ Call to regexp_search updated.
+ * info/session.c (match_in_match_list): Don't take WINDOW argument.
+ Callers updated.
+
2014-08-09 Gavin Smith <address@hidden>
* info/session.c (match_in_match_list): Arguments changed. Output
Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c 2014-08-09 10:46:16 UTC (rev 5744)
+++ trunk/info/info-utils.c 2014-08-10 14:00:03 UTC (rev 5745)
@@ -1590,10 +1590,10 @@
void
scan_node_contents (FILE_BUFFER *fb, NODE **node_ptr)
{
- SEARCH_BINDING s;
char *search_string;
long position;
- WINDOW save_search = {};
+ regmatch_t *matches;
+ size_t match_count;
size_t i;
int in_menu = 0;
@@ -1657,20 +1657,15 @@
search_string = INFO_MENU_REGEXP "|" INFO_MENU_ENTRY_REGEXP
"|" INFO_XREF_REGEXP "|" INFO_TAG_REGEXP;
- s.buffer = node->contents;
- s.start = inptr - node->contents;
- s.end = node->nodelen;
- s.flags = S_FoldCase;
-
- save_search.node = node;
-
- if (regexp_search (search_string, 0, &save_search) == search_success)
- for (i = 0; i < save_search.match_count; i++)
+ if (regexp_search (search_string, 1, node->contents, node->nodelen,
+ &matches, &match_count)
+ == search_success)
+ for (i = 0; i < match_count; i++)
{
int in_parentheses = 0;
REFERENCE *entry;
char *match;
- position = save_search.matches[i].rm_so;
+ position = matches[i].rm_so;
match = node->contents + position;
@@ -1699,8 +1694,8 @@
/* Create REFERENCE entity. */
entry = info_new_reference (0, 0);
- if (safe_string_index (inptr, -1, s.buffer, s.end) == '('
- && safe_string_index (inptr, 1, s.buffer, s.end) == 'n')
+ if (safe_string_index (inptr, -1, input_start, input_length) == '('
+ && safe_string_index (inptr, 1, input_start, input_length) == 'n')
in_parentheses = 1;
save_conversion_state ();
@@ -1715,15 +1710,11 @@
copy_input_to_output (cur_inptr - inptr);
info_reference_free (entry);
- s.start = inptr - s.buffer;
continue;
}
add_pointer_to_array (entry, refs_index, refs, refs_slots, 50);
}
-
- s.start = inptr - s.buffer;
- if (s.start >= s.end) break;
}
/* If we haven't accidentally gone past the end of the node, write
Modified: trunk/info/search.c
===================================================================
--- trunk/info/search.c 2014-08-09 10:46:16 UTC (rev 5744)
+++ trunk/info/search.c 2014-08-10 14:00:03 UTC (rev 5745)
@@ -119,85 +119,72 @@
return unescaped_regexp;
}
-/* Pass back the list of matches in WINDOW->matches. */
+/* Search BUFFER for REGEXP. Pass back the list of matches in MATCHES. */
enum search_result
-regexp_search (char *regexp, int is_insensitive, WINDOW *window)
+regexp_search (char *regexp, int is_insensitive, char *buffer, size_t buflen,
+ regmatch_t **matches_out, size_t *match_count_out)
{
- char *buffer; /* Buffer to search in. */
-
- regmatch_t *new_matches = 0; /* List of found matches. */
+ regmatch_t *matches = 0; /* List of found matches. */
size_t match_alloc = 0;
- size_t new_match_count = 0;
+ size_t match_count;
- /* Calculate new results. */
- {
- regex_t preg; /* Compiled pattern buffer for regexp. */
- int result;
- char *unescaped_regexp;
- char saved_char;
- regoff_t offset = 0;
+ regex_t preg; /* Compiled pattern buffer for regexp. */
+ int result;
+ char *unescaped_regexp;
+ char saved_char;
+ regoff_t offset = 0;
- unescaped_regexp = regexp_expand_newlines_and_tabs (regexp);
+ unescaped_regexp = regexp_expand_newlines_and_tabs (regexp);
- result = regcomp (&preg, unescaped_regexp,
- REG_EXTENDED|
- REG_NEWLINE|
- (is_insensitive ? REG_ICASE : 0));
- free (unescaped_regexp);
+ result = regcomp (&preg, unescaped_regexp,
+ REG_EXTENDED | REG_NEWLINE
+ | (is_insensitive ? REG_ICASE : 0));
+ free (unescaped_regexp);
- if (result != 0)
+ if (result != 0)
+ {
+ int size = regerror (result, &preg, NULL, 0);
+ char *buf = xmalloc (size);
+ regerror (result, &preg, buf, size);
+ info_error (_("regexp error: %s"), buf);
+ return search_failure;
+ }
+
+ saved_char = buffer[buflen];
+ buffer[buflen] = '\0';
+
+ for (match_count = 0; offset < buflen; )
+ {
+ int result = 0;
+ if (match_count == match_alloc)
{
- int size = regerror (result, &preg, NULL, 0);
- char *buf = xmalloc (size);
- regerror (result, &preg, buf, size);
- info_error (_("regexp error: %s"), buf);
- return search_failure;
+ /* The match list is full. Initially allocate 256 entries,
+ then double every time we fill it. */
+ if (match_alloc == 0)
+ match_alloc = 256;
+ matches = x2nrealloc (matches, &match_alloc, sizeof matches[0]);
}
- buffer = window->node->contents;
- saved_char = buffer[window->node->nodelen];
- buffer[window->node->nodelen] = '\0';
-
- for (new_match_count = 0; offset < window->node->nodelen; )
+ result = regexec (&preg, &buffer[offset], 1, &matches[match_count], 0);
+ if (result == 0)
{
- int result = 0;
- if (new_match_count == match_alloc)
+ if (matches[match_count].rm_eo == 0)
+ offset++; /* Ignore empty matches. */
+ else
{
- /* The match list is full. Initially allocate 256 entries,
- then double every time we fill it. */
- if (match_alloc == 0)
- match_alloc = 256;
- new_matches = x2nrealloc (new_matches, &match_alloc, sizeof
new_matches[0]);
+ matches[match_count].rm_so += offset;
+ matches[match_count].rm_eo += offset;
+ offset = matches[match_count++].rm_eo;
}
-
- result = regexec (&preg, &buffer[offset],
- 1, &new_matches[new_match_count], 0);
- if (result == 0)
- {
- if (new_matches[new_match_count].rm_eo == 0)
- {
- /* ignore empty matches */
- offset++;
- }
- else
- {
- new_matches[new_match_count].rm_so += offset;
- new_matches[new_match_count].rm_eo += offset;
- offset = new_matches[new_match_count++].rm_eo;
- }
- }
- else
- break;
}
- buffer[window->node->nodelen] = saved_char;
- regfree (&preg);
+ else
+ break;
}
+ buffer[buflen] = saved_char;
+ regfree (&preg);
- /* Pass back the full list of results. */
- window->search_string = xstrdup (regexp);
- window->search_is_case_sensitive = !is_insensitive;
- window->matches = new_matches;
- window->match_count = new_match_count;
+ *matches_out = matches;
+ *match_count_out = match_count;
return search_success;
}
Modified: trunk/info/search.h
===================================================================
--- trunk/info/search.h 2014-08-09 10:46:16 UTC (rev 5744)
+++ trunk/info/search.h 2014-08-10 14:00:03 UTC (rev 5745)
@@ -60,8 +60,10 @@
long *poff);
extern enum search_result search (char *string, SEARCH_BINDING *binding,
long *poff);
-extern enum search_result regexp_search (char *regexp, int is_sensitive,
- WINDOW *window);
+enum search_result regexp_search (char *regexp, int is_insensitive,
+ char *buffer, size_t buflen,
+ regmatch_t **matches_out,
+ size_t *match_count_out);
extern int looking_at (char *string, SEARCH_BINDING *binding);
/* Note that STRING_IN_LINE () always returns the offset of the 1st character
Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c 2014-08-09 10:46:16 UTC (rev 5744)
+++ trunk/info/session.c 2014-08-10 14:00:03 UTC (rev 5745)
@@ -3451,19 +3451,15 @@
return NULL;
}
-/* Search forwards or backwards for entries in WINDOW->matches that are within
+/* Search forwards or backwards for entries in MATCHES that are within
the search area delimited by BINDING. The search is forwards if
- BINDING->start is greater than BINDING->end. */
+ BINDING->start is greater than BINDING->end. Return index of match in
+ *MATCH_INDEX. */
static enum search_result
-match_in_match_list (WINDOW *window, SEARCH_BINDING *binding, int *match_index)
+match_in_match_list (regmatch_t *matches, size_t match_count,
+ SEARCH_BINDING *binding, int *match_index)
{
regoff_t start, end;
- regmatch_t *matches; /* List of matches. */
- size_t match_count;
-
- matches = window->matches;
- match_count = window->match_count;
-
if (binding->start < binding->end)
{
start = binding->start;
@@ -3527,6 +3523,8 @@
SEARCH_BINDING binding;
enum search_result result = search_not_found;
+ regmatch_t *matches;
+ size_t match_count;
int match_index;
binding.flags = 0;
@@ -3566,16 +3564,6 @@
if (result != search_success)
{
- /* regexp_search uses window->node now, not binding.buffer. */
- NODE *saved_node = 0;
- if (window)
- {
- saved_node = window->node;
- window->node = node;
- free (window->matches);
- window->matches = 0;
- }
-
binding.buffer = node->contents;
binding.start = start;
binding.end = node->nodelen;
@@ -3600,21 +3588,24 @@
|| strcmp (window->search_string, string)
|| !!window->search_is_case_sensitive
!= !!(binding.flags & S_FoldCase))
- result = regexp_search (string, binding.flags & S_FoldCase,
- window);
+ {
+ window->search_string = xstrdup (string);
+ window->search_is_case_sensitive = !(binding.flags & S_FoldCase);
+ result = regexp_search (string, binding.flags & S_FoldCase,
+ node->contents, node->nodelen,
+ &matches, &match_count);
+ }
else
result = search_success;
if (result != search_failure)
{
- result = match_in_match_list (window, &binding, &match_index);
+ result = match_in_match_list (matches, match_count,
+ &binding, &match_index);
if (result == search_success)
- *poff = window->matches[match_index].rm_so;
+ *poff = matches[match_index].rm_so;
}
}
-
- if (saved_node)
- window->node = saved_node;
}
if (result == search_success && window)
@@ -3623,20 +3614,19 @@
window->flags |= W_UpdateWindow;
if (window->node != node)
- {
- /* window->matches is already the match list for the new node,
- so prevent info_set_node_of_window freeing it. */
- regmatch_t *saved_matches = window->matches;
- window->matches = 0;
+ info_set_node_of_window (window, node);
- info_set_node_of_window (window, node);
- window->matches = saved_matches;
+ if (window->matches != matches)
+ {
+ free (window->matches);
+ window->matches = matches;
+ window->match_count = match_count;
}
if (dir > 0 && (binding.flags & S_SkipDest))
- new_point = window->matches[match_index].rm_eo;
+ new_point = matches[match_index].rm_eo;
else
- new_point = window->matches[match_index].rm_so;
+ new_point = matches[match_index].rm_so;
window->point = new_point;
window_adjust_pagetop (window);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [5745] regexp_search - don't take WINDOW argument,
Gavin D. Smith <=