1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2005, 2006, 2011 Free Software Foundation, Inc.
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.
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.
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/>. */
17 #ifndef FILE_HANDLE_DEF_H
18 #define FILE_HANDLE_DEF_H
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.) */
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. */
36 FH_MODE_TEXT, /* New-line delimited lines. */
37 FH_MODE_FIXED, /* Fixed-length records. */
38 FH_MODE_VARIABLE, /* Binary variable-length records. */
39 FH_MODE_360_VARIABLE, /* IBM 360 variable-length records. */
40 FH_MODE_360_SPANNED, /* IBM 360 variable-length, spanned records. */
43 /* Ways to access a file. */
46 FH_ACC_READ, /* Read from it. */
47 FH_ACC_WRITE /* Write to it. */
50 /* Properties of a file handle. */
53 enum fh_mode mode; /* File mode. */
54 size_t record_width; /* Length of fixed-format records. */
55 size_t tab_width; /* Tab width, 0=do not expand tabs. */
56 const char *encoding; /* ASCII or EBCDIC? */
62 /* Creating file handles. */
63 struct file_handle *fh_create_file (const char *handle_name,
64 const char *file_name,
65 const struct fh_properties *);
66 struct file_handle *fh_create_scratch (const char *handle_name);
67 const struct fh_properties *fh_default_properties (void);
69 /* Reference management. */
70 struct file_handle *fh_ref (struct file_handle *);
71 void fh_unref (struct file_handle *);
72 void fh_unname (struct file_handle *);
74 /* Finding file handles. */
75 struct file_handle *fh_from_id (const char *handle_name);
76 struct file_handle *fh_from_file_name (const char *file_name);
77 struct file_handle *fh_inline_file (void);
79 /* Generic properties of file handles. */
80 const char *fh_get_id (const struct file_handle *);
81 const char *fh_get_name (const struct file_handle *);
82 enum fh_referent fh_get_referent (const struct file_handle *);
84 /* Properties of FH_REF_FILE file handles. */
85 const char *fh_get_file_name (const struct file_handle *);
86 enum fh_mode fh_get_mode (const struct file_handle *) ;
88 /* Properties of FH_REF_FILE and FH_REF_INLINE file handles. */
89 size_t fh_get_record_width (const struct file_handle *);
90 size_t fh_get_tab_width (const struct file_handle *);
91 const char *fh_get_legacy_encoding (const struct file_handle *);
93 /* Properties of FH_REF_SCRATCH file handles. */
94 struct scratch_handle *fh_get_scratch_handle (const struct file_handle *);
95 void fh_set_scratch_handle (struct file_handle *, struct scratch_handle *);
97 /* Mutual exclusion for access . */
98 struct fh_lock *fh_lock (struct file_handle *, enum fh_referent mask,
99 const char *type, enum fh_access, bool exclusive);
100 bool fh_unlock (struct fh_lock *);
101 void *fh_lock_get_aux (const struct fh_lock *);
102 void fh_lock_set_aux (struct fh_lock *, void *aux);
103 bool fh_is_locked (const struct file_handle *, enum fh_access);
105 /* Default file handle for DATA LIST, REREAD, REPEATING DATA
107 struct file_handle *fh_get_default_handle (void);
108 void fh_set_default_handle (struct file_handle *);