filename.H 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * "$Id: filename.H 11555 2016-04-08 15:48:28Z 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. #ifndef FL_FILENAME_H
  22. # define FL_FILENAME_H
  23. #include "Fl_Export.H"
  24. #include <FL/platform_types.h>
  25. /** \addtogroup filenames File names and URI utility functions
  26. File names and URI functions defined in <FL/filename.H>
  27. @{ */
  28. # define FL_PATH_MAX 2048 /**< all path buffers should use this length */
  29. /** Gets the file name from a path.
  30. Similar to basename(3), exceptions shown below.
  31. \code
  32. #include <FL/filename.H>
  33. [..]
  34. const char *out;
  35. out = fl_filename_name("/usr/lib"); // out="lib"
  36. out = fl_filename_name("/usr/"); // out="" (basename(3) returns "usr" instead)
  37. out = fl_filename_name("/usr"); // out="usr"
  38. out = fl_filename_name("/"); // out="" (basename(3) returns "/" instead)
  39. out = fl_filename_name("."); // out="."
  40. out = fl_filename_name(".."); // out=".."
  41. \endcode
  42. \return a pointer to the char after the last slash, or to \p filename if there is none.
  43. */
  44. FL_EXPORT const char *fl_filename_name(const char * filename);
  45. FL_EXPORT const char *fl_filename_ext(const char *buf);
  46. FL_EXPORT char *fl_filename_setext(char *to, int tolen, const char *ext);
  47. FL_EXPORT int fl_filename_expand(char *to, int tolen, const char *from);
  48. FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from);
  49. FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from);
  50. FL_EXPORT int fl_filename_match(const char *name, const char *pattern);
  51. FL_EXPORT int fl_filename_isdir(const char *name);
  52. # if defined(__cplusplus) && !defined(FL_DOXYGEN)
  53. /*
  54. * Under WIN32, we include filename.H from numericsort.c; this should probably change...
  55. */
  56. inline char *fl_filename_setext(char *to, const char *ext) { return fl_filename_setext(to, FL_PATH_MAX, ext); }
  57. inline int fl_filename_expand(char *to, const char *from) { return fl_filename_expand(to, FL_PATH_MAX, from); }
  58. inline int fl_filename_absolute(char *to, const char *from) { return fl_filename_absolute(to, FL_PATH_MAX, from); }
  59. FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from, const char *cwd);
  60. inline int fl_filename_relative(char *to, const char *from) { return fl_filename_relative(to, FL_PATH_MAX, from); }
  61. # endif /* __cplusplus */
  62. # if defined (__cplusplus)
  63. extern "C" {
  64. # endif /* __cplusplus */
  65. # if !defined(FL_DOXYGEN)
  66. FL_EXPORT int fl_alphasort(struct dirent **, struct dirent **);
  67. FL_EXPORT int fl_casealphasort(struct dirent **, struct dirent **);
  68. FL_EXPORT int fl_casenumericsort(struct dirent **, struct dirent **);
  69. FL_EXPORT int fl_numericsort(struct dirent **, struct dirent **);
  70. # endif
  71. typedef int (Fl_File_Sort_F)(struct dirent **, struct dirent **); /**< File sorting function. \see fl_filename_list() */
  72. # if defined(__cplusplus)
  73. }
  74. /*
  75. * Portable "scandir" function. Ugly but necessary...
  76. */
  77. FL_EXPORT int fl_filename_list(const char *d, struct dirent ***l,
  78. Fl_File_Sort_F *s = fl_numericsort);
  79. FL_EXPORT void fl_filename_free_list(struct dirent ***l, int n);
  80. /*
  81. * Generic function to open a Uniform Resource Identifier (URI) using a
  82. * system-defined program (added in FLTK 1.1.8)
  83. */
  84. FL_EXPORT int fl_open_uri(const char *uri, char *msg = (char *)0,
  85. int msglen = 0);
  86. FL_EXPORT void fl_decode_uri(char *uri);
  87. # endif /* __cplusplus */
  88. /*
  89. * FLTK 1.0.x compatibility definitions...
  90. */
  91. # ifdef FLTK_1_0_COMPAT
  92. # define filename_absolute fl_filename_absolute
  93. # define filename_expand fl_filename_expand
  94. # define filename_ext fl_filename_ext
  95. # define filename_isdir fl_filename_isdir
  96. # define filename_list fl_filename_list
  97. # define filename_match fl_filename_match
  98. # define filename_name fl_filename_name
  99. # define filename_relative fl_filename_relative
  100. # define filename_setext fl_filename_setext
  101. # define numericsort fl_numericsort
  102. # endif /* FLTK_1_0_COMPAT */
  103. #endif /* FL_FILENAME_H */
  104. /** @} */
  105. /*
  106. * End of "$Id: filename.H 11555 2016-04-08 15:48:28Z manolo $".
  107. */