ELinks 0.18.0
search.c File Reference

Searching in the HTML document. More...

#include <ctype.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "bfu/dialog.h"
#include "config/kbdbind.h"
#include "document/document.h"
#include "document/view.h"
#include "intl/charsets.h"
#include "intl/libintl.h"
#include "main/event.h"
#include "main/module.h"
#include "session/session.h"
#include "terminal/screen.h"
#include "terminal/terminal.h"
#include "util/color.h"
#include "util/error.h"
#include "util/memory.h"
#include "util/string.h"
#include "viewer/action.h"
#include "viewer/text/draw.h"
#include "viewer/text/link.h"
#include "viewer/text/search.h"
#include "viewer/text/view.h"
#include "viewer/text/vs.h"
Include dependency graph for search.c:

Data Structures

struct  search_dlg_hop

Macros

#define _GNU_SOURCE   /* XXX: we _WANT_ strcasestr() ! */
#define SEARCH_HISTORY_FILENAME   "searchhist"
#define UCHAR   unicode_val_T
#define PATTERN   const wchar_t
#define Regcomp   tre_regwcomp
#define Regexec   tre_regwexec
#define maybe_tolower(c)
#define realloc_points(pts, size)
#define maybe_tolower(c)
#define maybe_tolower(c)
#define HASH_SIZE   4096
#define HASH(p)
#define SEARCH_WIDGETS_COUNT   5

Enumerations

enum  find_error {
  FIND_ERROR_NONE , FIND_ERROR_NO_PREVIOUS_SEARCH , FIND_ERROR_HIT_TOP , FIND_ERROR_HIT_BOTTOM ,
  FIND_ERROR_NOT_FOUND , FIND_ERROR_MEMORY , FIND_ERROR_REGEX
}
enum  search_option { SEARCH_OPT_CASE , SEARCH_OPTIONS }

Functions

static INIT_INPUT_HISTORY (search_history)
static UCHARmemacpy_u (char *text, int textlen, int utf8)
static enum frame_event_status move_search_do (struct session *ses, struct document_view *doc_view, int direction)
static void add_srch_chr (struct document *document, UCHAR c, int x, int y, int nn)
static void sort_srch (struct document *document)
static int get_srch (struct document *document)
static void get_search_data (struct document *document)
static int get_range (struct document *document, int y, int height, int l, struct search **s1, struct search **s2)
 Assign s1 and s2 the first search node and the last search node needed to form the region starting at line y and ending at the greater of y + height and the end of the document, with allowance at the start to allow for multi-line matches that would otherwise be partially outside of the region.
static int strlen_u (char *text, int utf8)
static UCHARlowered_string (char *text, int textlen, int utf8)
 Returns an allocated string which is a lowered copy of passed one.
static int is_in_range_plain (struct document *document, int y, int height, char *text, int textlen, int *min, int *max, struct search *s1, struct search *s2, int utf8)
static int is_in_range (struct document *document, int y, int height, char *text, int *min, int *max)
static void get_searched_plain (struct document_view *doc_view, struct point **pt, int *pl, int l, struct search *s1, struct search *s2, int utf8)
static void get_searched_plain_all (struct document_view *doc_view, struct point **pt, int *pl, int l, struct search *s1, struct search *s2, int utf8)
static void get_searched (struct document_view *doc_view, struct point **pt, int *pl, int utf8)
void draw_searched (struct terminal *term, struct document_view *doc_view)
 Highlighting of searched strings.
static enum find_error find_next_do (struct session *ses, struct document_view *doc_view, int direction)
static void print_find_error (struct session *ses, enum find_error find_error)
static enum find_error get_searched_all (struct session *ses, struct document_view *doc_view, struct point **pt, int *pl, int utf8)
static enum find_error search_for_do (struct session *ses, const char *str, int direction, int report_errors)
static void search_for_back (struct session *ses, const char *str)
void search_for (struct session *ses, const char *str)
static int point_intersect (struct point *p1, int l1, struct point *p2, int l2)
static int find_next_link_in_search (struct document_view *doc_view, int direction)
static void print_find_error_not_found (struct session *ses, char *title, char *message, char *search_string)
static void print_find_error (struct session *ses, enum find_error find_error)
static enum find_error move_search_number (struct session *ses, struct document_view *doc_view, int number)
static int is_y_on_screen (struct document_view *doc_view, int y)
static void find_first_search_in_view (struct session *ses, struct document_view *doc_view)
enum frame_event_status move_search_next (struct session *ses, struct document_view *doc_view)
enum frame_event_status move_search_prev (struct session *ses, struct document_view *doc_view)
enum frame_event_status find_next (struct session *ses, struct document_view *doc_view, int direction)
static widget_handler_status_T search_dlg_cancel (struct dialog_data *dlg_data, struct widget_data *widget_data)
static widget_handler_status_T search_dlg_ok (struct dialog_data *dlg_data, struct widget_data *widget_data)
static void search_dlg_do (struct terminal *term, struct memory_list *ml, char *title, void *data, struct input_history *history, void(*fn)(void *, char *))
enum frame_event_status search_dlg (struct session *ses, struct document_view *doc_view, int direction)
static enum evhook_status search_history_write_hook (va_list ap, void *data)
static void init_search_history (struct module *module)
static void done_search_history (struct module *module)
Typeahead
static enum input_line_code text_typeahead_handler (struct input_line *line, int action_id)
 action_id can be a value from enum edit_action, in which case the approriate action is performed; -1, which indicates to search and report any errors; or -2, which indicates to search without reporting any errors.
static enum input_line_code link_typeahead_handler (struct input_line *line, int action_id)
enum frame_event_status search_typeahead (struct session *ses, struct document_view *doc_view, action_id_T action_id)

Variables

static struct option_resolver resolvers []
static struct event_hook_info search_history_hooks []
struct module search_history_module

Link typeahead

enum  typeahead_code { TYPEAHEAD_MATCHED , TYPEAHEAD_ERROR , TYPEAHEAD_ERROR_NO_FURTHER , TYPEAHEAD_CANCEL }
static void typeahead_error (struct session *ses, char *typeahead, int no_further)
static const char * get_link_typeahead_text (struct link *link)
static int match_link_text (struct link *link, char *text, int textlen, int case_sensitive)
static int search_link_text (struct document *document, int current_link, int i, char *text, int direction, int *offset)
static void fixup_typeahead_match (struct session *ses, struct document_view *doc_view)
static UCHAR get_document_char (struct document *document, int x, int y)
static void draw_typeahead_match (struct terminal *term, struct document_view *doc_view, int chars, int offset)
static enum typeahead_code do_typeahead (struct session *ses, struct document_view *doc_view, char *text, int action_id, int *offset)

Detailed Description

Searching in the HTML document.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   /* XXX: we _WANT_ strcasestr() ! */

◆ HASH

#define HASH ( p)
Value:
((((p).y << 6) + (p).x) & (HASH_SIZE - 1))
#define HASH_SIZE

◆ HASH_SIZE

#define HASH_SIZE   4096

◆ maybe_tolower [1/3]

#define maybe_tolower ( c)
Value:
(case_sensitive ? (c) : tolower(c))

◆ maybe_tolower [2/3]

#define maybe_tolower ( c)
Value:
(case_sensitive ? (c) : tolower(c))

◆ maybe_tolower [3/3]

#define maybe_tolower ( c)
Value:
(case_sensitive ? (c) : tolower(c))

◆ PATTERN

#define PATTERN   const wchar_t

◆ realloc_points

#define realloc_points ( pts,
size )
Value:
mem_align_alloc(pts, size, (size) + 1, 0xFF)
#define mem_align_alloc(ptr, old, new_, mask)
Definition memory.h:148

◆ Regcomp

#define Regcomp   tre_regwcomp

◆ Regexec

#define Regexec   tre_regwexec

◆ SEARCH_HISTORY_FILENAME

#define SEARCH_HISTORY_FILENAME   "searchhist"

◆ SEARCH_WIDGETS_COUNT

#define SEARCH_WIDGETS_COUNT   5

◆ UCHAR

#define UCHAR   unicode_val_T

Enumeration Type Documentation

◆ find_error

enum find_error
Enumerator
FIND_ERROR_NONE 
FIND_ERROR_NO_PREVIOUS_SEARCH 
FIND_ERROR_HIT_TOP 
FIND_ERROR_HIT_BOTTOM 
FIND_ERROR_NOT_FOUND 
FIND_ERROR_MEMORY 
FIND_ERROR_REGEX 

◆ search_option

Enumerator
SEARCH_OPT_CASE 
SEARCH_OPTIONS 

◆ typeahead_code

Enumerator
TYPEAHEAD_MATCHED 
TYPEAHEAD_ERROR 
TYPEAHEAD_ERROR_NO_FURTHER 
TYPEAHEAD_CANCEL 

Function Documentation

◆ add_srch_chr()

void add_srch_chr ( struct document * document,
UCHAR c,
int x,
int y,
int nn )
inlinestatic

◆ do_typeahead()

enum typeahead_code do_typeahead ( struct session * ses,
struct document_view * doc_view,
char * text,
int action_id,
int * offset )
static

◆ done_search_history()

void done_search_history ( struct module * module)
static

◆ draw_searched()

void draw_searched ( struct terminal * term,
struct document_view * doc_view )

Highlighting of searched strings.

◆ draw_typeahead_match()

void draw_typeahead_match ( struct terminal * term,
struct document_view * doc_view,
int chars,
int offset )
static

◆ find_first_search_in_view()

void find_first_search_in_view ( struct session * ses,
struct document_view * doc_view )
static

◆ find_next()

enum frame_event_status find_next ( struct session * ses,
struct document_view * doc_view,
int direction )

◆ find_next_do()

enum find_error find_next_do ( struct session * ses,
struct document_view * doc_view,
int direction )
static

◆ find_next_link_in_search()

int find_next_link_in_search ( struct document_view * doc_view,
int direction )
static

◆ fixup_typeahead_match()

void fixup_typeahead_match ( struct session * ses,
struct document_view * doc_view )
inlinestatic

◆ get_document_char()

UCHAR get_document_char ( struct document * document,
int x,
int y )
inlinestatic

◆ get_link_typeahead_text()

const char * get_link_typeahead_text ( struct link * link)
inlinestatic

◆ get_range()

int get_range ( struct document * document,
int y,
int height,
int l,
struct search ** s1,
struct search ** s2 )
static

Assign s1 and s2 the first search node and the last search node needed to form the region starting at line y and ending at the greater of y + height and the end of the document, with allowance at the start to allow for multi-line matches that would otherwise be partially outside of the region.

Returns
-1 on assertion failure, 1 if s1 and s2 are not found, and 0 if they are found.

◆ get_search_data()

void get_search_data ( struct document * document)
static

◆ get_searched()

void get_searched ( struct document_view * doc_view,
struct point ** pt,
int * pl,
int utf8 )
static

◆ get_searched_all()

enum find_error get_searched_all ( struct session * ses,
struct document_view * doc_view,
struct point ** pt,
int * pl,
int utf8 )
static

◆ get_searched_plain()

void get_searched_plain ( struct document_view * doc_view,
struct point ** pt,
int * pl,
int l,
struct search * s1,
struct search * s2,
int utf8 )
static

◆ get_searched_plain_all()

void get_searched_plain_all ( struct document_view * doc_view,
struct point ** pt,
int * pl,
int l,
struct search * s1,
struct search * s2,
int utf8 )
static

◆ get_srch()

int get_srch ( struct document * document)
static

◆ INIT_INPUT_HISTORY()

INIT_INPUT_HISTORY ( search_history )
static

◆ init_search_history()

void init_search_history ( struct module * module)
static

◆ is_in_range()

int is_in_range ( struct document * document,
int y,
int height,
char * text,
int * min,
int * max )
static

◆ is_in_range_plain()

int is_in_range_plain ( struct document * document,
int y,
int height,
char * text,
int textlen,
int * min,
int * max,
struct search * s1,
struct search * s2,
int utf8 )
static

◆ is_y_on_screen()

int is_y_on_screen ( struct document_view * doc_view,
int y )
static

◆ link_typeahead_handler()

enum input_line_code link_typeahead_handler ( struct input_line * line,
int action_id )
static

◆ lowered_string()

UCHAR * lowered_string ( char * text,
int textlen,
int utf8 )
static

Returns an allocated string which is a lowered copy of passed one.

◆ match_link_text()

int match_link_text ( struct link * link,
char * text,
int textlen,
int case_sensitive )
static

◆ memacpy_u()

UCHAR * memacpy_u ( char * text,
int textlen,
int utf8 )
static

◆ move_search_do()

enum frame_event_status move_search_do ( struct session * ses,
struct document_view * doc_view,
int direction )
static

◆ move_search_next()

enum frame_event_status move_search_next ( struct session * ses,
struct document_view * doc_view )

◆ move_search_number()

enum find_error move_search_number ( struct session * ses,
struct document_view * doc_view,
int number )
static

◆ move_search_prev()

enum frame_event_status move_search_prev ( struct session * ses,
struct document_view * doc_view )

◆ point_intersect()

int point_intersect ( struct point * p1,
int l1,
struct point * p2,
int l2 )
inlinestatic

◆ print_find_error() [1/2]

void print_find_error ( struct session * ses,
enum find_error find_error )
static

◆ print_find_error() [2/2]

void print_find_error ( struct session * ses,
enum find_error find_error )
static

◆ print_find_error_not_found()

void print_find_error_not_found ( struct session * ses,
char * title,
char * message,
char * search_string )
static

◆ search_dlg()

enum frame_event_status search_dlg ( struct session * ses,
struct document_view * doc_view,
int direction )

◆ search_dlg_cancel()

widget_handler_status_T search_dlg_cancel ( struct dialog_data * dlg_data,
struct widget_data * widget_data )
static

◆ search_dlg_do()

void search_dlg_do ( struct terminal * term,
struct memory_list * ml,
char * title,
void * data,
struct input_history * history,
void(* fn )(void *, char *) )
static

◆ search_dlg_ok()

widget_handler_status_T search_dlg_ok ( struct dialog_data * dlg_data,
struct widget_data * widget_data )
static

◆ search_for()

void search_for ( struct session * ses,
const char * str )

◆ search_for_back()

void search_for_back ( struct session * ses,
const char * str )
static

◆ search_for_do()

enum find_error search_for_do ( struct session * ses,
const char * str,
int direction,
int report_errors )
static

◆ search_history_write_hook()

enum evhook_status search_history_write_hook ( va_list ap,
void * data )
static

◆ search_link_text()

int search_link_text ( struct document * document,
int current_link,
int i,
char * text,
int direction,
int * offset )
inlinestatic

◆ search_typeahead()

enum frame_event_status search_typeahead ( struct session * ses,
struct document_view * doc_view,
action_id_T action_id )

◆ sort_srch()

void sort_srch ( struct document * document)
static

◆ strlen_u()

int strlen_u ( char * text,
int utf8 )
static

◆ text_typeahead_handler()

enum input_line_code text_typeahead_handler ( struct input_line * line,
int action_id )
static

action_id can be a value from enum edit_action, in which case the approriate action is performed; -1, which indicates to search and report any errors; or -2, which indicates to search without reporting any errors.

◆ typeahead_error()

void typeahead_error ( struct session * ses,
char * typeahead,
int no_further )
static

Variable Documentation

◆ resolvers

struct option_resolver resolvers[]
static
Initial value:
= {
{ SEARCH_OPT_CASE, "case" },
}
@ SEARCH_OPT_CASE
Definition search.c:1867

◆ search_history_hooks

struct event_hook_info search_history_hooks[]
static
Initial value:
= {
{ "periodic-saving", 0, search_history_write_hook, {NULL} },
}
#define NULL
Definition explodename.c:35
#define NULL_EVENT_HOOK_INFO
Definition event.h:88
static enum evhook_status search_history_write_hook(va_list ap, void *data)
Definition search.c:2006

◆ search_history_module

struct module search_history_module
Initial value:
N_("Search History"),
)
#define N_(msg)
Definition libintl.h:25
#define struct_module(name, options, hooks, submods, data, init, done, getname)
Definition module.h:47
static void init_search_history(struct module *module)
Definition search.c:2019
static void done_search_history(struct module *module)
Definition search.c:2025
static struct event_hook_info search_history_hooks[]
Definition search.c:2012