docs
[pspp] / perl-module / typemap
1 ## PSPP - a program for statistical analysis.
2 ## Copyright (C) 2019 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 TYPEMAP
18  struct pspp_dict *    T_PTRREF
19  struct variable *     T_PTRREF
20  struct syswriter_info * T_PTRREF
21  struct sysreader_info * T_PTRREF
22  input_format  INPUT_FMT_SPEC
23  output_format OUTPUT_FMT_SPEC
24
25
26 INPUT
27 OUTPUT_FMT_SPEC
28  {
29    HV *hv = (HV *) SvRV ($arg);
30    SV** the_format = hv_fetch (hv, \"fmt\", 3, 0);
31    SV** decimals = hv_fetch (hv, \"decimals\", 8, 0);
32    SV** width = hv_fetch (hv, \"width\", 5, 0);
33
34    $var.type = the_format ? SvIV (*the_format) : FMT_F;
35    $var.w    = width ? SvIV (*width) : 8;
36    $var.d    = decimals ? SvIV (*decimals) :
37      fmt_takes_decimals ($var.type) ?
38      MIN (2, fmt_max_output_decimals ($var.type, $var.w)) : 0;
39    if ( ! fmt_check_output (&$var))
40    {
41         char buf[FMT_STRING_LEN_MAX + 1];
42         fmt_to_string (&$var, buf);
43         croak (\"%s is an invalid output format\", buf);
44    }
45
46  }
47
48
49 INPUT_FMT_SPEC
50  {
51    HV *hv = (HV *) SvRV ($arg);
52    SV** the_format = hv_fetch (hv, \"fmt\", 3, 0);
53    SV** decimals = hv_fetch (hv, \"decimals\", 8, 0);
54    SV** width = hv_fetch (hv, \"width\", 5, 0);
55
56
57    $var.type = the_format ? SvIV (*the_format) : FMT_F;
58    $var.w    = width ? SvIV (*width) : 8;
59    $var.d    = decimals ? SvIV (*decimals) :
60      fmt_takes_decimals ($var.type) ?
61      MIN (2, fmt_max_input_decimals ($var.type, $var.w)) : 0;
62    if ( ! fmt_check_input (&$var))
63    {
64         char buf[FMT_STRING_LEN_MAX + 1];
65         fmt_to_string (&$var, buf);
66         croak (\"%s is an invalid input format\", buf);
67    }
68
69  }