filters

gfile.h

00001 //========================================================================
00002 //
00003 // gfile.h
00004 //
00005 // Miscellaneous file and directory name manipulation.
00006 //
00007 // Copyright 1996-2002 Glyph & Cog, LLC
00008 //
00009 //========================================================================
00010 
00011 #ifndef GFILE_H
00012 #define GFILE_H
00013 
00014 #include <aconf.h>
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <stddef.h>
00018 #if defined(WIN32)
00019 #  include <sys/stat.h>
00020 #  ifdef FPTEX
00021 #    include <win32lib.h>
00022 #  else
00023 #    include <windows.h>
00024 #  endif
00025 #elif defined(ACORN)
00026 #elif defined(MACOS)
00027 #  include <ctime.h>
00028 #else
00029 #  include <unistd.h>
00030 #  include <sys/types.h>
00031 #  ifdef VMS
00032 #    include "vms_dirent.h"
00033 #  elif HAVE_DIRENT_H
00034 #    include <dirent.h>
00035 #    define NAMLEN(d) strlen((d)->d_name)
00036 #  else
00037 #    define dirent direct
00038 #    define NAMLEN(d) (d)->d_namlen
00039 #    if HAVE_SYS_NDIR_H
00040 #      include <sys/ndir.h>
00041 #    endif
00042 #    if HAVE_SYS_DIR_H
00043 #      include <sys/dir.h>
00044 #    endif
00045 #    if HAVE_NDIR_H
00046 #      include <ndir.h>
00047 #    endif
00048 #  endif
00049 #endif
00050 #include "gtypes.h"
00051 
00052 class GString;
00053 
00054 //------------------------------------------------------------------------
00055 
00056 // Get home directory path.
00057 extern GString *getHomeDir();
00058 
00059 // Get current directory.
00060 extern GString *getCurrentDir();
00061 
00062 // Append a file name to a path string.  <path> may be an empty
00063 // string, denoting the current directory).  Returns <path>.
00064 extern GString *appendToPath(GString *path, const char *fileName);
00065 
00066 // Grab the path from the front of the file name.  If there is no
00067 // directory component in <fileName>, returns an empty string.
00068 extern GString *grabPath(const char *fileName);
00069 
00070 // Is this an absolute path or file name?
00071 extern GBool isAbsolutePath(const char *path);
00072 
00073 // Make this path absolute by prepending current directory (if path is
00074 // relative) or prepending user's directory (if path starts with '~').
00075 extern GString *makePathAbsolute(GString *path);
00076 
00077 // Get the modification time for <fileName>.  Returns 0 if there is an
00078 // error.
00079 extern time_t getModTime(const char *fileName);
00080 
00081 // Create a temporary file and open it for writing.  If <ext> is not
00082 // NULL, it will be used as the file name extension.  Returns both the
00083 // name and the file pointer.  For security reasons, all writing
00084 // should be done to the returned file pointer; the file may be
00085 // reopened later for reading, but not for writing.  The <mode> string
00086 // should be "w" or "wb".  Returns true on success.
00087 extern GBool openTempFile(GString **name, FILE **f, const char *mode);//, char *ext);
00088 
00089 // Execute <command>.  Returns true on success.
00090 extern GBool executeCommand(const char *cmd);
00091 
00092 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
00093 // conventions.
00094 extern char *getLine(char *buf, int size, FILE *f);
00095 
00096 //------------------------------------------------------------------------
00097 // GDir and GDirEntry
00098 //------------------------------------------------------------------------
00099 
00100 class GDirEntry {
00101 public:
00102 
00103   GDirEntry(const char *dirPath, const char *nameA, GBool doStat);
00104   ~GDirEntry();
00105   GString *getName() { return name; }
00106   GBool isDir() { return dir; }
00107 
00108 private:
00109 
00110   GString *name;        // dir/file name
00111   GBool dir;            // is it a directory?
00112 };
00113 
00114 class GDir {
00115 public:
00116 
00117   GDir(const char *name, GBool doStatA = gTrue);
00118   ~GDir();
00119   GDirEntry *getNextEntry();
00120   void rewind();
00121 
00122 private:
00123 
00124   GString *path;        // directory path
00125   GBool doStat;         // call stat() for each entry?
00126 #if defined(WIN32)
00127   WIN32_FIND_DATA ffd;
00128   HANDLE hnd;
00129 #elif defined(ACORN)
00130 #elif defined(MACOS)
00131 #else
00132   DIR *dir;         // the DIR structure from opendir()
00133 #ifdef VMS
00134   GBool needParent;     // need to return an entry for [-]
00135 #endif
00136 #endif
00137 };
00138 
00139 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys