Clean up file handle code in preparation to add temporary file
[pspp-builds.git] / src / file-handle-def.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000,2005 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #ifndef FILE_HANDLE_DEF_H
21 #define FILE_HANDLE_DEF_H
22
23 #include <config.h>
24
25 /* File modes. */
26 enum fh_mode
27   {
28     MODE_TEXT,                  /* New-line delimited lines. */
29     MODE_BINARY                 /* Fixed-length records. */
30   };
31
32 /* Properties of a file handle. */
33 struct fh_properties 
34   {
35     enum fh_mode mode;          /* File mode. */
36     size_t record_width;        /* Length of fixed-format records. */
37     size_t tab_width;           /* Tab width, 0=do not expand tabs. */
38   };
39
40 void fh_init (void);
41 void fh_done (void);
42
43 /* Creating file handles. */
44 struct file_handle *fh_create (const char *handle_name, 
45                                const char *filename,
46                                const struct fh_properties *);
47 const struct fh_properties *fh_default_properties (void);
48
49 /* Finding file handles, based on handle name or filename. */
50 struct file_handle *fh_from_name (const char *handle_name);
51 struct file_handle *fh_from_filename (const char *filename);
52
53 /* Querying properties of file handles. */
54 const char *fh_get_name (const struct file_handle *);
55 const char *fh_get_filename (const struct file_handle *);
56 enum fh_mode fh_get_mode (const struct file_handle *) ;
57 size_t fh_get_record_width (const struct file_handle *);
58 size_t fh_get_tab_width (const struct file_handle *);
59
60 /* Opening and closing file handles. */
61 void **fh_open (struct file_handle *, const char *type, const char *mode);
62 int fh_close (struct file_handle *, const char *type, const char *mode);
63
64 #endif