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
20 #include "libpspp/compiler.h"
26 /* What a file handle refers to.
27 (Ordinarily only a single value is allowed, but fh_open()
28 and fh_parse() take a mask.) */
31 FH_REF_FILE = 001, /* Ordinary file (the most common case). */
32 FH_REF_INLINE = 002, /* The inline file. */
33 FH_REF_DATASET = 004 /* Dataset. */
39 FH_MODE_TEXT, /* New-line delimited lines. */
40 FH_MODE_FIXED, /* Fixed-length records. */
41 FH_MODE_VARIABLE, /* Binary variable-length records. */
42 FH_MODE_360_VARIABLE, /* IBM 360 variable-length records. */
43 FH_MODE_360_SPANNED, /* IBM 360 variable-length, spanned records. */
46 /* Ways to access a file. */
49 FH_ACC_READ, /* Read from it. */
50 FH_ACC_WRITE /* Write to it. */
55 This affects only writing FH_MODE_TEXT files. Writing in other modes does
56 not use line ends, and reading in FH_MODE_TEXT mode accepts all forms of
60 FH_END_LF, /* Unix line ends (\n). */
61 FH_END_CRLF /* MS-DOS line ends (\r\n). */
64 /* Properties of a file handle. */
67 enum fh_mode mode; /* File mode. */
68 enum fh_line_ends line_ends; /* Line ends for text files. */
69 size_t record_width; /* Length of fixed-format records. */
70 size_t tab_width; /* Tab width, 0=do not expand tabs. */
71 const char *encoding; /* Charset for contents. */
77 /* Creating file handles. */
78 struct file_handle *fh_create_file (const char *handle_name,
79 const char *file_name, const char *file_name_encoding,
80 const struct fh_properties *);
81 struct file_handle *fh_create_dataset (struct dataset *);
82 const struct fh_properties *fh_default_properties (void);
84 /* Reference management. */
85 struct file_handle *fh_ref (struct file_handle *) WARN_UNUSED_RESULT;
86 void fh_unref (struct file_handle *);
87 void fh_unname (struct file_handle *);
89 /* Finding file handles. */
90 struct file_handle *fh_from_id (const char *handle_name);
91 struct file_handle *fh_inline_file (void);
93 /* Generic properties of file handles. */
94 const char *fh_get_id (const struct file_handle *);
95 const char *fh_get_name (const struct file_handle *);
96 enum fh_referent fh_get_referent (const struct file_handle *);
97 const char *fh_get_encoding (const struct file_handle *);
99 bool fh_equal (const struct file_handle *, const struct file_handle *);
101 /* Properties of FH_REF_FILE file handles. */
102 const char *fh_get_file_name (const struct file_handle *);
103 const char *fh_get_file_name_encoding (const struct file_handle *handle);
104 enum fh_mode fh_get_mode (const struct file_handle *) ;
105 enum fh_line_ends fh_get_line_ends (const struct file_handle *);
107 /* Properties of FH_REF_FILE and FH_REF_INLINE file handles. */
108 size_t fh_get_record_width (const struct file_handle *);
109 size_t fh_get_tab_width (const struct file_handle *);
111 /* Properties of FH_REF_DATASET file handles. */
112 struct dataset *fh_get_dataset (const struct file_handle *);
114 /* Mutual exclusion for access . */
115 struct fh_lock *fh_lock (struct file_handle *, enum fh_referent mask,
116 const char *type, enum fh_access, bool exclusive);
117 bool fh_unlock (struct fh_lock *);
118 void *fh_lock_get_aux (const struct fh_lock *);
119 void fh_lock_set_aux (struct fh_lock *, void *aux);
120 bool fh_is_locked (const struct file_handle *, enum fh_access);
122 /* Default file handle for DATA LIST, REREAD, REPEATING DATA
124 struct file_handle *fh_get_default_handle (void);
125 void fh_set_default_handle (struct file_handle *);