slist.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* slist.h -- generalised singly linked lists
  2. Copyright (C) 2000, 2004, 2009, 2011-2015 Free Software Foundation,
  3. Inc.
  4. Written by Gary V. Vaughan, 2000
  5. NOTE: The canonical source of this file is maintained with the
  6. GNU Libtool package. Report bugs to bug-libtool@gnu.org.
  7. GNU Libltdl is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2 of the License, or (at your option) any later version.
  11. As a special exception to the GNU Lesser General Public License,
  12. if you distribute this file as part of a program or library that
  13. is built using GNU Libtool, you may include this file under the
  14. same distribution terms that you use for the rest of that program.
  15. GNU Libltdl is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU Lesser General Public License for more details.
  19. You should have received a copy of the GNU Lesser General Public
  20. License along with GNU Libltdl; see the file COPYING.LIB. If not, a
  21. copy can be downloaded from http://www.gnu.org/licenses/lgpl.html,
  22. or obtained by writing to the Free Software Foundation, Inc.,
  23. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  24. */
  25. /* A generalised list. This is deliberately transparent so that you
  26. can make the NEXT field of all your chained data structures first,
  27. and then cast them to '(SList *)' so that they can be manipulated
  28. by this API.
  29. Alternatively, you can generate raw SList elements using slist_new(),
  30. and put the element data in the USERDATA field. Either way you
  31. get to manage the memory involved by yourself.
  32. */
  33. #if !defined SLIST_H
  34. #define SLIST_H 1
  35. #if defined LTDL
  36. # include <libltdl/lt__glibc.h>
  37. # include <libltdl/lt_system.h>
  38. #else
  39. # define LT_SCOPE
  40. #endif
  41. #include <stddef.h>
  42. #if defined __cplusplus
  43. extern "C" {
  44. #endif
  45. typedef struct slist {
  46. struct slist *next; /* chain forward pointer*/
  47. const void *userdata; /* for boxed 'SList' item */
  48. } SList;
  49. typedef void * SListCallback (SList *item, void *userdata);
  50. typedef int SListCompare (const SList *item1, const SList *item2,
  51. void *userdata);
  52. LT_SCOPE SList *slist_concat (SList *head, SList *tail);
  53. LT_SCOPE SList *slist_cons (SList *item, SList *slist);
  54. LT_SCOPE SList *slist_delete (SList *slist, void (*delete_fct) (void *item));
  55. LT_SCOPE SList *slist_remove (SList **phead, SListCallback *find,
  56. void *matchdata);
  57. LT_SCOPE SList *slist_reverse (SList *slist);
  58. LT_SCOPE SList *slist_sort (SList *slist, SListCompare *compare,
  59. void *userdata);
  60. LT_SCOPE SList *slist_tail (SList *slist);
  61. LT_SCOPE SList *slist_nth (SList *slist, size_t n);
  62. LT_SCOPE void * slist_find (SList *slist, SListCallback *find,
  63. void *matchdata);
  64. LT_SCOPE size_t slist_length (SList *slist);
  65. LT_SCOPE void * slist_foreach (SList *slist, SListCallback *foreach,
  66. void *userdata);
  67. LT_SCOPE SList *slist_box (const void *userdata);
  68. LT_SCOPE void * slist_unbox (SList *item);
  69. #if defined __cplusplus
  70. }
  71. #endif
  72. #if !defined LTDL
  73. # undef LT_SCOPE
  74. #endif
  75. #endif /*!defined SLIST_H*/