line-reader: New library for reading a file line-by-line.
[pspp] / src / libpspp / line-reader.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 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 LIBPSPP_LINE_READER_H
18 #define LIBPSPP_LINE_READER_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <sys/types.h>
23
24 /* line_reader.
25
26    Reads a text file in an arbitrary encoding one line at a time, with
27    optional automatic encoding detection.
28 */
29
30 #define LINE_READER_BUFFER_SIZE 4096
31
32 struct string;
33
34 struct line_reader *line_reader_for_fd (const char *encoding, int fd);
35 struct line_reader *line_reader_for_file (const char *encoding,
36                                           const char *filename, int flags);
37
38 int line_reader_close (struct line_reader *);
39 void line_reader_free (struct line_reader *);
40
41 bool line_reader_read (struct line_reader *, struct string *,
42                        size_t max_length);
43
44 int line_reader_fileno (const struct line_reader *);
45 off_t line_reader_tell (const struct line_reader *);
46
47 bool line_reader_eof (const struct line_reader *);
48 int line_reader_error (const struct line_reader *);
49
50 const char *line_reader_get_encoding (const struct line_reader *);
51
52 bool line_reader_is_auto (const struct line_reader *);
53
54 #endif /* libpspp/line-reader.h */