1 /* PSPP - a program for statistical analysis. 2 Copyright (C) 2006, 2010, 2012, 2014, 2015 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 /* The name of this kind of data file, e.g. "SPSS System File". */ 38 const char *name; 39 40 /* Detects whether FILE contains this type of file. Returns 1 if so, 0 if 41 not, and a negative errno value if there is an error reading FILE. */ 42 int (*detect) (FILE *file); 43 44 struct any_reader *(*open) (struct file_handle *); 45 bool (*close) (struct any_reader *); 46 struct casereader *(*decode) (struct any_reader *, const char *encoding, 47 struct dictionary **, 48 struct any_read_info *); 49 size_t (*get_strings) (const struct any_reader *, struct pool *pool, 50 char ***labels, bool **ids, char ***values); 51 }; 52 53 extern const struct any_reader_class sys_file_reader_class; 54 extern const struct any_reader_class por_file_reader_class; 55 extern const struct any_reader_class pcp_file_reader_class; 56 57 enum any_type 58 { 59 ANY_SYS, /* SPSS System File. */ 60 ANY_PCP, /* SPSS/PC+ System File. */ 61 ANY_POR, /* SPSS Portable File. */ 62 }; 63 64 enum any_compression 65 { 66 ANY_COMP_NONE, /* No compression. */ 67 ANY_COMP_SIMPLE, /* Bytecode compression of integer values. */ 68 ANY_COMP_ZLIB /* ZLIB "deflate" compression. */ 69 }; 70 71 /* Data file info that doesn't fit in struct dictionary. 72 73 The strings in this structure are encoded in UTF-8. (They are normally in 74 the ASCII subset of UTF-8.) */ 75 struct any_read_info 76 { 77 const struct any_reader_class *klass; 78 char *creation_date; 79 char *creation_time; 80 enum integer_format integer_format; 81 enum float_format float_format; 82 enum any_compression compression; 83 casenumber case_cnt; /* -1 if unknown. */ 84 char *product; /* Product name. */ 85 char *product_ext; /* Extra product info. */ 86 87 /* Writer's version number in X.Y.Z format. 88 The version number is not always present; if not, then 89 all of these are set to 0. */ 90 int version_major; /* X. */ 91 int version_minor; /* Y. */ 92 int version_revision; /* Z. */ 93 }; 94 95 void any_read_info_destroy (struct any_read_info *); 96 97 struct file_handle; 98 struct dictionary; 99 100 int any_reader_detect (const struct file_handle *file_name, 101 const struct any_reader_class **); 102 103 struct any_reader *any_reader_open (struct file_handle *); 104 bool any_reader_close (struct any_reader *); 105 struct casereader *any_reader_decode (struct any_reader *, 106 const char *encoding, 107 struct dictionary **, 108 struct any_read_info *); 109 size_t any_reader_get_strings (const struct any_reader *, struct pool *pool, 110 char ***labels, bool **ids, char ***values); 111 112 struct casereader *any_reader_open_and_decode (struct file_handle *, 113 const char *encoding, 114 struct dictionary **, 115 struct any_read_info *); 116 117 #endif /* any-reader.h */ 118