Add support for reading and writing SPV files.
[pspp] / src / output / spv / spv-legacy-data.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2018 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 OUTPUT_SPV_LEGACY_DATA_H
18 #define OUTPUT_SPV_LEGACY_DATA_H 1
19
20 /* SPSS Viewer (SPV) legacy binary data decoder.
21
22    Used by spv.h, not useful directly. */
23
24 #include <stdbool.h>
25 #include <stddef.h>
26 #include <stdint.h>
27 #include <stdio.h>
28 #include "libpspp/compiler.h"
29
30 struct spv_data
31   {
32     struct spv_data_source *sources;
33     size_t n_sources;
34   };
35
36 void spv_data_uninit (struct spv_data *);
37 void spv_data_dump (const struct spv_data *, FILE *);
38
39 struct spv_data_source *spv_data_find_source (const struct spv_data *,
40                                               const char *source_name);
41 struct spv_data_variable *spv_data_find_variable (const struct spv_data *,
42                                                   const char *source_name,
43                                                   const char *variable_name);
44
45 struct spv_data_source
46   {
47     char *source_name;
48     struct spv_data_variable *vars;
49     size_t n_vars, n_values;
50   };
51
52 void spv_data_source_uninit (struct spv_data_source *);
53 void spv_data_source_dump (const struct spv_data_source *, FILE *);
54
55 struct spv_data_variable *spv_data_source_find_variable (
56   const struct spv_data_source *, const char *variable_name);
57
58 struct spv_data_variable
59   {
60     char *var_name;
61     struct spv_data_value *values;
62     size_t n_values;
63   };
64
65 void spv_data_variable_uninit (struct spv_data_variable *);
66 void spv_data_variable_dump (const struct spv_data_variable *, FILE *);
67
68 struct spv_data_value
69   {
70     double index;
71     int width;
72     union
73       {
74         double d;
75         char *s;
76       };
77   };
78
79 void spv_data_value_uninit (struct spv_data_value *);
80 bool spv_data_value_equal (const struct spv_data_value *,
81                            const struct spv_data_value *);
82 struct spv_data_value *spv_data_values_clone (const struct spv_data_value *,
83                                               size_t n);
84
85 char *spv_legacy_data_decode (const uint8_t *in, size_t size,
86                               struct spv_data *out) WARN_UNUSED_RESULT;
87 void spv_data_value_dump (const struct spv_data_value *, FILE *);
88
89 #endif /* output/spv/spv-legacy-data.h */