fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

File names and URI utility functions

Defines

#define FL_PATH_MAX   2048
#define fl_dirent_h_cyclic_include

Typedefs

typedef int( Fl_File_Sort_F )(struct dirent **, struct dirent **)

Functions

FL_EXPORT const char * fl_filename_name (const char *filename)
FL_EXPORT const char * fl_filename_ext (const char *buf)
FL_EXPORT char * fl_filename_setext (char *to, int tolen, const char *ext)
FL_EXPORT int fl_filename_expand (char *to, int tolen, const char *from)
FL_EXPORT int fl_filename_absolute (char *to, int tolen, const char *from)
FL_EXPORT int fl_filename_relative (char *to, int tolen, const char *from)
FL_EXPORT int fl_filename_match (const char *name, const char *pattern)
FL_EXPORT int fl_filename_isdir (const char *name)
FL_EXPORT int fl_alphasort (struct dirent **, struct dirent **)
FL_EXPORT int fl_casealphasort (struct dirent **, struct dirent **)
FL_EXPORT int fl_casenumericsort (struct dirent **, struct dirent **)
FL_EXPORT int fl_numericsort (struct dirent **, struct dirent **)
int fl_open_uri (const char *uri, char *msg, int msglen)

Detailed Description

File names and URI functions defined in <FL/filename.H>


Define Documentation

#define fl_dirent_h_cyclic_include

Definition at line 106 of file filename.H.


Typedef Documentation

typedef int( Fl_File_Sort_F)(struct dirent **, struct dirent **)

File sorting function.

See also:
fl_filename_list()

Definition at line 122 of file filename.H.


Function Documentation

FL_EXPORT int fl_alphasort ( struct dirent **  ,
struct dirent **   
)

Definition at line 44 of file filename_list.cxx.

FL_EXPORT int fl_casealphasort ( struct dirent **  ,
struct dirent **   
)

Definition at line 48 of file filename_list.cxx.

FL_EXPORT int fl_casenumericsort ( struct dirent **  ,
struct dirent **   
)

Definition at line 97 of file numericsort.c.

FL_EXPORT int fl_filename_absolute ( char *  to,
int  tolen,
const char *  from 
)

Makes a filename absolute from a relative filename.

    #include <FL/filename.H>
    [..]
    chdir("/var/tmp");
    fl_filename_absolute(out, sizeof(out), "foo.txt");         // out="/var/tmp/foo.txt"
    fl_filename_absolute(out, sizeof(out), "./foo.txt");       // out="/var/tmp/foo.txt"
    fl_filename_absolute(out, sizeof(out), "../log/messages"); // out="/var/log/messages"
Parameters:
[out]toresulting absolute filename
[in]tolensize of the absolute filename buffer
[in]fromrelative filename
Returns:
0 if no change, non zero otherwise

Definition at line 65 of file filename_absolute.cxx.

References b, fl_getcwd(), isdirsep, start, and strlcpy.

Referenced by Fl_File_Chooser::directory(), update_history(), and Fl_File_Chooser::value().

FL_EXPORT int fl_filename_expand ( char *  to,
int  tolen,
const char *  from 
)

Expands a filename containing shell variables and tilde (~). Currently handles these variants:

    "~username"               // if 'username' does not exist, result will be unchanged
    "~/file"
    "$VARNAME"                // does NOT handle ${VARNAME}

Examples:

    #include <FL/filename.H>
    [..]
    putenv("TMPDIR=/var/tmp");
    fl_filename_expand(out, sizeof(out), "~fred/.cshrc");     // out="/usr/fred/.cshrc"
    fl_filename_expand(out, sizeof(out), "~/.cshrc");         // out="/usr/<yourname>/.cshrc"
    fl_filename_expand(out, sizeof(out), "$TMPDIR/foo.txt");  // out="/var/tmp/foo.txt"
Parameters:
[out]toresulting expanded filename
[in]tolensize of the expanded filename buffer
[in]fromfilename containing shell variables
Returns:
0 if no change, non zero otherwise

Definition at line 72 of file filename_expand.cxx.

References fl_getenv(), isdirsep, start, strlcpy, and value.

FL_EXPORT const char* fl_filename_ext ( const char *  buf)

Gets the extensions of a filename.

   #include <FL/filename.H>
   [..]
   const char *out;
   out = fl_filename_ext("/some/path/foo.txt");        // result: ".txt"
   out = fl_filename_ext("/some/path/foo");            // result: NULL
Parameters:
[in]bufthe filename to be parsed
Returns:
a pointer to the extension (including '.') if any or NULL otherwise

Definition at line 43 of file filename_ext.cxx.

References buf.

Referenced by fl_filename_setext(), Fl_File_Icon::load(), and Fluid_Image::write_static().

FL_EXPORT int fl_filename_isdir ( const char *  n)

Determines if a file exists and is a directory from its filename.

   #include <FL/filename.H>
   [..]
   fl_filename_isdir("/etc");           // returns non-zero
   fl_filename_isdir("/etc/hosts");     // returns 0
Parameters:
[in]nthe filename to parse
Returns:
non zero if file exists and is a directory, zero otherwise

Definition at line 61 of file filename_isdir.cxx.

References FL_PATH_MAX, fl_stat(), isdirsep, and length.

Referenced by _fl_filename_isdir_quick(), Fl_File_Icon::find(), fl_filename_list(), Fl_File_Chooser::rescan_keep_filename(), and Fl_File_Chooser::value().

FL_EXPORT int fl_filename_match ( const char *  s,
const char *  p 
)

Checks if a string s matches a pattern p. The following syntax is used for the pattern:

  • * matches any sequence of 0 or more characters.
  • ? matches any single character.
  • [set] matches any character in the set. Set can contain any single characters, or a-z to represent a range. To match ] or - they must be the first characters. To match ^ or ! they must not be the first characters.
  • [^set] or [!set] matches any character not in the set.
  • {X|Y|Z} or {X,Y,Z} matches any one of the subexpressions literally.
  • \x quotes the character x so it has no special meaning.
  • x all other characters must be matched exactly.

Include:

    #include <FL/filename.H>
Parameters:
[in]sthe string to check for a match
[in]pthe string pattern
Returns:
non zero if the string matches the pattern

Definition at line 53 of file filename_match.cxx.

References fl_filename_match().

Referenced by do_matching(), Fl_File_Icon::find(), fl_filename_match(), Fl_Function_Type::has_signature(), Fl_File_Browser::load(), Fl_Plugin_Manager::loadAll(), and template_load().

FL_EXPORT const char* fl_filename_name ( const char *  name)

Gets the file name from a path. Similar to basename(3), exceptions shown below.

    #include <FL/filename.H>
    [..]
    const char *out;
    out = fl_filename_name("/usr/lib");     // out="lib"
    out = fl_filename_name("/usr/");        // out=""      (basename(3) returns "usr" instead)
    out = fl_filename_name("/usr");         // out="usr"
    out = fl_filename_name("/");            // out=""      (basename(3) returns "/" instead)
    out = fl_filename_name(".");            // out="."
    out = fl_filename_name("..");           // out=".."
Returns:
a pointer to the char after the last slash, or to filename if there is none.

returns pointer to the filename, or null if name ends with ':'

Definition at line 2339 of file Fl_mac.cxx.

References name.

Referenced by Fl_File_Icon::find(), Fl_File_Chooser::fl_file_chooser(), fl_show_file_selector(), goto_source_dir(), Fl_Window::show(), update_sourceview_cb(), write_cb(), Fluid_Image::write_code(), write_code(), Fluid_Image::write_static(), and write_strings_cb().

FL_EXPORT int fl_filename_relative ( char *  to,
int  tolen,
const char *  from 
)

Makes a filename relative to the current working directory.

    #include <FL/filename.H>
    [..]
    chdir("/var/tmp/somedir");       // set cwd to /var/tmp/somedir
    [..]
    char out[FL_PATH_MAX];
    fl_filename_relative(out, sizeof(out), "/var/tmp/somedir/foo.txt");  // out="foo.txt",    return=1
    fl_filename_relative(out, sizeof(out), "/var/tmp/foo.txt");          // out="../foo.txt", return=1
    fl_filename_relative(out, sizeof(out), "foo.txt");                   // out="foo.txt",    return=0 (no change)
    fl_filename_relative(out, sizeof(out), "./foo.txt");                 // out="./foo.txt",  return=0 (no change)
    fl_filename_relative(out, sizeof(out), "../foo.txt");                // out="../foo.txt", return=0 (no change)
Parameters:
[out]toresulting relative filename
[in]tolensize of the relative filename buffer
[in]fromabsolute filename
Returns:
0 if no change, non zero otherwise

Definition at line 137 of file filename_absolute.cxx.

References fl_filename_relative(), fl_getcwd(), FL_PATH_MAX, and strlcpy.

Referenced by Fl_File_Chooser::fl_dir_chooser(), Fl_File_Chooser::fl_file_chooser(), fl_filename_relative(), load_history(), and update_history().

FL_EXPORT char* fl_filename_setext ( char *  buf,
int  buflen,
const char *  ext 
)

Replaces the extension in buf of max.
size buflen with the extension in ext.
If there's no '.' in buf, ext is appended.
If ext is NULL, behaves as if it were an empty string ("").

Example

   #include <FL/filename.H>
   [..]
   char buf[FL_PATH_MAX] = "/path/myfile.cxx";
   fl_filename_setext(buf, sizeof(buf), ".txt");      // buf[] becomes "/path/myfile.txt"
Returns:
buf itself for calling convenience.

Definition at line 49 of file filename_setext.cxx.

References fl_filename_ext(), and strlcpy.

Referenced by update_sourceview_cb(), write_cb(), and write_strings_cb().

FL_EXPORT int fl_numericsort ( struct dirent **  ,
struct dirent **   
)

Definition at line 105 of file numericsort.c.

int fl_open_uri ( const char *  uri,
char *  msg,
int  msglen 
)

Opens the specified Uniform Resource Identifier (URI). Uses an operating-system dependent program or interface. For URIs using the "ftp", "http", or "https" schemes, the system default web browser is used to open the URI, while "mailto" and "news" URIs are typically opened using the system default mail reader and "file" URIs are opened using the file system navigator.

On success, the (optional) msg buffer is filled with the command that was run to open the URI; on Windows, this will always be "open uri".

On failure, the msg buffer is filled with an English error message.

Example

 #include <FL/filename.H>
 [..]
 char errmsg[512];
 if ( !fl_open_uri("http://google.com/", errmsg, sizeof(errmsg)) ) {
     char warnmsg[768];
     sprintf(warnmsg, "Error: %s", errmsg);
     fl_alert(warnmsg);
 }
Parameters:
uriThe URI to open
msgOptional buffer which contains the command or error message
msglenLength of optional buffer
Returns:
1 on success, 0 on failure

Definition at line 95 of file fl_open_uri.cxx.

References FL_PATH_MAX, i, NULL, snprintf, strlcat, and strlcpy.

Referenced by Fl_Help_View::load().