b4ca8e27d69bb32909b2521d2c069bc2c997212d
[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 /* Destroy file handle */
48 void fh_free(struct file_handle *);
49
50 const struct fh_properties *fh_default_properties (void);
51
52 /* Finding file handles, based on handle name or filename. */
53 struct file_handle *fh_from_name (const char *handle_name);
54 struct file_handle *fh_from_filename (const char *filename);
55
56 /* Querying properties of file handles. */
57 const char *fh_get_name (const struct file_handle *);
58 const char *fh_get_filename (const struct file_handle *);
59 enum fh_mode fh_get_mode (const struct file_handle *) ;
60 size_t fh_get_record_width (const struct file_handle *);
61 size_t fh_get_tab_width (const struct file_handle *);
62
63 /* Opening and closing file handles. */
64 void **fh_open (struct file_handle *, const char *type, const char *mode);
65 int fh_close (struct file_handle *, const char *type, const char *mode);
66
67 #endif