1/*	$NetBSD: search.h,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $	*/
2
3// -*- C++ -*-
4/* Copyright (C) 1989, 1990, 1991, 1992, 2004 Free Software Foundation, Inc.
5     Written by James Clark (jjc@jclark.com)
6
7This file is part of groff.
8
9groff is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 2, or (at your option) any later
12version.
13
14groff is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17for more details.
18
19You should have received a copy of the GNU General Public License along
20with groff; see the file COPYING.  If not, write to the Free Software
21Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
22
23class search_item;
24class search_item_iterator;
25
26class search_list {
27public:
28  search_list();
29  ~search_list();
30  void add_file(const char *fn, int silent = 0);
31  int nfiles() const;
32private:
33  search_item *list;
34  int niterators;
35  int next_fid;
36  friend class search_list_iterator;
37};
38
39class bmpattern;
40
41class linear_searcher {
42  const char *ignore_fields;
43  int truncate_len;
44  bmpattern **keys;
45  int nkeys;
46  const char *search_and_check(const bmpattern *key, const char *buf,
47			       const char *bufend, const char **start = 0)
48    const;
49  int check_match(const char *buf, const char *bufend, const char *match,
50		  int matchlen, const char **cont, const char **start)
51    const;
52public:
53  linear_searcher(const char *query, int query_len,
54		  const char *ign, int trunc);
55  ~linear_searcher();
56  int search(const char *buf, const char *bufend,
57	     const char **startp, int *lengthp) const;
58};
59
60class search_list_iterator {
61  search_list *list;
62  search_item *ptr;
63  search_item_iterator *iter;
64  char *query;
65  linear_searcher searcher;
66public:
67  search_list_iterator(search_list *, const char *query);
68  ~search_list_iterator();
69  int next(const char **, int *, reference_id * = 0);
70};
71
72class search_item {
73protected:
74  char *name;
75  int filename_id;
76public:
77  search_item *next;
78  search_item(const char *nm, int fid);
79  virtual search_item_iterator *make_search_item_iterator(const char *) = 0;
80  virtual ~search_item();
81  int is_named(const char *) const;
82  virtual int next_filename_id() const;
83};
84
85class search_item_iterator {
86  char shut_g_plus_plus_up;
87public:
88  virtual ~search_item_iterator();
89  virtual int next(const linear_searcher &, const char **ptr, int *lenp,
90		   reference_id *) = 0;
91};
92
93search_item *make_index_search_item(const char *filename, int fid);
94search_item *make_linear_search_item(int fd, const char *filename, int fid);
95
96extern int linear_truncate_len;
97extern const char *linear_ignore_fields;
98extern int verify_flag;
99