filename.H 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * "$Id: filename.H 9704 2012-10-19 11:23:51Z manolo $"
  3. *
  4. * Filename header file for the Fast Light Tool Kit (FLTK).
  5. *
  6. * Copyright 1998-2010 by Bill Spitzak and others.
  7. *
  8. * This library is free software. Distribution and use rights are outlined in
  9. * the file "COPYING" which should have been included with this file. If this
  10. * file is missing or damaged, see the license at:
  11. *
  12. * http://www.fltk.org/COPYING.php
  13. *
  14. * Please report all bugs and problems on the following page:
  15. *
  16. * http://www.fltk.org/str.php
  17. */
  18. /** \file
  19. File names and URI utility functions.
  20. */
  21. /* Xcode on OS X includes files by recursing down into directories.
  22. * This code catches the cycle and directly includes the required file.
  23. */
  24. #ifdef fl_dirent_h_cyclic_include
  25. # include "/usr/include/dirent.h"
  26. #endif
  27. #ifndef FL_FILENAME_H
  28. # define FL_FILENAME_H
  29. # include "Fl_Export.H"
  30. /** \addtogroup filenames File names and URI utility functions
  31. File names and URI functions defined in <FL/filename.H>
  32. @{ */
  33. # define FL_PATH_MAX 2048 /**< all path buffers should use this length */
  34. /** Gets the file name from a path.
  35. Similar to basename(3), exceptions shown below.
  36. \code
  37. #include <FL/filename.H>
  38. [..]
  39. const char *out;
  40. out = fl_filename_name("/usr/lib"); // out="lib"
  41. out = fl_filename_name("/usr/"); // out="" (basename(3) returns "usr" instead)
  42. out = fl_filename_name("/usr"); // out="usr"
  43. out = fl_filename_name("/"); // out="" (basename(3) returns "/" instead)
  44. out = fl_filename_name("."); // out="."
  45. out = fl_filename_name(".."); // out=".."
  46. \endcode
  47. \return a pointer to the char after the last slash, or to \p filename if there is none.
  48. */
  49. FL_EXPORT const char *fl_filename_name(const char * filename);
  50. FL_EXPORT const char *fl_filename_ext(const char *buf);
  51. FL_EXPORT char *fl_filename_setext(char *to, int tolen, const char *ext);
  52. FL_EXPORT int fl_filename_expand(char *to, int tolen, const char *from);
  53. FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from);
  54. FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from);
  55. FL_EXPORT int fl_filename_match(const char *name, const char *pattern);
  56. FL_EXPORT int fl_filename_isdir(const char *name);
  57. # if defined(__cplusplus) && !defined(FL_DOXYGEN)
  58. /*
  59. * Under WIN32, we include filename.H from numericsort.c; this should probably change...
  60. */
  61. inline char *fl_filename_setext(char *to, const char *ext) { return fl_filename_setext(to, FL_PATH_MAX, ext); }
  62. inline int fl_filename_expand(char *to, const char *from) { return fl_filename_expand(to, FL_PATH_MAX, from); }
  63. inline int fl_filename_absolute(char *to, const char *from) { return fl_filename_absolute(to, FL_PATH_MAX, from); }
  64. FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from, const char *cwd);
  65. inline int fl_filename_relative(char *to, const char *from) { return fl_filename_relative(to, FL_PATH_MAX, from); }
  66. # endif /* __cplusplus */
  67. # if defined(WIN32) /*&& !defined(__MINGW32__)*/ && !defined(__CYGWIN__) && !defined(__WATCOMC__)
  68. struct dirent {char d_name[1];};
  69. # elif defined(__WATCOMC__)
  70. # include <sys/types.h>
  71. # include <direct.h>
  72. # else
  73. /*
  74. * WARNING: on some systems (very few nowadays?) <dirent.h> may not exist.
  75. * The correct information is in one of these files:
  76. *
  77. * #include <sys/ndir.h>
  78. * #include <sys/dir.h>
  79. * #include <ndir.h>
  80. *
  81. * plus you must do the following #define:
  82. *
  83. * #define dirent direct
  84. *
  85. * It would be best to create a <dirent.h> file that does this...
  86. */
  87. # include <sys/types.h>
  88. # define fl_dirent_h_cyclic_include
  89. # include <dirent.h>
  90. # undef fl_dirent_h_cyclic_include
  91. # endif
  92. # if defined (__cplusplus)
  93. extern "C" {
  94. # endif /* __cplusplus */
  95. # if !defined(FL_DOXYGEN)
  96. FL_EXPORT int fl_alphasort(struct dirent **, struct dirent **);
  97. FL_EXPORT int fl_casealphasort(struct dirent **, struct dirent **);
  98. FL_EXPORT int fl_casenumericsort(struct dirent **, struct dirent **);
  99. FL_EXPORT int fl_numericsort(struct dirent **, struct dirent **);
  100. # endif
  101. typedef int (Fl_File_Sort_F)(struct dirent **, struct dirent **); /**< File sorting function. \see fl_filename_list() */
  102. # if defined(__cplusplus)
  103. }
  104. /*
  105. * Portable "scandir" function. Ugly but necessary...
  106. */
  107. FL_EXPORT int fl_filename_list(const char *d, struct dirent ***l,
  108. Fl_File_Sort_F *s = fl_numericsort);
  109. FL_EXPORT void fl_filename_free_list(struct dirent ***l, int n);
  110. /*
  111. * Generic function to open a Uniform Resource Identifier (URI) using a
  112. * system-defined program (added in FLTK 1.1.8)
  113. */
  114. FL_EXPORT int fl_open_uri(const char *uri, char *msg = (char *)0,
  115. int msglen = 0);
  116. FL_EXPORT void fl_decode_uri(char *uri);
  117. # ifndef FL_DOXYGEN
  118. /*
  119. * _fl_filename_isdir_quick() is a private function that checks for a
  120. * trailing slash and assumes that the passed name is a directory if
  121. * it finds one. This function is used by Fl_File_Browser and
  122. * Fl_File_Chooser to avoid extra stat() calls, but is not supported
  123. * outside of FLTK...
  124. */
  125. int _fl_filename_isdir_quick(const char *name);
  126. # endif
  127. # endif /* __cplusplus */
  128. /*
  129. * FLTK 1.0.x compatibility definitions...
  130. */
  131. # ifdef FLTK_1_0_COMPAT
  132. # define filename_absolute fl_filename_absolute
  133. # define filename_expand fl_filename_expand
  134. # define filename_ext fl_filename_ext
  135. # define filename_isdir fl_filename_isdir
  136. # define filename_list fl_filename_list
  137. # define filename_match fl_filename_match
  138. # define filename_name fl_filename_name
  139. # define filename_relative fl_filename_relative
  140. # define filename_setext fl_filename_setext
  141. # define numericsort fl_numericsort
  142. # endif /* FLTK_1_0_COMPAT */
  143. #endif /* FL_FILENAME_H */
  144. /** @} */
  145. /*
  146. * End of "$Id: filename.H 9704 2012-10-19 11:23:51Z manolo $".
  147. */