2c7074d24adb8be393aeb566f44e7662d2dfd4fa
[pspp-builds.git] / src / data / format.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #if !format_h
21 #define format_h 1
22
23 /* Display format types. */
24
25 #include <stdbool.h>
26
27 /* See the definitions of these functions and variables when modifying
28    this list:
29    misc.c:convert_fmt_ItoO()
30    sys-file-reader.c:parse_format_spec()
31    data-in.c:parse_string_as_format() */
32 #define DEFFMT(LABEL, NAME, N_ARGS, IMIN_W, IMAX_W, OMIN_W, OMAX_W,     \
33                CAT, OUTPUT, SPSS_FMT)                                   \
34         LABEL,
35 enum
36   {
37 #include "format.def"
38     FMT_NUMBER_OF_FORMATS
39   };
40 #undef DEFFMT
41
42 /* Length of longest format specifier name,
43    not including terminating null. */
44 #define FMT_TYPE_LEN_MAX 8
45
46 /* Describes one of the display formats above. */
47 struct fmt_desc
48   {
49     char name[FMT_TYPE_LEN_MAX + 1]; /* Name, in all caps. */
50     int n_args;                 /* 1=width; 2=width.decimals. */
51     int Imin_w, Imax_w;         /* Bounds on input width. */
52     int Omin_w, Omax_w;         /* Bounds on output width. */
53     int cat;                    /* Categories. */
54     int output;                 /* Output format. */
55     int spss;                   /* Equivalent SPSS output format. */
56   };
57
58 /* Display format categories. */
59 enum
60   {
61     FCAT_BLANKS_SYSMIS = 001,   /* 1=All-whitespace means SYSMIS. */
62     FCAT_EVEN_WIDTH = 002,      /* 1=Width must be even. */
63     FCAT_STRING = 004,          /* 1=String input/output format. */
64     FCAT_SHIFT_DECIMAL = 010,   /* 1=Automatically shift decimal point
65                                    on output--used for fixed-point
66                                    formats. */
67     FCAT_OUTPUT_ONLY = 020      /* 1=This is not an input format. */
68   };
69
70 /* Display format. */
71 struct fmt_spec
72   {
73     int type;                   /* One of the above constants. */
74     int w;                      /* Width. */
75     int d;                      /* Number of implied decimal places. */
76   };
77
78
79 enum alignment 
80   {
81     ALIGN_LEFT = 0,
82     ALIGN_RIGHT = 1,
83     ALIGN_CENTRE = 2, 
84     n_ALIGN
85   };
86
87
88 enum measure
89   {
90     MEASURE_NOMINAL=1,
91     MEASURE_ORDINAL=2,
92     MEASURE_SCALE=3,
93     n_MEASURES
94   };
95
96 bool measure_is_valid(enum measure m);
97 bool alignment_is_valid(enum alignment a);
98
99
100 /* Descriptions of all the display formats above. */
101 extern const struct fmt_desc formats[];
102
103 union value;
104
105 /* Maximum length of formatted value, in characters. */
106 #define MAX_FORMATTED_LEN 256
107
108 /* Common formats. */
109 extern const struct fmt_spec f8_2;      /* F8.2. */
110
111 int check_input_specifier (const struct fmt_spec *spec, int emit_error);
112 int check_output_specifier (const struct fmt_spec *spec, int emit_error);
113 bool check_specifier_type (const struct fmt_spec *, int type, bool emit_error);
114 bool check_specifier_width (const struct fmt_spec *,
115                             int width, bool emit_error);
116 void convert_fmt_ItoO (const struct fmt_spec *input, struct fmt_spec *output);
117 int get_format_var_width (const struct fmt_spec *);
118 int parse_string_as_format (const char *s, int len, const struct fmt_spec *fp,
119                             int fc, union value *v);
120 int translate_fmt (int spss);
121 bool data_out (char *s, const struct fmt_spec *fp, const union value *v);
122 bool fmt_type_from_string (const char *name, int *type);
123 char *fmt_to_string (const struct fmt_spec *);
124 struct fmt_spec make_input_format (int type, int w, int d);
125 struct fmt_spec make_output_format (int type, int w, int d);
126 bool fmt_is_binary (int type);
127
128 #endif /* !format_h */