Added new files resulting from directory restructuring.
[pspp-builds.git] / src / data / file-handle-def.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000, 2005, 2006 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 <stdbool.h>
24 #include <stddef.h>
25
26 /* What a file handle refers to.
27    (Ordinarily only a single value is allowed, but fh_open()
28    and fh_parse() take a mask.) */
29 enum fh_referent
30   {
31     FH_REF_FILE = 001,          /* Ordinary file (the most common case). */
32     FH_REF_INLINE = 002,        /* The inline file. */
33     FH_REF_SCRATCH = 004        /* Temporary dataset. */
34   };
35
36 /* File modes. */
37 enum fh_mode
38   {
39     FH_MODE_TEXT,               /* New-line delimited lines. */
40     FH_MODE_BINARY              /* Fixed-length records. */
41   };
42
43 /* Properties of a file handle. */
44 struct fh_properties 
45   {
46     enum fh_mode mode;          /* File mode. */
47     size_t record_width;        /* Length of fixed-format records. */
48     size_t tab_width;           /* Tab width, 0=do not expand tabs. */
49   };
50
51 void fh_init (void);
52 void fh_done (void);
53
54 /* Creating file handles. */
55 struct file_handle *fh_create_file (const char *handle_name,
56                                     const char *filename,
57                                     const struct fh_properties *);
58 struct file_handle *fh_create_scratch (const char *handle_name);
59 const struct fh_properties *fh_default_properties (void);
60
61 /* Delete file handle from global list. */
62 void fh_free (struct file_handle *);
63
64 /* Finding file handles. */
65 struct file_handle *fh_from_name (const char *handle_name);
66 struct file_handle *fh_from_filename (const char *filename);
67 struct file_handle *fh_inline_file (void);
68
69 /* Generic properties of file handles. */
70 const char *fh_get_name (const struct file_handle *);
71 enum fh_referent fh_get_referent (const struct file_handle *);
72
73 /* Properties of FH_REF_FILE file handles. */
74 const char *fh_get_filename (const struct file_handle *);
75 enum fh_mode fh_get_mode (const struct file_handle *) ;
76
77 /* Properties of FH_REF_FILE and FH_REF_INLINE file handles. */
78 size_t fh_get_record_width (const struct file_handle *);
79 size_t fh_get_tab_width (const struct file_handle *);
80
81 /* Properties of FH_REF_SCRATCH file handles. */
82 struct scratch_handle *fh_get_scratch_handle (struct file_handle *);
83 void fh_set_scratch_handle (struct file_handle *, struct scratch_handle *);
84
85 /* Opening and closing file handles. */
86 void **fh_open (struct file_handle *, enum fh_referent mask,
87                 const char *type, const char *mode);
88 int fh_close (struct file_handle *, const char *type, const char *mode);
89 bool fh_is_open (const struct file_handle *);
90
91 /* Default file handle for DATA LIST, REREAD, REPEATING DATA
92    commands. */
93 struct file_handle *fh_get_default_handle (void);
94 void fh_set_default_handle (struct file_handle *);
95
96 #endif