Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

filename.h

00001 /*
00002  * $Id: filename.h,v 1.9 2003/01/29 23:38:12 laza2000 Exp $
00003  *
00004  * Extended Fast Light Toolkit (EFLTK)
00005  * Copyright (C) 2002-2003 by EDE-Team
00006  * WWW: http://www.sourceforge.net/projects/ede
00007  *
00008  * Fast Light Toolkit (FLTK)
00009  * Copyright (C) 1998-2003 by Bill Spitzak and others.
00010  * WWW: http://www.fltk.org
00011  *
00012  * This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00013  * version 2. See COPYING for details.
00014  *
00015  * Author : Mikko Lahteenmaki
00016  * Email  : mikko@fltk.net
00017  *
00018  * Please report all bugs and problems to "efltk-bugs@fltk.net"
00019  *
00020  */
00021 
00022 #ifndef _FL_FILENAME_H_
00023 #define _FL_FILENAME_H_
00024 
00025 #include "Enumerations.h" // for FL_API
00026 #include "Fl_Util.h"
00027 
00028 #define FL_PATH_MAX 1024 // all buffers are assummed to be at least this long
00029 
00030 #if defined(_WIN32) && !defined(__CYGWIN__)
00031 
00032 # define DT_REG 0 //Regular
00033 # define DT_DIR 1 //Directory
00034  struct dirent { uchar d_type; char d_name[1]; };
00035 
00036 #elif defined(__linux__)
00037 // Newest Linux libc is broken when it emulates the 32-bit dirent, it
00038 // generates errors when the data like the inode number does not fit, even
00039 // though we are not going to look at anything other than the name. This
00040 // code seems to force the 64-bit version to be used:
00041 
00042 //Breaks too much... :(
00043 //#define _GNU_SOURCE
00044 //#define __USE_LARGEFILE64
00045 
00046 #include <features.h>
00047 #include <sys/types.h>
00048 
00049 #include <dirent.h>
00050 //#define dirent dirent64
00051 //#define scandir scandir64
00052 
00053 #else
00054 
00055  // warning: on some systems (very few nowadays?) <dirent.h> may not exist.
00056 // The correct information is in one of these three files:
00057 //  #include <sys/ndir.h>
00058 //  #include <sys/dir.h>
00059 //  #include <ndir.h>
00060 // plus you must do the following #define:
00061 //  #define dirent direct
00062 // I recommend you create a /usr/include/dirent.h containing the correct info
00063 #include <sys/types.h>
00064 #include <dirent.h>
00065 
00066 #endif
00067 
00068 // File list sort function type
00069 typedef int (Fl_File_Sort_F)(struct dirent **, struct dirent **);
00070 // Pre-defined sort functions
00071 extern FL_API int fl_alphasort(struct dirent **, struct dirent **);
00072 extern FL_API int fl_casealphasort(struct dirent **, struct dirent **);
00073 
00074 // Portable "scandir" function.  Ugly but necessary...
00075 extern FL_API int fl_filename_list(const char *dir, struct dirent ***list, Fl_File_Sort_F *sort = fl_alphasort);
00076 
00077 
00078 // Returns pointer to .ext or NULL if no extension
00079 extern FL_API const char *fl_file_getext(const char *filename);
00080 // Returns extension ".ext" of file as Fl_String.
00081 extern FL_API Fl_String fl_file_getext(const Fl_String &filename);
00082 
00083 // Change / Add extension, returns pointer to filename
00084 extern FL_API char *fl_file_setext(char *filename, const char *ext);
00085 // Change / Add extension, returns new Fl_String with changed extension
00086 extern FL_API Fl_String fl_file_setext(const Fl_String &, const char *ext);
00087 
00088 // Strip path from absolute path filename. Returns pointer to filename
00089 extern FL_API const char *fl_file_filename(const char *filename);
00090 // Strip path from absolute path filename. Returns Fl_String
00091 extern FL_API Fl_String fl_file_filename(const Fl_String &);
00092 
00093 // Expand filename, Convert $x and ~x to strings. Returns true, if anything converted
00094 extern FL_API bool fl_file_expand(char *buf, int buf_len, const char *from);
00095 // Expand filename, Convert $x and ~x to strings. Returns converted Fl_String
00096 extern FL_API Fl_String fl_file_expand(const Fl_String &from);
00097 
00098 // prepend getcwd()
00099 extern FL_API bool fl_file_absolute(char *buf, int buf_len, const char *from);
00100 // prepend getcwd()
00101 extern FL_API Fl_String fl_file_absolute(const Fl_String &from);
00102 
00103 // glob match
00104 extern FL_API bool fl_file_match(const char *, const char *pattern); 
00105 
00106 // Returns homepath in WIN32 and Linux
00107 extern FL_API char *fl_get_homedir();
00108 extern FL_API const Fl_String &fl_homedir();
00109 
00110 // Check if given file exists on disk
00111 extern FL_API bool fl_file_exists(const char *name);
00112 
00113 // Check if given name is dir
00114 extern FL_API bool fl_is_dir(const char *path);
00115 
00116 class FL_API Fl_File_Attr
00117 {
00118 public:
00119     Fl_File_Attr() { size=0; flags=0; }
00120 
00121     enum {
00122         DIR       = 1, //Directory
00123         FILE      = 2, //Regular file
00124         LINK   = 4, //Sym link (ignored on WIN32)
00125         DEVICE = 8  //Logical disk (ignored on Linux)
00126     };
00127     bool parse(const char *filename);
00128     
00129     ulong size; // size of file
00130     ulong modified; // time modified
00131     char time[128]; // time modified str
00132     Fl_Flags flags; // type flags
00133 
00134 #ifdef _WIN32
00135     uint64 free; //Free space
00136     uint64 capacity; //total capacity space
00137 #endif
00138 };
00139 
00140 // Backward compatibility
00141 typedef Fl_File_Attr Fl_FileAttr;
00142 
00143 extern FL_API Fl_File_Attr *fl_file_attr(const char *name);
00144 
00145 // Backward compatibility..
00146 inline bool fl_file_absolute(char *buf, const char *from) { return fl_file_absolute(buf, FL_PATH_MAX, from); }
00147 
00148 #define FL_DIR    Fl_File_Attr::DIR
00149 #define FL_FILE   Fl_File_Attr::FILE
00150 #define FL_LINK   Fl_File_Attr::LINK
00151 #define FL_DEVICE Fl_File_Attr::DEVICE
00152 
00153 #endif

Generated on Thu Jul 31 15:33:43 2003 for eFLTK by doxygen1.2.15