applied diff between xpdf-3.00-orig and xpdf-3.00-swftools
[swftools.git] / pdf2swf / xpdf / gfile.h
1 //========================================================================
2 //
3 // gfile.h
4 //
5 // Miscellaneous file and directory name manipulation.
6 //
7 // Copyright 1996-2003 Glyph & Cog, LLC
8 //
9 //========================================================================
10
11 #ifndef GFILE_H
12 #define GFILE_H
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <stddef.h>
17 #if defined(WIN32)
18 #  include <sys/stat.h>
19 #  ifdef FPTEX
20 #    include <win32lib.h>
21 #  else
22 #    include <windows.h>
23 #  endif
24 #elif defined(ACORN)
25 #elif defined(MACOS)
26 #  include <ctime.h>
27 #else
28 #  include <unistd.h>
29 #  include <sys/types.h>
30 #  ifdef VMS
31 #    include "vms_dirent.h"
32 #  elif HAVE_DIRENT_H
33 #    include <dirent.h>
34 #    define NAMLEN(d) strlen((d)->d_name)
35 #  else
36 #    define dirent direct
37 #    define NAMLEN(d) (d)->d_namlen
38 #    if HAVE_SYS_NDIR_H
39 #      include <sys/ndir.h>
40 #    endif
41 #    if HAVE_SYS_DIR_H
42 #      include <sys/dir.h>
43 #    endif
44 #    if HAVE_NDIR_H
45 #      include <ndir.h>
46 #    endif
47 #  endif
48 #endif
49 #include "gtypes.h"
50
51 class GString;
52
53 //------------------------------------------------------------------------
54
55 // Get home directory path.
56 extern GString *getHomeDir();
57
58 // Get current directory.
59 extern GString *getCurrentDir();
60
61 /* create a temporary filename */
62 char* mktmpname(char*ptr);
63
64 // Append a file name to a path string.  <path> may be an empty
65 // string, denoting the current directory).  Returns <path>.
66 extern GString *appendToPath(GString *path, char *fileName);
67
68 // Grab the path from the front of the file name.  If there is no
69 // directory component in <fileName>, returns an empty string.
70 extern GString *grabPath(char *fileName);
71
72 // Is this an absolute path or file name?
73 extern GBool isAbsolutePath(char *path);
74
75 // Make this path absolute by prepending current directory (if path is
76 // relative) or prepending user's directory (if path starts with '~').
77 extern GString *makePathAbsolute(GString *path);
78
79 // Get the modification time for <fileName>.  Returns 0 if there is an
80 // error.
81 extern time_t getModTime(char *fileName);
82
83 // Create a temporary file and open it for writing.  If <ext> is not
84 // NULL, it will be used as the file name extension.  Returns both the
85 // name and the file pointer.  For security reasons, all writing
86 // should be done to the returned file pointer; the file may be
87 // reopened later for reading, but not for writing.  The <mode> string
88 // should be "w" or "wb".  Returns true on success.
89 extern GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
90
91 // Execute <command>.  Returns true on success.
92 extern GBool executeCommand(char *cmd);
93
94 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
95 // conventions.
96 extern char *getLine(char *buf, int size, FILE *f);
97
98 //------------------------------------------------------------------------
99 // GDir and GDirEntry
100 //------------------------------------------------------------------------
101
102 class GDirEntry {
103 public:
104
105   GDirEntry(char *dirPath, char *nameA, GBool doStat);
106   ~GDirEntry();
107   GString *getName() { return name; }
108   GBool isDir() { return dir; }
109
110 private:
111
112   GString *name;                // dir/file name
113   GBool dir;                    // is it a directory?
114 };
115
116 class GDir {
117 public:
118
119   GDir(char *name, GBool doStatA = gTrue);
120   ~GDir();
121   GDirEntry *getNextEntry();
122   void rewind();
123
124 private:
125
126   GString *path;                // directory path
127   GBool doStat;                 // call stat() for each entry?
128 #if defined(WIN32)
129   WIN32_FIND_DATA ffd;
130   HANDLE hnd;
131 #elif defined(ACORN)
132 #elif defined(MACOS)
133 #else
134   DIR *dir;                     // the DIR structure from opendir()
135 #ifdef VMS
136   GBool needParent;             // need to return an entry for [-]
137 #endif
138 #endif
139 };
140
141 #endif