]> www.fi.muni.cz Git - evince.git/blob - pdf/goo/gfile.h
Completely synched with Xpdf 0.90
[evince.git] / pdf / goo / gfile.h
1 //========================================================================
2 //
3 // gfile.h
4 //
5 // Miscellaneous file and directory name manipulation.
6 //
7 // Copyright 1996 Derek B. Noonburg
8 //
9 //========================================================================
10
11 #ifndef GFILE_H
12 #define GFILE_H
13
14 extern "C" {
15 #include <stdlib.h>
16 #include <stddef.h>
17 #if defined(WIN32)
18 #  ifdef _MSC_VER
19 #    include <windows.h>
20 #  else
21 #    include <kpathsea/win32lib.h>
22 #  endif
23 #elif defined(ACORN)
24 #else
25 #  include <unistd.h>
26 #  include <sys/types.h>
27 #  ifdef VMS
28 #    include "vms_dirent.h"
29 #  elif HAVE_DIRENT_H
30 #    include <dirent.h>
31 #    define NAMLEN(dirent) strlen((dirent)->d_name)
32 #  else
33 #    define dirent direct
34 #    define NAMLEN(dirent) (dirent)->d_namlen
35 #    if HAVE_SYS_NDIR_H
36 #      include <sys/ndir.h>
37 #    endif
38 #    if HAVE_SYS_DIR_H
39 #      include <sys/dir.h>
40 #    endif
41 #    if HAVE_NDIR_H
42 #      include <ndir.h>
43 #    endif
44 #  endif
45 #endif
46 }
47 #include "gtypes.h"
48
49 class GString;
50
51 //------------------------------------------------------------------------
52
53 // Get home directory path.
54 extern GString *getHomeDir();
55
56 // Get current directory.
57 extern GString *getCurrentDir();
58
59 // Append a file name to a path string.  <path> may be an empty
60 // string, denoting the current directory).  Returns <path>.
61 extern GString *appendToPath(GString *path, char *fileName);
62
63 // Grab the path from the front of the file name.  If there is no
64 // directory component in <fileName>, returns an empty string.
65 extern GString *grabPath(char *fileName);
66
67 // Is this an absolute path or file name?
68 extern GBool isAbsolutePath(char *path);
69
70 // Make this path absolute by prepending current directory (if path is
71 // relative) or prepending user's directory (if path starts with '~').
72 GString *makePathAbsolute(GString *path);
73
74 //------------------------------------------------------------------------
75 // GDir and GDirEntry
76 //------------------------------------------------------------------------
77
78 class GDirEntry {
79 public:
80
81   GDirEntry(char *dirPath, char *name1, GBool doStat);
82   ~GDirEntry();
83   GString *getName() { return name; }
84   GBool isDir() { return dir; }
85
86 private:
87
88   GString *name;                // dir/file name
89   GBool dir;                    // is it a directory?
90 };
91
92 class GDir {
93 public:
94
95   GDir(char *name, GBool doStat1 = gTrue);
96   ~GDir();
97   GDirEntry *getNextEntry();
98   void rewind();
99
100 private:
101
102   GString *path;                // directory path
103   GBool doStat;                 // call stat() for each entry?
104 #if defined(WIN32)
105   WIN32_FIND_DATA ffd;
106   HANDLE hnd;
107 #elif defined(ACORN)
108 #else
109   DIR *dir;                     // the DIR structure from opendir()
110 #ifdef VMS
111   GBool needParent;             // need to return an entry for [-]
112 #endif
113 #endif
114 };
115
116 #endif