2 /* Copyright (C) 1989-2018 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
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.
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
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/>. */
34 int linear_truncate_len = 6;
35 const char *linear_ignore_fields = "XYZ";
37 search_list::search_list()
38 : list(0), niterators(0), next_fid(1)
42 search_list::~search_list()
44 assert(niterators == 0);
46 search_item *tem = list->next;
52 void search_list::add_file(const char *filename, int silent)
54 search_item *p = make_index_search_item(filename, next_fid);
56 int fd = open(filename, O_RDONLY | O_BINARY);
59 error("can't open '%1': %2", filename, strerror(errno));
62 p = make_linear_search_item(fd, filename, next_fid);
66 for (pp = &list; *pp; pp = &(*pp)->next)
69 next_fid = p->next_filename_id();
73 int search_list::nfiles() const
76 for (search_item *ptr = list; ptr; ptr = ptr->next)
81 search_list_iterator::search_list_iterator(search_list *p, const char *q)
82 : list(p), ptr(p->list), iter(0), query(strsave(q)),
83 searcher(q, strlen(q), linear_ignore_fields, linear_truncate_len)
85 list->niterators += 1;
88 search_list_iterator::~search_list_iterator()
90 list->niterators -= 1;
95 int search_list_iterator::next(const char **pp, int *lenp, reference_id *ridp)
99 iter = ptr->make_search_item_iterator(query);
100 if (iter->next(searcher, pp, lenp, ridp))
109 search_item::search_item(const char *nm, int fid)
110 : name(strsave(nm)), filename_id(fid), next(0)
114 search_item::~search_item()
119 int search_item::is_named(const char *nm) const
121 return strcmp(name, nm) == 0;
124 int search_item::next_filename_id() const
126 return filename_id + 1;
129 search_item_iterator::~search_item_iterator()