X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsettings.c;h=b0fc89ae55e1d9b4145ff8c64f18e9bcf804b02d;hb=a1d8ce0ad176357cf250ec065e0bf1a4520a19e3;hp=37fda6006ee3e99858abb9c7bbb1b1014cb17ffe;hpb=655bf3a3917cdf16f99fcbb680d2bf3159126a93;p=pspp-builds.git diff --git a/src/data/settings.c b/src/data/settings.c index 37fda600..b0fc89ae 100644 --- a/src/data/settings.c +++ b/src/data/settings.c @@ -1,21 +1,18 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. - Written by Ben Pfaff . +/* PSPP - a program for statistical analysis. + Copyright (C) 1997-9, 2000, 2006, 2007 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with this program. If not, see . */ #include #include "settings.h" @@ -27,22 +24,27 @@ #include "xalloc.h" #include +#include "error.h" + +#include "gettext.h" +#define _(msgid) gettext (msgid) + static int viewlength = 24; static int viewwidth = 79; static bool long_view = false; static bool safer_mode = false; -static char decimal = '.'; -static char grouping = ','; - -static bool echo = false; +static bool do_echo = false; static bool include = true; static int epoch = -1; static bool errorbreak = false; +static bool route_errors_to_terminal = true; +static bool route_errors_to_listing = true; + static bool scompress = true; static bool undefined = true; @@ -64,16 +66,6 @@ static size_t workspace = 4L * 1024 * 1024; static struct fmt_spec default_format = {FMT_F, 8, 2}; -#define CC_INITIALIZER {"-", "", "", "", '.', ','} -static struct custom_currency cc[CC_CNT] = - { - CC_INITIALIZER, - CC_INITIALIZER, - CC_INITIALIZER, - CC_INITIALIZER, - CC_INITIALIZER, - }; - static bool testing_mode = false; static int global_algorithm = ENHANCED; @@ -83,6 +75,7 @@ static int *algorithm = &global_algorithm; static int syntax = ENHANCED; static void init_viewport (void); +static void get_termcap_viewport (void); void settings_init (void) @@ -106,7 +99,7 @@ get_viewlength (void) /* Sets the view length. */ void -set_viewlength (int viewlength_) +set_viewlength (int viewlength_) { viewlength = viewlength_; } @@ -129,43 +122,20 @@ get_viewwidth(void) /* Sets the screen width. */ void -set_viewwidth (int viewwidth_) +set_viewwidth (int viewwidth_) { viewwidth = viewwidth_; } -#if HAVE_LIBTERMCAP static void -get_termcap_viewport (void) -{ - char term_buffer[16384]; - if (getenv ("TERM") == NULL) - return; - else if (tgetent (term_buffer, getenv ("TERM")) <= 0) - { - msg (IE, _("Could not access definition for terminal `%s'."), termtype); - return; - } - - if (tgetnum ("li") > 0) - viewlength = tgetnum ("li"); - - if (tgetnum ("co") > 1) - viewwidth = tgetnum ("co") - 1; -} -#endif /* HAVE_LIBTERMCAP */ - -static void init_viewport (void) { if (long_view) return; - + viewwidth = viewlength = -1; -#if HAVE_LIBTERMCAP get_termcap_viewport (); -#endif /* HAVE_LIBTERMCAP */ if (viewwidth < 0 && getenv ("COLUMNS") != NULL) viewwidth = atoi (getenv ("COLUMNS")); @@ -192,53 +162,18 @@ set_safer_mode (void) safer_mode = true; } -/* The character used for a decimal point: ',' or '.'. Only - respected for data input and output. */ -char -get_decimal (void) -{ - return decimal; -} - -/* Sets the character used for a decimal point, which must be - either ',' or '.'. */ -void -set_decimal (char decimal_) -{ - assert (decimal_ == '.' || decimal_ == ','); - decimal = decimal_; -} - -/* The character used for grouping in numbers: '.' or ','; the - opposite of set_decimal. Only used in COMMA data input and - output. */ -char -get_grouping (void) -{ - return grouping; -} - -/* Sets the character used for grouping, which must be either ',' - or '.'. */ -void -set_grouping (char grouping_) -{ - assert (grouping_ == '.' || grouping_ == ','); - grouping = grouping_; -} - /* Echo commands to the listing file/printer? */ bool get_echo (void) { - return echo; + return do_echo; } /* Set echo. */ void -set_echo (bool echo_) +set_echo (bool echo_) { - echo = echo_; + do_echo = echo_; } /* If echo is on, whether commands from include files are echoed. */ @@ -250,16 +185,16 @@ get_include (void) /* Set include file echo. */ void -set_include (bool include_) +set_include (bool include_) { include = include_; } /* What year to use as the start of the epoch. */ int -get_epoch (void) +get_epoch (void) { - if (epoch < 0) + if (epoch < 0) { time_t t = time (0); struct tm *tm = localtime (&t); @@ -271,7 +206,7 @@ get_epoch (void) /* Sets the year that starts the epoch. */ void -set_epoch (int epoch_) +set_epoch (int epoch_) { epoch = epoch_; } @@ -285,13 +220,43 @@ get_errorbreak (void) /* Sets whether an error stops execution. */ void -set_errorbreak (bool errorbreak_) +set_errorbreak (bool errorbreak_) { errorbreak = errorbreak_; } +/* Route error messages to terminal? */ +bool +get_error_routing_to_terminal (void) +{ + return route_errors_to_terminal; +} + +/* Sets whether error messages should be routed to the + terminal. */ +void +set_error_routing_to_terminal (bool route_to_terminal) +{ + route_errors_to_terminal = route_to_terminal; +} + +/* Route error messages to listing file? */ +bool +get_error_routing_to_listing (void) +{ + return route_errors_to_listing; +} + +/* Sets whether error messages should be routed to the + listing file. */ +void +set_error_routing_to_listing (bool route_to_listing) +{ + route_errors_to_listing = route_to_listing; +} + /* Compress system files by default? */ -bool +bool get_scompression (void) { return scompress; @@ -299,7 +264,7 @@ get_scompression (void) /* Set system file default compression. */ void -set_scompression (bool scompress_) +set_scompression (bool scompress_) { scompress = scompress_; } @@ -313,7 +278,7 @@ get_undefined (void) /* Set whether to warn on undefined values. */ void -set_undefined (bool undefined_) +set_undefined (bool undefined_) { undefined = undefined_; } @@ -328,7 +293,7 @@ get_blanks (void) /* Set the value that blank numeric fields are set to when read in. */ void -set_blanks (double blanks_) +set_blanks (double blanks_) { blanks = blanks_; } @@ -336,13 +301,13 @@ set_blanks (double blanks_) /* Maximum number of warnings + errors. */ int get_mxwarns (void) -{ +{ return mxwarns; } /* Sets maximum number of warnings + errors. */ void -set_mxwarns (int mxwarns_) +set_mxwarns (int mxwarns_) { mxwarns = mxwarns_; } @@ -356,7 +321,7 @@ get_mxerrs (void) /* Sets maximum number of errors. */ void -set_mxerrs (int mxerrs_) +set_mxerrs (int mxerrs_) { mxerrs = mxerrs_; } @@ -370,7 +335,7 @@ get_printback (void) /* Sets whether commands are written to the display. */ void -set_printback (bool printback_) +set_printback (bool printback_) { printback = printback_; } @@ -386,7 +351,7 @@ get_mprint (void) /* Sets whether the commands generated by macro invocations are displayed. */ void -set_mprint (bool mprint_) +set_mprint (bool mprint_) { mprint = mprint_; } @@ -400,7 +365,7 @@ get_mxloops (void) /* Set implied limit of unbounded loop. */ void -set_mxloops (int mxloops_) +set_mxloops (int mxloops_) { mxloops = mxloops_; } @@ -428,7 +393,7 @@ get_endcmd (void) /* Set the character used to terminate commands. */ void -set_endcmd (char endcmd_) +set_endcmd (char endcmd_) { endcmd = endcmd_; } @@ -441,11 +406,21 @@ get_workspace (void) return workspace; } +/* Approximate maximum number of cases to allocate in-core, given + that each case contains VALUE_CNT values. */ +size_t +get_workspace_cases (size_t value_cnt) +{ + size_t case_size = sizeof (union value) * value_cnt + 4 * sizeof (void *); + size_t case_cnt = MAX (get_workspace () / case_size, 4); + return case_cnt; +} + /* Set approximate maximum amount of memory to use for cases, in bytes. */ void -set_workspace (size_t workspace_) +set_workspace (size_t workspace_) { workspace = workspace_; } @@ -454,45 +429,29 @@ set_workspace (size_t workspace_) DATA LIST {FREE,LIST}. */ const struct fmt_spec * get_format (void) -{ +{ return &default_format; } /* Set default format for variables created by transformations and by DATA LIST {FREE,LIST}. */ void -set_format (const struct fmt_spec *default_format_) +set_format (const struct fmt_spec *default_format_) { default_format = *default_format_; } -/* Gets the custom currency specification with the given IDX. */ -const struct custom_currency * -get_cc (int idx) -{ - assert (idx >= 0 && idx < CC_CNT); - return &cc[idx]; -} - -/* Gets custom currency specification IDX to CC. */ -void -set_cc (int idx, const struct custom_currency *cc_) -{ - assert (idx >= 0 && idx < CC_CNT); - cc[idx] = *cc_; -} - /* Are we in testing mode? (e.g. --testing-mode command line option) */ bool -get_testing_mode (void) +get_testing_mode (void) { return testing_mode; } /* Set testing mode. */ void -set_testing_mode (bool testing_mode_) +set_testing_mode (bool testing_mode_) { testing_mode = testing_mode_; } @@ -505,17 +464,17 @@ get_algorithm (void) } /* Set the algorithm option globally. */ -void +void set_algorithm (enum behavior_mode mode) { global_algorithm = mode; } /* Set the algorithm option for this command only */ -void +void set_cmd_algorithm (enum behavior_mode mode) { - cmd_algorithm = mode; + cmd_algorithm = mode; algorithm = &cmd_algorithm; } @@ -534,8 +493,43 @@ get_syntax (void) } /* Set the syntax option */ -void +void set_syntax (enum behavior_mode mode) { syntax = mode; } + +/* Code that interfaces to ncurses. This must be at the very end + of this file because curses.h redefines "bool" on some systems + (e.g. OpenBSD), causing declaration mismatches with functions + that have parameters or return values of type "bool". */ +#if HAVE_LIBNCURSES +#include +#include + +static void +get_termcap_viewport (void) +{ + char term_buffer[16384]; + if (getenv ("TERM") == NULL) + return; + else if (tgetent (term_buffer, getenv ("TERM")) <= 0) + { + error (0,0, _("could not access definition for terminal `%s'"), + getenv ("TERM")); + return; + } + + if (tgetnum ("li") > 0) + viewlength = tgetnum ("li"); + + if (tgetnum ("co") > 1) + viewwidth = tgetnum ("co") - 1; +} +#else /* !HAVE_LIBNCURSES */ +static void +get_termcap_viewport (void) +{ + /* Nothing to do. */ +} +#endif /* !HAVE_LIBNCURSES */