Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / data / file-handle-def.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2005, 2006 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef FILE_HANDLE_DEF_H
18 #define FILE_HANDLE_DEF_H
19
20 #include <stdbool.h>
21 #include <stddef.h>
22
23 /* What a file handle refers to.
24    (Ordinarily only a single value is allowed, but fh_open()
25    and fh_parse() take a mask.) */
26 enum fh_referent
27   {
28     FH_REF_FILE = 001,          /* Ordinary file (the most common case). */
29     FH_REF_INLINE = 002,        /* The inline file. */
30     FH_REF_SCRATCH = 004        /* Temporary dataset. */
31   };
32
33 /* File modes. */
34 enum fh_mode
35   {
36     FH_MODE_TEXT,               /* New-line delimited lines. */
37     FH_MODE_BINARY              /* Fixed-length records. */
38   };
39
40 /* Properties of a file handle. */
41 struct fh_properties
42   {
43     enum fh_mode mode;          /* File mode. */
44     size_t record_width;        /* Length of fixed-format records. */
45     size_t tab_width;           /* Tab width, 0=do not expand tabs. */
46   };
47
48 void fh_init (void);
49 void fh_done (void);
50
51 /* Creating file handles. */
52 struct file_handle *fh_create_file (const char *handle_name,
53                                     const char *file_name,
54                                     const struct fh_properties *);
55 struct file_handle *fh_create_scratch (const char *handle_name);
56 const struct fh_properties *fh_default_properties (void);
57
58 /* Delete file handle from global list. */
59 void fh_free (struct file_handle *);
60
61 /* Finding file handles. */
62 struct file_handle *fh_from_id (const char *handle_name);
63 struct file_handle *fh_from_file_name (const char *file_name);
64 struct file_handle *fh_inline_file (void);
65
66 /* Generic properties of file handles. */
67 const char *fh_get_id (const struct file_handle *);
68 const char *fh_get_name (const struct file_handle *);
69 enum fh_referent fh_get_referent (const struct file_handle *);
70
71 /* Properties of FH_REF_FILE file handles. */
72 const char *fh_get_file_name (const struct file_handle *);
73 enum fh_mode fh_get_mode (const struct file_handle *) ;
74
75 /* Properties of FH_REF_FILE and FH_REF_INLINE file handles. */
76 size_t fh_get_record_width (const struct file_handle *);
77 size_t fh_get_tab_width (const struct file_handle *);
78
79 /* Properties of FH_REF_SCRATCH file handles. */
80 struct scratch_handle *fh_get_scratch_handle (struct file_handle *);
81 void fh_set_scratch_handle (struct file_handle *, struct scratch_handle *);
82
83 /* Opening and closing file handles. */
84 void **fh_open (struct file_handle *, enum fh_referent mask,
85                 const char *type, const char *mode);
86 int fh_close (struct file_handle *, const char *type, const char *mode);
87 bool fh_is_open (const struct file_handle *);
88
89 /* Default file handle for DATA LIST, REREAD, REPEATING DATA
90    commands. */
91 struct file_handle *fh_get_default_handle (void);
92 void fh_set_default_handle (struct file_handle *);
93
94 #endif