🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
6.5 KiB

  1. #ifndef INCL_PHYSFSEXT_GLOBBING_H
  2. #define INCL_PHYSFSEXT_GLOBBING_H
  3. /** \file globbing.h */
  4. #include "physfs.h"
  5. /**
  6. * \mainpage PhysicsFS globbing
  7. *
  8. * This is an extension to PhysicsFS to let you search for files with basic
  9. * wildcard matching, regardless of what sort of filesystem or archive they
  10. * reside in. It does this by enumerating directories as needed and manually
  11. * locating matching entries.
  12. *
  13. * Usage: Set up PhysicsFS as you normally would, then use
  14. * PHYSFSEXT_enumerateFilesWildcard() when enumerating files. This is just
  15. * like PHYSFS_enumerateFiles(), but it returns a subset that matches your
  16. * wildcard pattern. You must call PHYSFSEXT_freeEnumeration() on the results,
  17. * just PHYSFS_enumerateFiles() would do with PHYSFS_freeList().
  18. *
  19. * License: this code is public domain. I make no warranty that it is useful,
  20. * correct, harmless, or environmentally safe.
  21. *
  22. * This particular file may be used however you like, including copying it
  23. * verbatim into a closed-source project, exploiting it commercially, and
  24. * removing any trace of my name from the source (although I hope you won't
  25. * do that). I welcome enhancements and corrections to this file, but I do
  26. * not require you to send me patches if you make changes. This code has
  27. * NO WARRANTY.
  28. *
  29. * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
  30. * Please see LICENSE.txt in the source's "docs" directory.
  31. *
  32. * \author Ryan C. Gordon.
  33. */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /**
  38. * \fn char **PHYSFS_enumerateFilesWildcard(const char *dir, const char *wildcard, int caseSensitive)
  39. * \brief Get a file listing of a search path's directory, filtered with a wildcard pattern.
  40. *
  41. * Matching directories are interpolated. That is, if "C:\mydir" is in the
  42. * search path and contains a directory "savegames" that contains "x.sav",
  43. * "y.Sav", and "z.txt", and there is also a "C:\userdir" in the search path
  44. * that has a "savegames" subdirectory with "w.sav", then the following code:
  45. *
  46. * \code
  47. * char **rc = PHYSFS_enumerateFilesWildcard("savegames", "*.sav", 0);
  48. * char **i;
  49. *
  50. * for (i = rc; *i != NULL; i++)
  51. * printf(" * We've got [%s].\n", *i);
  52. *
  53. * PHYSFS_freeList(rc);
  54. * \endcode
  55. *
  56. * ...will print:
  57. *
  58. * \verbatim
  59. * We've got [x.sav].
  60. * We've got [y.Sav].
  61. * We've got [w.sav].\endverbatim
  62. *
  63. * Feel free to sort the list however you like. We only promise there will
  64. * be no duplicates, but not what order the final list will come back in.
  65. *
  66. * Wildcard strings can use the '*' and '?' characters, currently.
  67. * Matches can be case-insensitive if you pass a zero for argument 3.
  68. *
  69. * Don't forget to call PHYSFSEXT_freeEnumerator() with the return value from
  70. * this function when you are done with it. As we use PhysicsFS's allocator
  71. * for this list, you must free it before calling PHYSFS_deinit().
  72. * Do not use PHYSFS_freeList() on the returned value!
  73. *
  74. * \param dir directory in platform-independent notation to enumerate.
  75. * \param wildcard Wildcard pattern to use for filtering.
  76. * \param caseSensitive Zero for case-insensitive matching,
  77. * non-zero for case-sensitive.
  78. * \return Null-terminated array of null-terminated strings.
  79. *
  80. * \sa PHYSFSEXT_freeEnumeration
  81. */
  82. PHYSFS_DECL char **PHYSFSEXT_enumerateFilesWildcard(const char *dir,
  83. const char *wildcard,
  84. int caseSensitive);
  85. /**
  86. * \fn void PHYSFSEXT_freeEnumeration(char **list)
  87. * \brief Free data returned by PHYSFSEXT_enumerateFilesWildcard
  88. *
  89. * Conceptually, this works like PHYSFS_freeList(), but is used with data
  90. * returned by PHYSFSEXT_enumerateFilesWildcard() only. Be sure to call this
  91. * on any returned data from that function before
  92. *
  93. * \param list Pointer previously returned by
  94. * PHYSFSEXT_enumerateFilesWildcard(). It is safe to pass a
  95. * NULL here.
  96. *
  97. * \sa PHYSFSEXT_enumerateFilesWildcard
  98. */
  99. PHYSFS_DECL void PHYSFSEXT_freeEnumeration(char **list);
  100. /**
  101. * \fn void PHYSFSEXT_enumerateFilesCallbackWildcard(const char *dir, const char *wildcard, int caseSensitive, PHYSFS_EnumFilesCallback c, void *d);
  102. * \brief Get a file listing of a search path's directory, filtered with a wildcard pattern, using an application-defined callback.
  103. *
  104. * This function is equivalent to PHYSFSEXT_enumerateFilesWildcard(). It
  105. * reports file listings, filtered by a wildcard pattern.
  106. *
  107. * Unlike PHYSFS_enumerateFiles(), this function does not return an array.
  108. * Rather, it calls a function specified by the application once per
  109. * element of the search path:
  110. *
  111. * \code
  112. *
  113. * static void printDir(void *data, const char *origdir, const char *fname)
  114. * {
  115. * printf(" * We've got [%s] in [%s].\n", fname, origdir);
  116. * }
  117. *
  118. * // ...
  119. * PHYSFS_enumerateFilesCallbackWildcard("savegames","*.sav",0,printDir,NULL);
  120. * \endcode
  121. *
  122. * Items sent to the callback are not guaranteed to be in any order whatsoever.
  123. * There is no sorting done at this level, and if you need that, you should
  124. * probably use PHYSFS_enumerateFilesWildcard() instead, which guarantees
  125. * alphabetical sorting. This form reports whatever is discovered in each
  126. * archive before moving on to the next. Even within one archive, we can't
  127. * guarantee what order it will discover data. <em>Any sorting you find in
  128. * these callbacks is just pure luck. Do not rely on it.</em> As this walks
  129. * the entire list of archives, you may receive duplicate filenames.
  130. *
  131. * Wildcard strings can use the '*' and '?' characters, currently.
  132. * Matches can be case-insensitive if you pass a zero for argument 3.
  133. *
  134. * \param dir Directory, in platform-independent notation, to enumerate.
  135. * \param wildcard Wildcard pattern to use for filtering.
  136. * \param caseSensitive Zero for case-insensitive matching,
  137. * non-zero for case-sensitive.
  138. * \param c Callback function to notify about search path elements.
  139. * \param d Application-defined data passed to callback. Can be NULL.
  140. *
  141. * \sa PHYSFS_EnumFilesCallback
  142. * \sa PHYSFS_enumerateFiles
  143. */
  144. PHYSFS_DECL void PHYSFSEXT_enumerateFilesCallbackWildcard(const char *dir,
  145. const char *wildcard,
  146. int caseSensitive,
  147. PHYSFS_EnumFilesCallback c,
  148. void *d);
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* include-once blocker. */
  153. /* end of globbing.h ... */