FLTK 1.5.0
Loading...
Searching...
No Matches
filename.H
Go to the documentation of this file.
1/*
2 * Filename header file for the Fast Light Tool Kit (FLTK).
3 *
4 * Copyright 1998-2023 by Bill Spitzak and others.
5 *
6 * This library is free software. Distribution and use rights are outlined in
7 * the file "COPYING" which should have been included with this file. If this
8 * file is missing or damaged, see the license at:
9 *
10 * https://www.fltk.org/COPYING.php
11 *
12 * Please see the following page on how to report bugs and issues:
13 *
14 * https://www.fltk.org/bugs.php
15 */
16
17/*
18 * Note to devs:
19 * Under Windows, we include filename.H from numericsort.c; this should probably change.
20 * This implies that we need C-style comments and '#ifdef __cplusplus ... #endif'
21 */
22
27#ifndef FL_FILENAME_H
28# define FL_FILENAME_H
29
30#include "Fl_Export.H"
31#include <FL/platform_types.h>
32
33#ifdef __cplusplus
34
35// The following include is not (yet) used in FLTK 1.4
36// In FLTK 1.5 or 4.0 using std::string would be default.
37// #include <string>
38
39#endif /* __cplusplus */
40
45# define FL_PATH_MAX 2048
61FL_EXPORT const char *fl_filename_name(const char * filename);
62FL_EXPORT const char *fl_filename_ext(const char *buf);
63FL_EXPORT char *fl_filename_setext(char *to, int tolen, const char *ext);
64FL_EXPORT int fl_filename_expand(char *to, int tolen, const char *from);
65FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from);
66FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from);
67FL_EXPORT int fl_filename_match(const char *name, const char *pattern);
68FL_EXPORT int fl_filename_isdir(const char *name);
69
70# if defined(__cplusplus)
71
72FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from, const char *cwd);
73FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from, const char *cwd);
74
75#include <string>
76
77FL_EXPORT std::string fl_filename_name_str(const std::string &filename);
78FL_EXPORT std::string fl_filename_path_str(const std::string &filename);
79FL_EXPORT std::string fl_filename_ext_str(const std::string &filename);
80FL_EXPORT std::string fl_filename_setext_str(const std::string &filename, const std::string &new_extension);
81FL_EXPORT std::string fl_filename_expand_str(const std::string &from);
82FL_EXPORT std::string fl_filename_absolute_str(const std::string &from);
83FL_EXPORT std::string fl_filename_absolute_str(const std::string &from, const std::string &base);
84FL_EXPORT std::string fl_filename_relative_str(const std::string &from);
85FL_EXPORT std::string fl_filename_relative_str(const std::string &from, const std::string &base);
86FL_EXPORT std::string fl_getcwd_str();
87
88# endif /* defined(__cplusplus) */
89
90# if defined(__cplusplus) && !defined(FL_DOXYGEN)
91/*
92 * Under Windows, we include filename.H from numericsort.c; this should probably change...
93 */
94
95inline char *fl_filename_setext(char *to, const char *ext) { return fl_filename_setext(to, FL_PATH_MAX, ext); }
96inline int fl_filename_expand(char *to, const char *from) { return fl_filename_expand(to, FL_PATH_MAX, from); }
97inline int fl_filename_absolute(char *to, const char *from) { return fl_filename_absolute(to, FL_PATH_MAX, from); }
98inline int fl_filename_relative(char *to, const char *from) { return fl_filename_relative(to, FL_PATH_MAX, from); }
99# endif /* __cplusplus */
100
101# if defined (__cplusplus)
102extern "C" {
103# endif /* __cplusplus */
104
105# if !defined(FL_DOXYGEN)
106FL_EXPORT int fl_alphasort(struct dirent **, struct dirent **);
107FL_EXPORT int fl_casealphasort(struct dirent **, struct dirent **);
108FL_EXPORT int fl_casenumericsort(struct dirent **, struct dirent **);
109FL_EXPORT int fl_numericsort(struct dirent **, struct dirent **);
110# endif
111
112typedef int (Fl_File_Sort_F)(struct dirent **, struct dirent **);
114# if defined(__cplusplus)
115}
116
117/*
118 * Portable "scandir" function. Ugly but necessary...
119 */
120
121FL_EXPORT int fl_filename_list(const char *d, struct dirent ***l,
123FL_EXPORT void fl_filename_free_list(struct dirent ***l, int n);
124
125/*
126 * Generic function to open a Uniform Resource Identifier (URI) using a
127 * system-defined program (added in FLTK 1.1.8)
128 */
129
130FL_EXPORT int fl_open_uri(const char *uri, char *msg = (char *)0,
131 int msglen = 0);
132
133FL_EXPORT void fl_decode_uri(char *uri);
134
135# endif /* __cplusplus */
136
137/*
138 * Note: FLTK 1.0.x compatibility definitions (FLTK_1_0_COMPAT) dropped in 1.4.0
139 */
140
141#endif /* FL_FILENAME_H */
142
std::string fl_filename_setext_str(const std::string &filename, const std::string &new_extension)
Return a copy of the old filename with the new extension.
Definition filename_absolute.cxx:339
int fl_filename_expand(char *to, int tolen, const char *from)
Expands a filename containing shell variables and tilde (~).
Definition filename_expand.cxx:42
#define FL_PATH_MAX
all path buffers should use this length
Definition filename.H:45
std::string fl_filename_path_str(const std::string &filename)
Return a new string that contains the path part of the filename.
Definition filename_absolute.cxx:311
int fl_filename_isdir(const char *name)
Determines if a file exists and is a directory from its filename.
Definition filename_isdir.cxx:36
std::string fl_getcwd_str()
Cross-platform function to get the current working directory as a UTF-8 encoded value in an std::stri...
Definition filename_absolute.cxx:413
int Fl_File_Sort_F(struct dirent **, struct dirent **)
File sorting function.
Definition filename.H:112
const char * fl_filename_name(const char *filename)
Gets the file name from a path.
Definition Fl.cxx:2193
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:68
void fl_decode_uri(char *uri)
Decodes a URL-encoded string.
Definition fl_open_uri.cxx:113
std::string fl_filename_name_str(const std::string &filename)
Return a new string that contains the name part of the filename.
Definition filename_absolute.cxx:301
std::string fl_filename_absolute_str(const std::string &from)
Makes a filename absolute from a filename relative to the current working directory.
Definition filename_absolute.cxx:364
std::string fl_filename_relative_str(const std::string &from)
Makes a filename relative to the current working directory.
Definition filename_absolute.cxx:390
int fl_filename_relative(char *to, int tolen, const char *from)
Makes a filename relative to the current working directory.
Definition filename_absolute.cxx:172
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:74
int fl_filename_match(const char *name, const char *pattern)
Checks if a string s matches a pattern p.
Definition filename_match.cxx:49
std::string fl_filename_expand_str(const std::string &from)
Expands a filename containing shell variables and tilde (~).
Definition filename_absolute.cxx:352
const char * fl_filename_ext(const char *buf)
Gets the extension of a filename.
Definition filename_ext.cxx:31
std::string fl_filename_ext_str(const std::string &filename)
Return a new string that contains the filename extension.
Definition filename_absolute.cxx:328
char * fl_filename_setext(char *to, int tolen, const char *ext)
Replaces the extension in buf of max.
Definition filename_setext.cxx:38
int fl_filename_absolute(char *to, int tolen, const char *from)
Makes a filename absolute from a relative filename to the current working directory.
Definition filename_absolute.cxx:46
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:81
int fl_casenumericsort(struct dirent **A, struct dirent **B)
Compares directory entries alphanumerically (case-insensitive).
Definition numericsort.c:90
int fl_numericsort(struct dirent **A, struct dirent **B)
Compares directory entries alphanumerically (case-sensitive).
Definition numericsort.c:127
Definitions of platform-dependent types.