kwset.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef KWSET_H
  2. #define KWSET_H
  3. /* This file has been copied from commit e7ac713d^ in the GNU grep git
  4. * repository. A few small changes have been made to adapt the code to
  5. * Git.
  6. */
  7. /* kwset.h - header declaring the keyword set library.
  8. Copyright (C) 1989, 1998, 2005 Free Software Foundation, Inc.
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2, or (at your option)
  12. any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  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. /* Written August 1989 by Mike Haertel.
  20. The author may be reached (Email) at the address mike@ai.mit.edu,
  21. or (US mail) as Mike Haertel c/o Free Software Foundation. */
  22. struct kwsmatch
  23. {
  24. int index; /* Index number of matching keyword. */
  25. size_t offset[1]; /* Offset of each submatch. */
  26. size_t size[1]; /* Length of each submatch. */
  27. };
  28. struct kwset_t;
  29. typedef struct kwset_t* kwset_t;
  30. /* Return an opaque pointer to a newly allocated keyword set, or NULL
  31. if enough memory cannot be obtained. The argument if non-NULL
  32. specifies a table of character translations to be applied to all
  33. pattern and search text. */
  34. kwset_t kwsalloc(unsigned char const *);
  35. /* Incrementally extend the keyword set to include the given string.
  36. Return NULL for success, or an error message. Remember an index
  37. number for each keyword included in the set. */
  38. const char *kwsincr(kwset_t, char const *, size_t);
  39. /* When the keyword set has been completely built, prepare it for
  40. use. Return NULL for success, or an error message. */
  41. const char *kwsprep(kwset_t);
  42. /* Search through the given buffer for a member of the keyword set.
  43. Return a pointer to the leftmost longest match found, or NULL if
  44. no match is found. If foundlen is non-NULL, store the length of
  45. the matching substring in the integer it points to. Similarly,
  46. if foundindex is non-NULL, store the index of the particular
  47. keyword found therein. */
  48. size_t kwsexec(kwset_t, char const *, size_t, struct kwsmatch *);
  49. /* Deallocate the given keyword set and all its associated storage. */
  50. void kwsfree(kwset_t);
  51. #endif /* KWSET_H */