Add support for reading SPSS/PC+ system files.
[pspp] / src / data / any-reader.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2006, 2010, 2012, 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 ANY_READER_H
18 #define ANY_READER_H 1
19
20 #include <stdbool.h>
21 #include <stdio.h>
22 #include "data/case.h"
23 #include "libpspp/float-format.h"
24 #include "libpspp/integer-format.h"
25
26 struct any_read_info;
27 struct dictionary;
28 struct file_handle;
29
30 struct any_reader
31   {
32     const struct any_reader_class *klass;
33   };
34
35 struct any_reader_class
36   {
37     const char *name;
38
39     int (*detect) (FILE *);
40
41     struct any_reader *(*open) (struct file_handle *);
42     bool (*close) (struct any_reader *);
43     struct casereader *(*decode) (struct any_reader *, const char *encoding,
44                                   struct dictionary **,
45                                   struct any_read_info *);
46     size_t (*get_strings) (const struct any_reader *, struct pool *pool,
47                            char ***labels, bool **ids, char ***values);
48   };
49
50 extern const struct any_reader_class sys_file_reader_class;
51 extern const struct any_reader_class por_file_reader_class;
52 extern const struct any_reader_class pcp_file_reader_class;
53
54 enum any_type
55   {
56     ANY_SYS,                    /* SPSS System File. */
57     ANY_PCP,                    /* SPSS/PC+ System File. */
58     ANY_POR,                    /* SPSS Portable File. */
59   };
60
61 enum any_compression
62   {
63     ANY_COMP_NONE,              /* No compression. */
64     ANY_COMP_SIMPLE,            /* Bytecode compression of integer values. */
65     ANY_COMP_ZLIB               /* ZLIB "deflate" compression. */
66   };
67
68 /* Data file info that doesn't fit in struct dictionary.
69
70    The strings in this structure are encoded in UTF-8.  (They are normally in
71    the ASCII subset of UTF-8.) */
72 struct any_read_info
73   {
74     const struct any_reader_class *klass;
75     char *creation_date;
76     char *creation_time;
77     enum integer_format integer_format;
78     enum float_format float_format;
79     enum any_compression compression;
80     casenumber case_cnt;        /* -1 if unknown. */
81     char *product;              /* Product name. */
82     char *product_ext;          /* Extra product info. */
83
84     /* Writer's version number in X.Y.Z format.
85        The version number is not always present; if not, then
86        all of these are set to 0. */
87     int version_major;          /* X. */
88     int version_minor;          /* Y. */
89     int version_revision;       /* Z. */
90   };
91
92 void any_read_info_destroy (struct any_read_info *);
93
94 struct file_handle;
95 struct dictionary;
96
97 int any_reader_detect (const char *file_name,
98                        const struct any_reader_class **);
99
100 struct any_reader *any_reader_open (struct file_handle *);
101 bool any_reader_close (struct any_reader *);
102 struct casereader *any_reader_decode (struct any_reader *,
103                                       const char *encoding,
104                                       struct dictionary **,
105                                       struct any_read_info *);
106 size_t any_reader_get_strings (const struct any_reader *, struct pool *pool,
107                                char ***labels, bool **ids, char ***values);
108
109 struct casereader *any_reader_open_and_decode (struct file_handle *,
110                                                const char *encoding,
111                                                struct dictionary **,
112                                                struct any_read_info *);
113
114 #endif /* any-reader.h */