NTK 1.3.0
filename.H
1/*
2 * "$Id: filename.H 8073 2010-12-20 13:35:43Z ianmacarthur $"
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; 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
28/* Xcode on OS X includes files by recursing down into directories.
29 * This code catches the cycle and directly includes the required file.
30 */
31#ifdef fl_dirent_h_cyclic_include
32# include "/usr/include/dirent.h"
33#endif
34
35#ifndef FL_FILENAME_H
36# define FL_FILENAME_H
37
38# include "Fl_Export.H"
39
44# define FL_PATH_MAX 2048
60FL_EXPORT const char *fl_filename_name(const char * filename);
61FL_EXPORT const char *fl_filename_ext(const char *buf);
62FL_EXPORT char *fl_filename_setext(char *to, int tolen, const char *ext);
63FL_EXPORT int fl_filename_expand(char *to, int tolen, const char *from);
64FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from);
65FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from);
66FL_EXPORT int fl_filename_match(const char *name, const char *pattern);
67FL_EXPORT int fl_filename_isdir(const char *name);
68
69# if defined(__cplusplus) && !defined(FL_DOXYGEN)
70/*
71 * Under WIN32, we include filename.H from numericsort.c; this should probably change...
72 */
73
74inline char *fl_filename_setext(char *to, const char *ext) { return fl_filename_setext(to, FL_PATH_MAX, ext); }
75inline int fl_filename_expand(char *to, const char *from) { return fl_filename_expand(to, FL_PATH_MAX, from); }
76inline int fl_filename_absolute(char *to, const char *from) { return fl_filename_absolute(to, FL_PATH_MAX, from); }
77FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from, const char *cwd);
78inline int fl_filename_relative(char *to, const char *from) { return fl_filename_relative(to, FL_PATH_MAX, from); }
79# endif /* __cplusplus */
80
81
82# if defined(WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
83
84struct dirent {char d_name[1];};
85
86# elif defined(__WATCOMC__)
87# include <sys/types.h>
88# include <direct.h>
89
90# else
91/*
92 * WARNING: on some systems (very few nowadays?) <dirent.h> may not exist.
93 * The correct information is in one of these files:
94 *
95 * #include <sys/ndir.h>
96 * #include <sys/dir.h>
97 * #include <ndir.h>
98 *
99 * plus you must do the following #define:
100 *
101 * #define dirent direct
102 *
103 * It would be best to create a <dirent.h> file that does this...
104 */
105# include <sys/types.h>
106# define fl_dirent_h_cyclic_include
107# include <dirent.h>
108# undef fl_dirent_h_cyclic_include
109# endif
110
111# if defined (__cplusplus)
112extern "C" {
113# endif /* __cplusplus */
114
115# if !defined(FL_DOXYGEN)
116FL_EXPORT int fl_alphasort(struct dirent **, struct dirent **);
117FL_EXPORT int fl_casealphasort(struct dirent **, struct dirent **);
118FL_EXPORT int fl_casenumericsort(struct dirent **, struct dirent **);
119FL_EXPORT int fl_numericsort(struct dirent **, struct dirent **);
120# endif
121
122 typedef int (Fl_File_Sort_F)(struct dirent **, struct dirent **);
124# if defined(__cplusplus)
125}
126
127/*
128 * Portable "scandir" function. Ugly but necessary...
129 */
130
131FL_EXPORT int fl_filename_list(const char *d, struct dirent ***l,
132 Fl_File_Sort_F *s = fl_numericsort);
133FL_EXPORT void fl_filename_free_list(struct dirent ***l, int n);
134
135/*
136 * Generic function to open a Uniform Resource Identifier (URI) using a
137 * system-defined program (added in FLTK 1.1.8)
138 */
139
140FL_EXPORT int fl_open_uri(const char *uri, char *msg = (char *)0,
141 int msglen = 0);
142
143# ifndef FL_DOXYGEN
144/*
145 * _fl_filename_isdir_quick() is a private function that checks for a
146 * trailing slash and assumes that the passed name is a directory if
147 * it finds one. This function is used by Fl_File_Browser and
148 * Fl_File_Chooser to avoid extra stat() calls, but is not supported
149 * outside of FLTK...
150 */
151int _fl_filename_isdir_quick(const char *name);
152# endif
153
154# endif /* __cplusplus */
155
156/*
157 * FLTK 1.0.x compatibility definitions...
158 */
159
160# ifdef FLTK_1_0_COMPAT
161# define filename_absolute fl_filename_absolute
162# define filename_expand fl_filename_expand
163# define filename_ext fl_filename_ext
164# define filename_isdir fl_filename_isdir
165# define filename_list fl_filename_list
166# define filename_match fl_filename_match
167# define filename_name fl_filename_name
168# define filename_relative fl_filename_relative
169# define filename_setext fl_filename_setext
170# define numericsort fl_numericsort
171# endif /* FLTK_1_0_COMPAT */
172
173
174#endif /* FL_FILENAME_H */
175
178/*
179 * End of "$Id: filename.H 8073 2010-12-20 13:35:43Z ianmacarthur $".
180 */
#define FL_PATH_MAX
all path buffers should use this length
Definition: filename.H:44
FL_EXPORT char * fl_filename_setext(char *to, int tolen, const char *ext)
Replaces the extension in buf of max.
Definition: filename_setext.cxx:49
FL_EXPORT int fl_filename_list(const char *d, struct dirent ***l, Fl_File_Sort_F *s=fl_numericsort)
Portable and const-correct wrapper for the scandir() function.
Definition: filename_list.cxx:82
FL_EXPORT const char * fl_filename_ext(const char *buf)
Gets the extensions of a filename.
Definition: filename_ext.cxx:43
FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from)
Makes a filename absolute from a relative filename.
Definition: filename_absolute.cxx:65
FL_EXPORT const char * fl_filename_name(const char *filename)
Gets the file name from a path.
FL_EXPORT int fl_open_uri(const char *uri, char *msg=(char *) 0, int msglen=0)
Opens the specified Uniform Resource Identifier (URI).
Definition: fl_open_uri.cxx:95
int() Fl_File_Sort_F(struct dirent **, struct dirent **)
File sorting function.
Definition: filename.H:122
FL_EXPORT int fl_filename_expand(char *to, int tolen, const char *from)
Expands a filename containing shell variables and tilde (~).
Definition: filename_expand.cxx:72
FL_EXPORT int fl_filename_match(const char *name, const char *pattern)
Checks if a string s matches a pattern p.
Definition: filename_match.cxx:53
FL_EXPORT void fl_filename_free_list(struct dirent ***l, int n)
Free the list of filenames that is generated by fl_filename_list().
Definition: filename_list.cxx:190
FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from)
Makes a filename relative to the current working directory.
Definition: filename_absolute.cxx:137
FL_EXPORT int fl_filename_isdir(const char *name)
Determines if a file exists and is a directory from its filename.
Definition: filename_isdir.cxx:61