work on PRINT encoding
[pspp] / src / data / sys-file-private.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2006-2007, 2009-2012 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 /* Infrastructure common to system file reader and writer.
18
19    Old versions of SPSS limited string variables to a width of
20    255 bytes.  For backward compatibility with these older
21    versions, the system file format represents a string longer
22    than 255 bytes, called a "very long string", as a collection
23    of strings no longer than 255 bytes each.  The strings
24    concatenated to make a very long string are called its
25    "segments"; for consistency, variables other than very long
26    strings are considered to have a single segment.
27
28    The interfaces in this file primarily provide support for
29    dealing with very long strings.  */
30
31 #ifndef DATA_SYS_FILE_PRIVATE_H
32 #define DATA_SYS_FILE_PRIVATE_H 1
33
34 #include <stddef.h>
35
36 struct dictionary;
37
38 /* Magic numbers.
39
40    Both of these are actually $FL2 in the respective character set.  The "FL2"
41    part is invariant among national variants of each character set, but "$" has
42    different encodings, so it is safer to write them as hexadecimal. */
43 #define ASCII_MAGIC  "\x24\x46\x4c\x32"
44 #define EBCDIC_MAGIC "\x5b\xc6\xd3\xf2"
45
46 /* A variable in a system file. */
47 struct sfm_var
48   {
49     int var_width;              /* Variable width (0 to 32767). */
50     int segment_width;          /* Segment width (0 to 255). */
51     int case_index;             /* Index into case. */
52
53     /* The following members are interesting only for string
54        variables (width != 0).  For numeric variables (width ==
55        0) their values are always 0.
56
57        Note: width + padding is always a multiple of 8. */
58     int offset;                 /* Offset within string variable in case. */
59     int padding;                /* Number of padding bytes following data. */
60   };
61
62 int sfm_dictionary_to_sfm_vars (const struct dictionary *,
63                                 struct sfm_var **, size_t *);
64
65 int sfm_width_to_octs (int width);
66 int sfm_width_to_segments (int width);
67
68 int sfm_segment_effective_offset (int width, int segment);
69 int sfm_segment_alloc_width (int width, int segment);
70
71 /* A mapping between an encoding name and a Windows codepage. */
72 struct sys_encoding
73   {
74     int number;
75     const char *name;
76   };
77
78 extern struct sys_encoding sys_codepage_number_to_name[];
79 extern struct sys_encoding sys_codepage_name_to_number[];
80
81 int sys_get_codepage_from_encoding (const char *);
82 const char *sys_get_encoding_from_codepage (int);
83
84 #endif /* data/sys-file-private.h */