FLTK 1.4.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
76// FIXME: We can't do this in 1.4.x - enable this block in 1.5 or higher.
77// See fluid/fluid_filename.{h|cxx} for an implementation using Fl_String.
78
79// FL_EXPORT std::string fl_filename_name(const std::string &filename);
80// FL_EXPORT std::string fl_filename_path(const std::string &filename);
81// FL_EXPORT std::string fl_filename_ext(const std::string &filename);
82// FL_EXPORT std::string fl_filename_setext(const std::string &filename, const std::string &new_extension);
83// FL_EXPORT std::string fl_filename_expand(const std::string &from);
84// FL_EXPORT std::string fl_filename_absolute(const std::string &from);
85// FL_EXPORT std::string fl_filename_absolute(const std::string &from, const std::string &base);
86// FL_EXPORT std::string fl_filename_relative(const std::string &from);
87// FL_EXPORT std::string fl_filename_relative(const std::string &from, const std::string &base);
88// FL_EXPORT std::string fl_getcwd();
89
90# endif /* defined(__cplusplus) */
91
92# if defined(__cplusplus) && !defined(FL_DOXYGEN)
93/*
94 * Under Windows, we include filename.H from numericsort.c; this should probably change...
95 */
96
97inline char *fl_filename_setext(char *to, const char *ext) { return fl_filename_setext(to, FL_PATH_MAX, ext); }
98inline int fl_filename_expand(char *to, const char *from) { return fl_filename_expand(to, FL_PATH_MAX, from); }
99inline int fl_filename_absolute(char *to, const char *from) { return fl_filename_absolute(to, FL_PATH_MAX, from); }
100inline int fl_filename_relative(char *to, const char *from) { return fl_filename_relative(to, FL_PATH_MAX, from); }
101# endif /* __cplusplus */
102
103# if defined (__cplusplus)
104extern "C" {
105# endif /* __cplusplus */
106
107# if !defined(FL_DOXYGEN)
108FL_EXPORT int fl_alphasort(struct dirent **, struct dirent **);
109FL_EXPORT int fl_casealphasort(struct dirent **, struct dirent **);
110FL_EXPORT int fl_casenumericsort(struct dirent **, struct dirent **);
111FL_EXPORT int fl_numericsort(struct dirent **, struct dirent **);
112# endif
113
114typedef int (Fl_File_Sort_F)(struct dirent **, struct dirent **);
116# if defined(__cplusplus)
117}
118
119/*
120 * Portable "scandir" function. Ugly but necessary...
121 */
122
123FL_EXPORT int fl_filename_list(const char *d, struct dirent ***l,
125FL_EXPORT void fl_filename_free_list(struct dirent ***l, int n);
126
127/*
128 * Generic function to open a Uniform Resource Identifier (URI) using a
129 * system-defined program (added in FLTK 1.1.8)
130 */
131
132FL_EXPORT int fl_open_uri(const char *uri, char *msg = (char *)0,
133 int msglen = 0);
134
135FL_EXPORT void fl_decode_uri(char *uri);
136
137# endif /* __cplusplus */
138
139/*
140 * Note: FLTK 1.0.x compatibility definitions (FLTK_1_0_COMPAT) dropped in 1.4.0
141 */
142
143#endif /* FL_FILENAME_H */
144
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
int fl_filename_isdir(const char *name)
Determines if a file exists and is a directory from its filename.
Definition filename_isdir.cxx:36
const char * fl_filename_name(const char *filename)
Gets the file name from a path.
Definition Fl.cxx:2089
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
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
int() Fl_File_Sort_F(struct dirent **, struct dirent **)
File sorting function.
Definition filename.H:114
const char * fl_filename_ext(const char *buf)
Gets the extension of a filename.
Definition filename_ext.cxx:31
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:91
int fl_numericsort(struct dirent **A, struct dirent **B)
Compares directory entries alphanumerically (case-sensitive).
Definition numericsort.c:128
Definitions of platform-dependent types.