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 7 This file is part of groff. 8 9 groff is free software; you can redistribute it and/or modify it under 10 the terms of the GNU General Public License as published by the Free 11 Software Foundation; either version 2, or (at your option) any later 12 version. 13 14 groff is distributed in the hope that it will be useful, but WITHOUT ANY 15 WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 for more details. 18 19 You should have received a copy of the GNU General Public License along 20 with groff; see the file COPYING. If not, write to the Free Software 21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23 class search_item; 24 class search_item_iterator; 25 26 class search_list { 27 public: 28 search_list(); 29 ~search_list(); 30 void add_file(const char *fn, int silent = 0); 31 int nfiles() const; 32 private: 33 search_item *list; 34 int niterators; 35 int next_fid; 36 friend class search_list_iterator; 37 }; 38 39 class bmpattern; 40 41 class 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; 52 public: 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 60 class search_list_iterator { 61 search_list *list; 62 search_item *ptr; 63 search_item_iterator *iter; 64 char *query; 65 linear_searcher searcher; 66 public: 67 search_list_iterator(search_list *, const char *query); 68 ~search_list_iterator(); 69 int next(const char **, int *, reference_id * = 0); 70 }; 71 72 class search_item { 73 protected: 74 char *name; 75 int filename_id; 76 public: 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 85 class search_item_iterator { 86 char shut_g_plus_plus_up; 87 public: 88 virtual ~search_item_iterator(); 89 virtual int next(const linear_searcher &, const char **ptr, int *lenp, 90 reference_id *) = 0; 91 }; 92 93 search_item *make_index_search_item(const char *filename, int fid); 94 search_item *make_linear_search_item(int fd, const char *filename, int fid); 95 96 extern int linear_truncate_len; 97 extern const char *linear_ignore_fields; 98 extern int verify_flag; 99