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