source: trunk/poppler/mypoppler/goo/gfile.h @ 2

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 16 years ago

First import

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