checkin of 0.3.0
[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 /* See the definitions of these functions and variables when modifying
25    this list:
26    misc.c:convert_fmt_ItoO()
27    sfm-read.c:parse_format_spec()
28    data-in.c:parse_string_as_format()
29    data-out.c:convert_format_to_string(). */
30 #define DEFFMT(LABEL, NAME, N_ARGS, IMIN_W, IMAX_W, OMIN_W, OMAX_W,     \
31                CAT, OUTPUT, SPSS_FMT)                                   \
32         LABEL,
33 enum
34   {
35 #include "format.def"
36     FMT_NUMBER_OF_FORMATS
37   };
38 #undef DEFFMT
39
40 /* Describes one of the display formats above. */
41 struct fmt_desc
42   {
43     char name[9];               /* `DATETIME' is the longest name. */
44     int n_args;                 /* 1=width; 2=width.decimals. */
45     int Imin_w, Imax_w;         /* Bounds on input width. */
46     int Omin_w, Omax_w;         /* Bounds on output width. */
47     int cat;                    /* Categories. */
48     int output;                 /* Output format. */
49     int spss;                   /* Equivalent SPSS output format. */
50   };
51
52 /* Display format categories. */
53 enum
54   {
55     FCAT_BLANKS_SYSMIS = 001,   /* 1=All-whitespace means SYSMIS. */
56     FCAT_EVEN_WIDTH = 002,      /* 1=Width must be even. */
57     FCAT_STRING = 004,          /* 1=String input/output format. */
58     FCAT_SHIFT_DECIMAL = 010,   /* 1=Automatically shift decimal point
59                                    on output--used for fixed-point
60                                    formats. */
61     FCAT_OUTPUT_ONLY = 020      /* 1=This is not an input format. */
62   };
63
64 /* Display format. */
65 struct fmt_spec
66   {
67     int type;                   /* One of the above constants. */
68     int w;                      /* Width. */
69     int d;                      /* Number of implied decimal places. */
70   };
71
72 /* Descriptions of all the display formats above. */
73 extern struct fmt_desc formats[];
74
75 /* Translates SPSS formats to PSPP formats. */
76 extern const int translate_fmt[40];
77
78 union value;
79
80 int parse_format_specifier (struct fmt_spec *input, int allow_xt);
81 int parse_format_specifier_name (const char **cp, int allow_xt);
82 int check_input_specifier (const struct fmt_spec *spec);
83 int check_output_specifier (const struct fmt_spec *spec);
84 int check_string_specifier (const struct fmt_spec *spec, int min_len);
85 void convert_fmt_ItoO (const struct fmt_spec *input, struct fmt_spec *output);
86 int parse_string_as_format (const char *s, int len, const struct fmt_spec *fp,
87                             int fc, union value *v);
88 int data_out (char *s, const struct fmt_spec *fp, const union value *v);
89 char *fmt_to_string (const struct fmt_spec *);
90 void num_to_string (double v, char *s, int w, int d);
91
92 #endif /* !format_h */