4 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001
5 Free Software Foundation, Inc.
6 Written by James Clark (jjc@jclark.com)
8 This file is part of groff.
10 groff is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 groff is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License along
21 with groff; see the file COPYING. If not, write to the Free Software
22 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
38 int linear_truncate_len
= 6;
39 const char *linear_ignore_fields
= "XYZ";
41 search_list::search_list()
42 : list(0), niterators(0), next_fid(1)
46 search_list::~search_list()
48 assert(niterators
== 0);
50 search_item
*tem
= list
->next
;
56 void search_list::add_file(const char *filename
, int silent
)
58 search_item
*p
= make_index_search_item(filename
, next_fid
);
60 int fd
= open(filename
, O_RDONLY
| O_BINARY
);
63 error("can't open `%1': %2", filename
, strerror(errno
));
66 p
= make_linear_search_item(fd
, filename
, next_fid
);
70 for (pp
= &list
; *pp
; pp
= &(*pp
)->next
)
73 next_fid
= p
->next_filename_id();
77 int search_list::nfiles() const
80 for (search_item
*ptr
= list
; ptr
; ptr
= ptr
->next
)
85 search_list_iterator::search_list_iterator(search_list
*p
, const char *q
)
86 : list(p
), ptr(p
->list
), iter(0), query(strsave(q
)),
87 searcher(q
, strlen(q
), linear_ignore_fields
, linear_truncate_len
)
89 list
->niterators
+= 1;
92 search_list_iterator::~search_list_iterator()
94 list
->niterators
-= 1;
99 int search_list_iterator::next(const char **pp
, int *lenp
, reference_id
*ridp
)
103 iter
= ptr
->make_search_item_iterator(query
);
104 if (iter
->next(searcher
, pp
, lenp
, ridp
))
113 search_item::search_item(const char *nm
, int fid
)
114 : name(strsave(nm
)), filename_id(fid
), next(0)
118 search_item::~search_item()
123 int search_item::is_named(const char *nm
) const
125 return strcmp(name
, nm
) == 0;
128 int search_item::next_filename_id() const
130 return filename_id
+ 1;
133 search_item_iterator::~search_item_iterator()