Implement DATASET commands.
[pspp-builds.git] / src / data / file-handle-def.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2005, 2006, 2010, 2011 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 struct dataset;
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_DATASET = 004        /* Dataset. */
33   };
34
35 /* File modes. */
36 enum fh_mode
37   {
38     FH_MODE_TEXT,               /* New-line delimited lines. */
39     FH_MODE_FIXED,              /* Fixed-length records. */
40     FH_MODE_VARIABLE,           /* Binary variable-length records. */
41     FH_MODE_360_VARIABLE,       /* IBM 360 variable-length records. */
42     FH_MODE_360_SPANNED,        /* IBM 360 variable-length, spanned records. */
43   };
44
45 /* Ways to access a file. */
46 enum fh_access
47   {
48     FH_ACC_READ,                /* Read from it. */
49     FH_ACC_WRITE                /* Write to it. */
50   };
51
52 /* Properties of a file handle. */
53 struct fh_properties
54   {
55     enum fh_mode mode;          /* File mode. */
56     size_t record_width;        /* Length of fixed-format records. */
57     size_t tab_width;           /* Tab width, 0=do not expand tabs. */
58     const char *encoding;       /* ASCII or EBCDIC? */
59   };
60
61 void fh_init (void);
62 void fh_done (void);
63
64 /* Creating file handles. */
65 struct file_handle *fh_create_file (const char *handle_name,
66                                     const char *file_name,
67                                     const struct fh_properties *);
68 struct file_handle *fh_create_dataset (struct dataset *);
69 const struct fh_properties *fh_default_properties (void);
70
71 /* Reference management. */
72 struct file_handle *fh_ref (struct file_handle *);
73 void fh_unref (struct file_handle *);
74 void fh_unname (struct file_handle *);
75
76 /* Finding file handles. */
77 struct file_handle *fh_from_id (const char *handle_name);
78 struct file_handle *fh_from_file_name (const char *file_name);
79 struct file_handle *fh_inline_file (void);
80
81 /* Generic properties of file handles. */
82 const char *fh_get_id (const struct file_handle *);
83 const char *fh_get_name (const struct file_handle *);
84 enum fh_referent fh_get_referent (const struct file_handle *);
85
86 /* Properties of FH_REF_FILE file handles. */
87 const char *fh_get_file_name (const struct file_handle *);
88 enum fh_mode fh_get_mode (const struct file_handle *) ;
89
90 /* Properties of FH_REF_FILE and FH_REF_INLINE file handles. */
91 size_t fh_get_record_width (const struct file_handle *);
92 size_t fh_get_tab_width (const struct file_handle *);
93 const char *fh_get_legacy_encoding (const struct file_handle *);
94
95 /* Properties of FH_REF_DATASET file handles. */
96 struct dataset *fh_get_dataset (const struct file_handle *);
97
98 /* Mutual exclusion for access . */
99 struct fh_lock *fh_lock (struct file_handle *, enum fh_referent mask,
100                          const char *type, enum fh_access, bool exclusive);
101 bool fh_unlock (struct fh_lock *);
102 void *fh_lock_get_aux (const struct fh_lock *);
103 void fh_lock_set_aux (struct fh_lock *, void *aux);
104 bool fh_is_locked (const struct file_handle *, enum fh_access);
105
106 /* Default file handle for DATA LIST, REREAD, REPEATING DATA
107    commands. */
108 struct file_handle *fh_get_default_handle (void);
109 void fh_set_default_handle (struct file_handle *);
110
111 #endif