470c45cbf7117308702130afca56223a034098a2
[pspp-builds.git] / src / 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., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #if !format_h
21 #define format_h 1
22
23 /* Display format types. */
24
25 #include "bool.h"
26
27 /* See the definitions of these functions and variables when modifying
28    this list:
29    misc.c:convert_fmt_ItoO()
30    sfm-read.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 /* Describes one of the display formats above. */
43 struct fmt_desc
44   {
45     char name[9];               /* `DATETIME' is the longest name. */
46     int n_args;                 /* 1=width; 2=width.decimals. */
47     int Imin_w, Imax_w;         /* Bounds on input width. */
48     int Omin_w, Omax_w;         /* Bounds on output width. */
49     int cat;                    /* Categories. */
50     int output;                 /* Output format. */
51     int spss;                   /* Equivalent SPSS output format. */
52   };
53
54 /* Display format categories. */
55 enum
56   {
57     FCAT_BLANKS_SYSMIS = 001,   /* 1=All-whitespace means SYSMIS. */
58     FCAT_EVEN_WIDTH = 002,      /* 1=Width must be even. */
59     FCAT_STRING = 004,          /* 1=String input/output format. */
60     FCAT_SHIFT_DECIMAL = 010,   /* 1=Automatically shift decimal point
61                                    on output--used for fixed-point
62                                    formats. */
63     FCAT_OUTPUT_ONLY = 020      /* 1=This is not an input format. */
64   };
65
66 /* Display format. */
67 struct fmt_spec
68   {
69     int type;                   /* One of the above constants. */
70     int w;                      /* Width. */
71     int d;                      /* Number of implied decimal places. */
72   };
73
74 /* Descriptions of all the display formats above. */
75 extern struct fmt_desc formats[];
76
77 union value;
78
79 /* Maximum length of formatted value, in characters. */
80 #define MAX_FORMATTED_LEN 256
81
82 /* Flags for parsing formats. */
83 enum fmt_parse_flags
84   {
85     FMTP_ALLOW_XT = 001,                /* 1=Allow X and T formats. */
86     FMTP_SUPPRESS_ERRORS = 002          /* 1=Do not emit error messages. */
87   };
88
89 int parse_format_specifier (struct fmt_spec *input, enum fmt_parse_flags);
90 int parse_format_specifier_name (const char **cp, enum fmt_parse_flags);
91 int check_input_specifier (const struct fmt_spec *spec, int emit_error);
92 int check_output_specifier (const struct fmt_spec *spec, int emit_error);
93 bool check_specifier_type (const struct fmt_spec *, int type, bool emit_error);
94 bool check_specifier_width (const struct fmt_spec *,
95                             int width, bool emit_error);
96 void convert_fmt_ItoO (const struct fmt_spec *input, struct fmt_spec *output);
97 int get_format_var_width (const struct fmt_spec *);
98 int parse_string_as_format (const char *s, int len, const struct fmt_spec *fp,
99                             int fc, union value *v);
100 int translate_fmt (int spss);
101 void data_out (char *s, const struct fmt_spec *fp, const union value *v);
102 char *fmt_to_string (const struct fmt_spec *);
103 void num_to_string (double v, char *s, int w, int d);
104
105 #endif /* !format_h */