PageRenderTime 36ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/fltk/FL/filename.H

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