1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2005, 2006, 2010, 2011, 2013 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
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.) */
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. */
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. */
45 /* Ways to access a file. */
48 FH_ACC_READ, /* Read from it. */
49 FH_ACC_WRITE /* Write to it. */
54 This affects only writing FH_MODE_TEXT files. Writing in other modes does
55 not use line ends, and reading in FH_MODE_TEXT mode accepts all forms of
59 FH_END_LF, /* Unix line ends (\n). */
60 FH_END_CRLF /* MS-DOS line ends (\r\n). */
63 /* Properties of a file handle. */
66 enum fh_mode mode; /* File mode. */
67 enum fh_line_ends line_ends; /* Line ends for text files. */
68 size_t record_width; /* Length of fixed-format records. */
69 size_t tab_width; /* Tab width, 0=do not expand tabs. */
70 const char *encoding; /* Charset for contents. */
76 /* Creating file handles. */
77 struct file_handle *fh_create_file (const char *handle_name,
78 const char *file_name, const char *file_name_encoding,
79 const struct fh_properties *);
80 struct file_handle *fh_create_dataset (struct dataset *);
81 const struct fh_properties *fh_default_properties (void);
83 /* Reference management. */
84 struct file_handle *fh_ref (struct file_handle *);
85 void fh_unref (struct file_handle *);
86 void fh_unname (struct file_handle *);
88 /* Finding file handles. */
89 struct file_handle *fh_from_id (const char *handle_name);
90 struct file_handle *fh_inline_file (void);
92 /* Generic properties of file handles. */
93 const char *fh_get_id (const struct file_handle *);
94 const char *fh_get_name (const struct file_handle *);
95 enum fh_referent fh_get_referent (const struct file_handle *);
96 const char *fh_get_encoding (const struct file_handle *);
98 /* Properties of FH_REF_FILE file handles. */
99 const char *fh_get_file_name (const struct file_handle *);
100 const char *fh_get_file_name_encoding (const struct file_handle *handle);
101 enum fh_mode fh_get_mode (const struct file_handle *) ;
102 enum fh_line_ends fh_get_line_ends (const struct file_handle *);
104 /* Properties of FH_REF_FILE and FH_REF_INLINE file handles. */
105 size_t fh_get_record_width (const struct file_handle *);
106 size_t fh_get_tab_width (const struct file_handle *);
108 /* Properties of FH_REF_DATASET file handles. */
109 struct dataset *fh_get_dataset (const struct file_handle *);
111 /* Mutual exclusion for access . */
112 struct fh_lock *fh_lock (struct file_handle *, enum fh_referent mask,
113 const char *type, enum fh_access, bool exclusive);
114 bool fh_unlock (struct fh_lock *);
115 void *fh_lock_get_aux (const struct fh_lock *);
116 void fh_lock_set_aux (struct fh_lock *, void *aux);
117 bool fh_is_locked (const struct file_handle *, enum fh_access);
119 /* Default file handle for DATA LIST, REREAD, REPEATING DATA
121 struct file_handle *fh_get_default_handle (void);
122 void fh_set_default_handle (struct file_handle *);