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