849da670fce2f1f0ebe21b830dd41386eee536e0
[pspp] / src / data / sys-file-reader.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2009, 2011, 2012, 2013, 2014 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 SFM_READ_H
18 #define SFM_READ_H 1
19
20 #include <stdbool.h>
21 #include <stdio.h>
22
23 #include "data/case.h"
24 #include "data/sys-file.h"
25 #include "libpspp/float-format.h"
26 #include "libpspp/integer-format.h"
27
28 /* Reading system files.
29
30    To read a system file:
31
32       1. Open it with sfm_open().
33
34       2. Figure out what encoding to read it with.  sfm_get_encoding() can
35          help.
36
37       3. Obtain a casereader with sfm_decode().
38
39    If, after step 1 or 2, you decide that you don't want the system file
40    anymore, you can close it with sfm_close().  Otherwise, don't call
41    sfm_close(), because sfm_decode() consumes it. */
42
43 struct dictionary;
44 struct file_handle;
45 struct sfm_read_info;
46
47 /* Opening and closing an sfm_reader. */
48 struct sfm_reader *sfm_open (struct file_handle *);
49 bool sfm_close (struct sfm_reader *);
50
51 /* Obtaining information about an sfm_reader before . */
52 const char *sfm_get_encoding (const struct sfm_reader *);
53 size_t sfm_get_strings (const struct sfm_reader *, struct pool *pool,
54                         char ***labels, bool **ids, char ***values);
55
56 /* Decoding a system file's dictionary and obtaining a casereader. */
57 struct casereader *sfm_decode (struct sfm_reader *, const char *encoding,
58                                struct dictionary **, struct sfm_read_info *);
59
60 /* Detecting whether a file is a system file. */
61 bool sfm_detect (FILE *);
62 \f
63 /* System file info that doesn't fit in struct dictionary.
64
65    The strings in this structure are encoded in UTF-8.  (They are normally in
66    the ASCII subset of UTF-8.) */
67 struct sfm_read_info
68   {
69     char *creation_date;        /* "dd mmm yy". */
70     char *creation_time;        /* "hh:mm:ss". */
71     enum integer_format integer_format;
72     enum float_format float_format;
73     enum sfm_compression compression;
74     casenumber case_cnt;        /* -1 if unknown. */
75     char *product;              /* Product name. */
76     char *product_ext;          /* Extra product info. */
77
78     /* Writer's version number in X.Y.Z format.
79        The version number is not always present; if not, then
80        all of these are set to 0. */
81     int version_major;          /* X. */
82     int version_minor;          /* Y. */
83     int version_revision;       /* Z. */
84   };
85
86 void sfm_read_info_destroy (struct sfm_read_info *);
87
88 #endif /* sys-file-reader.h */