This will allow pivot_table formatting to supply its own.
Gregorian calendar. Returns SYSMIS for dates before 14 Oct
1582. */
double
-calendar_gregorian_to_offset (int y, int m, int d, char **errorp)
+calendar_gregorian_to_offset (int y, int m, int d,
+ const struct fmt_settings *settings,
+ char **errorp)
{
/* Normalize year. */
if (y >= 0 && y < 100)
{
- int epoch = settings_get_epoch ();
+ int epoch = fmt_settings_get_epoch (settings);
int century = epoch / 100 + (y < epoch % 100);
y += century * 100;
}
#ifndef CALENDAR_H
#define CALENDAR_H 1
-double calendar_gregorian_to_offset (int y, int m, int d, char **errorp);
+struct fmt_settings;
+
+double calendar_gregorian_to_offset (int y, int m, int d,
+ const struct fmt_settings *,
+ char **errorp);
void calendar_offset_to_gregorian (int ofs, int *y, int *m, int *d, int *yd);
int calendar_offset_to_year (int ofs);
int calendar_offset_to_month (int ofs);
csv_output_format (struct csv_writer *w, const struct csv_var *cv,
const union value *value)
{
- char *s = data_out (value, w->encoding, &cv->format);
+ char *s = data_out (value, w->encoding, &cv->format,
+ settings_get_fmt_settings ());
struct substring ss = ss_cstr (s);
if (cv->format.type != FMT_A)
ss_trim (&ss, ss_cstr (" "));
/* Information about parsing one data field. */
struct data_in
{
+ const struct fmt_settings *settings;
+
struct substring input; /* Source. */
enum fmt_type format; /* Input format. */
*/
char *
data_in (struct substring input, const char *input_encoding,
- enum fmt_type format,
+ enum fmt_type format, const struct fmt_settings *settings,
union value *output, int width, const char *output_encoding)
{
static data_in_parser_func *const handlers[FMT_NUMBER_OF_FORMATS] =
assert ((width != 0) == fmt_is_string (format));
+ i.settings = settings;
+
i.format = format;
i.output = output;
bool
data_in_msg (struct substring input, const char *input_encoding,
- enum fmt_type format,
+ enum fmt_type format, const struct fmt_settings *settings,
union value *output, int width, const char *output_encoding)
{
- char *error = data_in (input, input_encoding, format,
+ char *error = data_in (input, input_encoding, format, settings,
output, width, output_encoding);
if (error != NULL)
{
}
static bool
-number_has_implied_decimals (const char *s, enum fmt_type type)
+number_has_implied_decimals (const struct fmt_settings *settings,
+ const char *s, enum fmt_type type)
{
- int decimal = settings_get_style (type)->decimal;
+ int decimal = fmt_settings_get_style (settings, type)->decimal;
bool got_digit = false;
for (;;)
{
static bool
has_implied_decimals (struct substring input, const char *input_encoding,
- enum fmt_type format)
+ enum fmt_type format,
+ const struct fmt_settings *settings)
{
bool retval;
char *s;
ss_data (input), ss_length (input));
retval = (format == FMT_Z
? strchr (s, '.') == NULL
- : number_has_implied_decimals (s, format));
+ : number_has_implied_decimals (settings, s, format));
free (s);
return retval;
If it is appropriate, this function modifies the numeric value in OUTPUT. */
void
data_in_imply_decimals (struct substring input, const char *input_encoding,
- enum fmt_type format, int d, union value *output)
+ enum fmt_type format, int d,
+ const struct fmt_settings *settings,
+ union value *output)
{
if (d > 0 && output->f != SYSMIS
- && has_implied_decimals (input, input_encoding, format))
+ && has_implied_decimals (input, input_encoding, format, settings))
output->f /= pow (10., d);
}
\f
static char *
parse_number (struct data_in *i)
{
- const struct fmt_number_style *style =
- settings_get_style (i->format);
+ const struct fmt_number_style *style = fmt_settings_get_style (
+ i->settings,
+ fmt_get_category (i->format) == FMT_CAT_CUSTOM ? FMT_F : i->format);
struct string tmp;
int save_errno;
char *tail;
- if (fmt_get_category (i->format) == FMT_CAT_CUSTOM)
- {
- style = settings_get_style (FMT_F);
- }
-
/* Trim spaces and check for missing value representation. */
if (trim_spaces_and_check_missing (i))
return NULL;
if (*year >= 0 && *year <= 99)
{
- int epoch = settings_get_epoch ();
+ int epoch = fmt_settings_get_epoch (i->settings);
int epoch_century = ROUND_DOWN (epoch, 100);
int epoch_offset = epoch - epoch_century;
if (*year >= epoch_offset)
cp = buf;
while (c_isdigit (ss_first (i->input)))
*cp++ = ss_get_byte (&i->input);
- if (ss_match_byte (&i->input, settings_get_decimal_char (FMT_F)))
+ if (ss_match_byte (&i->input, i->settings->decimal))
*cp++ = '.';
while (c_isdigit (ss_first (i->input)))
*cp++ = ss_get_byte (&i->input);
char *error;
double ofs;
- ofs = calendar_gregorian_to_offset (year, month, day, &error);
+ ofs = calendar_gregorian_to_offset (
+ year, month, day, settings_get_fmt_settings (), &error);
if (ofs == SYSMIS)
return error;
date = (yday - 1 + ofs) * 60. * 60. * 24.;
struct dictionary;
char *data_in (struct substring input, const char *input_encoding,
- enum fmt_type,
+ enum fmt_type, const struct fmt_settings *,
union value *output, int width, const char *output_encoding);
bool data_in_msg (struct substring input, const char *input_encoding,
- enum fmt_type,
+ enum fmt_type, const struct fmt_settings *,
union value *output, int width, const char *output_encoding);
void data_in_imply_decimals (struct substring input, const char *encoding,
- enum fmt_type format, int d, union value *output);
+ enum fmt_type format, int d,
+ const struct fmt_settings *, union value *output);
#endif /* data/data-in.h */
\f
typedef void data_out_converter_func (const union value *,
const struct fmt_spec *,
- char *);
+ const struct fmt_settings *, char *);
#define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) \
static data_out_converter_func output_##METHOD;
#include "format.def"
static bool output_decimal (const struct rounder *, const struct fmt_spec *,
- bool require_affixes, char *);
+ const struct fmt_settings *, bool require_affixes,
+ char *);
static bool output_scientific (double, const struct fmt_spec *,
+ const struct fmt_settings *,
bool require_affixes, char *);
static double power10 (int) PURE_FUNCTION;
void
data_out_recode (const union value *input, const char *input_encoding,
const struct fmt_spec *format,
+ const struct fmt_settings *settings,
struct string *output, const char *output_encoding)
{
assert (fmt_check_output (format));
free (out);
}
else if (fmt_get_category (format->type) == FMT_CAT_BINARY)
- converters[format->type] (input, format,
+ converters[format->type] (input, format, settings,
ds_put_uninit (output, format->w));
else
{
- char *utf8_encoded = data_out (input, input_encoding, format);
+ char *utf8_encoded = data_out (input, input_encoding, format, settings);
char *output_encoded = recode_string (output_encoding, UTF8,
utf8_encoded, -1);
ds_put_cstr (output, output_encoded);
If POOL is non-null, then the return value is allocated on that pool. */
char *
data_out_pool (const union value *input, const char *input_encoding,
- const struct fmt_spec *format, struct pool *pool)
+ const struct fmt_spec *format,
+ const struct fmt_settings *settings, struct pool *pool)
{
assert (fmt_check_output (format));
if (format->type == FMT_A)
char tmp[16];
assert (format->w + 1 <= sizeof tmp);
- converters[format->type] (input, format, tmp);
+ converters[format->type] (input, format, settings, tmp);
return binary_to_utf8 (tmp, pool);
}
else
{
- const struct fmt_number_style *style = settings_get_style (format->type);
+ const struct fmt_number_style *style = fmt_settings_get_style (
+ settings, format->type);
size_t size = format->w + style->extra_bytes + 1;
char *output;
output = pool_alloc_unaligned (pool, size);
- converters[format->type] (input, format, output);
+ converters[format->type] (input, format, settings, output);
return output;
}
}
necessary to fully display the selected number of decimal places. */
char *
data_out_stretchy (const union value *input, const char *encoding,
- const struct fmt_spec *format, struct pool *pool)
+ const struct fmt_spec *format,
+ const struct fmt_settings *settings, struct pool *pool)
{
if (fmt_get_category (format->type) & (FMT_CAT_BASIC | FMT_CAT_CUSTOM))
{
- const struct fmt_number_style *style = settings_get_style (format->type);
+ const struct fmt_number_style *style
+ = fmt_settings_get_style (settings, format->type);
struct fmt_spec wide_format;
char tmp[128];
size_t size;
size = format->w + style->extra_bytes + 1;
if (size <= sizeof tmp)
{
- output_number (input, &wide_format, tmp);
+ output_number (input, &wide_format, settings, tmp);
return pool_strdup (pool, tmp + strspn (tmp, " "));
}
}
- return data_out_pool (input, encoding, format, pool);
+ return data_out_pool (input, encoding, format, settings, pool);
}
char *
data_out (const union value *input, const char *input_encoding,
- const struct fmt_spec *format)
+ const struct fmt_spec *format, const struct fmt_settings *settings)
{
- return data_out_pool (input, input_encoding, format, NULL);
+ return data_out_pool (input, input_encoding, format, settings, NULL);
}
\f
CCE formats. */
static void
output_number (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings, char *output)
{
double number = input->f;
struct rounder r;
rounder_init (&r, number, format->d);
- if (output_decimal (&r, format, true, output)
- || output_scientific (number, format, true, output)
- || output_decimal (&r, format, false, output))
+ if (output_decimal (&r, format, settings, true, output)
+ || output_scientific (number, format, settings, true, output)
+ || output_decimal (&r, format, settings, false, output))
return;
}
- if (!output_scientific (number, format, false, output))
+ if (!output_scientific (number, format, settings, false, output))
output_overflow (format, output);
}
}
/* Outputs N format. */
static void
output_N (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
double number = input->f * power10 (format->d);
if (input->f == SYSMIS || number < 0)
/* Outputs Z format. */
static void
output_Z (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
double number = input->f * power10 (format->d);
char buf[128];
/* Outputs P format. */
static void
output_P (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
if (output_bcd_integer (fabs (input->f * power10 (format->d)),
format->w * 2 - 1, output)
/* Outputs PK format. */
static void
output_PK (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
output_bcd_integer (input->f * power10 (format->d), format->w * 2, output);
}
/* Outputs IB format. */
static void
output_IB (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
double number = round (input->f * power10 (format->d));
if (input->f == SYSMIS
/* Outputs PIB format. */
static void
output_PIB (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
double number = round (input->f * power10 (format->d));
if (input->f == SYSMIS
/* Outputs PIBHEX format. */
static void
output_PIBHEX (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
double number = round (input->f);
if (input->f == SYSMIS)
/* Outputs RB format. */
static void
output_RB (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
double d = input->f;
memcpy (output, &d, format->w);
/* Outputs RBHEX format. */
static void
output_RBHEX (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
double d = input->f;
DATETIME, TIME, and DTIME formats. */
static void
output_date (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings, char *output)
{
double number = input->f;
int year, month, day, yday;
}
else
{
- int epoch = settings_get_epoch ();
+ int epoch = fmt_settings_get_epoch (settings);
int offset = year - epoch;
if (offset < 0 || offset > 99)
goto overflow;
int d = MIN (format->d, excess_width - 4);
int w = d + 3;
c_snprintf (p, 64, ":%0*.*f", w, d, number);
- if (settings_get_decimal_char (FMT_F) != '.')
+ if (settings->decimal != '.')
{
char *cp = strchr (p, '.');
if (cp != NULL)
- *cp = settings_get_decimal_char (FMT_F);
+ *cp = settings->decimal;
}
p += strlen (p);
}
/* Outputs WKDAY format. */
static void
output_WKDAY (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
static const char *const weekdays[7] =
{
/* Outputs MONTH format. */
static void
output_MONTH (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
static const char *const months[12] =
{
/* Outputs A format. */
static void
output_A (const union value *input UNUSED,
- const struct fmt_spec *format UNUSED, char *output UNUSED)
+ const struct fmt_spec *format UNUSED,
+ const struct fmt_settings *settings UNUSED, char *output UNUSED)
{
NOT_REACHED ();
}
/* Outputs AHEX format. */
static void
output_AHEX (const union value *input, const struct fmt_spec *format,
- char *output)
+ const struct fmt_settings *settings UNUSED, char *output)
{
output_hex (input->s, format->w / 2, output);
}
omitted to make the number fit. */
static bool
output_decimal (const struct rounder *r, const struct fmt_spec *format,
- bool require_affixes, char *output)
+ const struct fmt_settings *settings, bool require_affixes,
+ char *output)
{
const struct fmt_number_style *style =
- settings_get_style (format->type);
+ fmt_settings_get_style (settings, format->type);
int decimals;
the style of the format specified in FORMAT. */
static bool
output_scientific (double number, const struct fmt_spec *format,
+ const struct fmt_settings *settings,
bool require_affixes, char *output)
{
const struct fmt_number_style *style =
- settings_get_style (format->type);
+ fmt_settings_get_style (settings, format->type);
int width;
int fraction_width;
bool add_affixes;
#include "libpspp/float-format.h"
#include "libpspp/integer-format.h"
+struct fmt_settings;
struct fmt_spec;
struct string;
union value;
char *data_out (const union value *input, const char *input_encoding,
- const struct fmt_spec *);
+ const struct fmt_spec *, const struct fmt_settings *);
char *data_out_pool (const union value *input, const char *input_encoding,
- const struct fmt_spec *, struct pool *pool);
+ const struct fmt_spec *, const struct fmt_settings *,
+ struct pool *pool);
char *data_out_stretchy (const union value *input, const char *input_encoding,
- const struct fmt_spec *, struct pool *);
+ const struct fmt_spec *, const struct fmt_settings *,
+ struct pool *);
void data_out_recode (const union value *input, const char *input_encoding,
- const struct fmt_spec *,
+ const struct fmt_spec *, const struct fmt_settings *,
struct string *output, const char *output_encoding);
#endif /* data-out.h */
can't tell whether the ',' or '.' is a grouping or
decimal character. Assume that the decimal character
from the settings is in use. */
- if (prev_delim == settings_get_decimal_char (FMT_F))
+ if (prev_delim == settings_get_fmt_settings ()->decimal)
{
decimal = prev_delim;
precision = delim_digits;
static void
guess_numeric (struct fmt_guesser *g, struct fmt_spec *f)
{
- int decimal_char = settings_get_decimal_char (FMT_COMMA);
+ int decimal_char = settings_get_fmt_settings ()->decimal;
f->d = g->decimals / g->count;
if (g->pct)
size_t digit_cnt = ss_get_long (s, &value);
enum date_token token = 0;
- if (ss_match_byte (s, settings_get_decimal_char (FMT_F))
+ if (ss_match_byte (s, settings_get_fmt_settings ()->decimal)
&& tokens_seen & DT_COLON
&& value <= 59)
{
/* Returns the output format specifier corresponding to input
format specifier INPUT. */
struct fmt_spec
-fmt_for_output_from_input (const struct fmt_spec *input)
+fmt_for_output_from_input (const struct fmt_spec *input,
+ const struct fmt_settings *settings)
{
struct fmt_spec output;
case FMT_PCT:
{
const struct fmt_number_style *style =
- settings_get_style (input->type);
+ fmt_settings_get_style (settings, input->type);
output.w += fmt_affix_width (style);
if (style->grouping != 0 && input->w - input->d >= 3)
#include "data/val-type.h"
#include "libpspp/str.h"
+struct fmt_settings;
+
/* How a format is going to be used. */
enum fmt_use
{
/* Constructing formats. */
struct fmt_spec fmt_for_input (enum fmt_type, int w, int d) PURE_FUNCTION;
struct fmt_spec fmt_for_output (enum fmt_type, int w, int d) PURE_FUNCTION;
-struct fmt_spec fmt_for_output_from_input (const struct fmt_spec *);
+struct fmt_spec fmt_for_output_from_input (const struct fmt_spec *,
+ const struct fmt_settings *);
struct fmt_spec fmt_default_for_width (int width);
/* Verifying formats. */
const struct fmt_spec *fmt = var_get_write_format (var);
- char *m = data_in (ss_cstr (text), "UTF-8",
- fmt->type,
- v,
- var_get_width (var),
+ char *m = data_in (ss_cstr (text), "UTF-8", fmt->type,
+ settings_get_fmt_settings (), v, var_get_width (var),
"UTF-8");
if (m)
const char *text = xmv->value ?
CHAR_CAST (const char *, xmv->value) : CHAR_CAST (const char *, xmv->text);
- char *m = data_in (ss_cstr (text), "UTF-8",
- fmt->type,
- v,
- var_get_width (var),
- "UTF-8");
+ char *m = data_in (ss_cstr (text), "UTF-8", fmt->type,
+ settings_get_fmt_settings (), v,
+ var_get_width (var), "UTF-8");
if (m)
{
}
}
- r->postgres_epoch = calendar_gregorian_to_offset (2000, 1, 1, NULL);
+ r->postgres_epoch = calendar_gregorian_to_offset (
+ 2000, 1, 1, settings_get_fmt_settings (), NULL);
{
const int enc = PQclientEncoding (r->conn);
the_settings.include = include;
}
-/* What year to use as the start of the epoch. */
-int
-settings_get_epoch (void)
-{
- return fmt_settings_get_epoch (&the_settings.styles);
-}
-
/* Sets the year that starts the epoch. */
void
settings_set_epoch (int epoch)
return true;
}
-/* Returns the decimal point character for TYPE. */
-int
-settings_get_decimal_char (enum fmt_type type)
-{
- return fmt_settings_get_style (&the_settings.styles, type)->decimal;
-}
-
void
settings_set_decimal_char (char decimal)
{
the_settings.styles.decimal = decimal;
}
-/* Returns the number formatting style associated with the given
- format TYPE. */
-const struct fmt_number_style *
-settings_get_style (enum fmt_type type)
+const struct fmt_settings *
+settings_get_fmt_settings (void)
{
- assert (is_fmt_type (type));
- return fmt_settings_get_style (&the_settings.styles, type);
+ return &the_settings.styles;
}
/* Returns a string of the form "$#,###.##" according to FMT,
bool settings_get_include (void);
void settings_set_include (bool);
-int settings_get_epoch (void);
void settings_set_epoch (int);
bool settings_get_scompression (void);
enum fmt_type;
bool settings_set_cc (const char *cc_string, enum fmt_type type);
-int settings_get_decimal_char (enum fmt_type type);
void settings_set_decimal_char (char decimal);
-
-const struct fmt_number_style * settings_get_style (enum fmt_type type);
+const struct fmt_settings *settings_get_fmt_settings (void);
char * settings_dollar_template (const struct fmt_spec *fmt);
append_value (const struct variable *v, const union value *value,
struct string *str)
{
- char *s = data_out (value, var_get_encoding (v), &v->print);
+ char *s = data_out (value, var_get_encoding (v), &v->print,
+ settings_get_fmt_settings ());
struct substring ss = ss_cstr (s);
ss_rtrim (&ss, ss_cstr (" "));
ds_put_substring (str, ss);
data_parser_set_quotes (parser, ss_cstr ("'\""));
data_parser_set_soft_delimiters (parser,
ss_cstr (CC_SPACES));
- const char decimal = settings_get_decimal_char (FMT_F);
+ const char decimal = settings_get_fmt_settings ()->decimal;
data_parser_set_hard_delimiters (parser,
ss_buffer (",", (decimal == '.') ? 1 : 0));
}
if (v != NULL)
{
/* Success. */
- struct fmt_spec output = fmt_for_output_from_input (f);
+ struct fmt_spec output = fmt_for_output_from_input (
+ f, settings_get_fmt_settings ());
var_set_both_formats (v, &output);
}
else
if (input.type == FMT_N)
input.type = FMT_F;
- output = fmt_for_output_from_input (&input);
+ output = fmt_for_output_from_input (&input,
+ settings_get_fmt_settings ());
}
else
{
f->format.w);
union value *value = case_data_rw_idx (c, f->case_idx);
char *error = data_in (s, input_encoding, f->format.type,
+ settings_get_fmt_settings (),
value, fmt_var_width (&f->format),
output_encoding);
if (error == NULL)
data_in_imply_decimals (s, input_encoding, f->format.type,
- f->format.d, value);
+ f->format.d, settings_get_fmt_settings (),
+ value);
else
parse_error (reader, f, f->first_column,
f->first_column + f->format.w, error);
const char *input_encoding = dfm_reader_get_encoding (reader);
error = data_in (s, input_encoding, f->format.type,
+ settings_get_fmt_settings (),
case_data_rw_idx (c, f->case_idx),
fmt_var_width (&f->format), output_encoding);
if (error != NULL)
const char *input_encoding = dfm_reader_get_encoding (reader);
error = data_in (s, input_encoding, f->format.type,
+ settings_get_fmt_settings (),
case_data_rw_idx (c, f->case_idx),
fmt_var_width (&f->format), output_encoding);
if (error != NULL)
{
goto error;
}
- output = fmt_for_output_from_input (&input);
+ output = fmt_for_output_from_input (&input,
+ settings_get_fmt_settings ());
}
else
{
goto error;
}
else
- output = fmt_for_output_from_input (&input);
+ output = fmt_for_output_from_input (&input,
+ settings_get_fmt_settings ());
}
v = dict_create_var (dict, name, fmt_var_width (&input));
if (v == NULL)
struct fmt_spec fmt = {FMT_A, 0, 0};
fmt.w = w;
- char *vname = data_out (uvv, enc, &fmt);
+ char *vname = data_out (uvv, enc, &fmt, settings_get_fmt_settings ());
struct substring the_name = ss_cstr (vname);
int mrow = -1;
char *s;
s = data_out (input, var_get_encoding (spec->var),
- &spec->format);
+ &spec->format, settings_get_fmt_settings ());
len = strlen (s);
width = u8_width (CHAR_CAST (const uint8_t *, s), len, UTF8);
x1 = x0 + width;
const union value *input = case_data (*c, spec->var);
if (!spec->sysmis_as_spaces || input->f != SYSMIS)
data_out_recode (input, var_get_encoding (spec->var),
- &spec->format, &line, trns->encoding);
+ &spec->format, settings_get_fmt_settings (),
+ &line, trns->encoding);
else
ds_put_byte_multiple (&line, encoded_space, spec->format.w);
if (spec->add_space)
include_var_names = false;
use_value_labels = false;
use_print_formats = false;
- decimal = settings_get_decimal_char (FMT_F);
+ decimal = settings_get_fmt_settings ()->decimal;
delimiter = 0;
qualifier = '"';
if (!c->warned && utf8_strcasecmp (c->label, label))
{
char *s = data_out (value, var_get_encoding (var),
- var_get_print_format (var));
+ var_get_print_format (var),
+ settings_get_fmt_settings ());
c->warned = true;
msg (SW, _("Variables specified on MCGROUP should "
"have the same categories, but %s and %s "
return SYSMIS;
}
- ofs = calendar_gregorian_to_offset (y, m, d, &error);
+ ofs = calendar_gregorian_to_offset (y, m, d, settings_get_fmt_settings (),
+ &error);
if (error != NULL)
{
msg (SE, "%s", error);
if (method == SUM_CLOSEST && d > calendar_days_in_month (y, m))
d = calendar_days_in_month (y, m);
- output = calendar_gregorian_to_offset (y, m, d, &error);
+ output = calendar_gregorian_to_offset (y, m, d, settings_get_fmt_settings (),
+ &error);
if (output != SYSMIS)
output = (output * DAY_S) + fmod (date, DAY_S);
else
if (s.length > f->w)
s.length = f->w;
- error = data_in (s, C_ENCODING, f->type, &out, 0, NULL);
+ error = data_in (s, C_ENCODING, f->type, settings_get_fmt_settings (),
+ &out, 0, NULL);
if (error == NULL)
- data_in_imply_decimals (s, C_ENCODING, f->type, f->d, &out);
+ data_in_imply_decimals (s, C_ENCODING, f->type, f->d,
+ settings_get_fmt_settings (), &out);
else
{
msg (SE, "Cannot parse `%.*s' as format %s: %s",
v.f = x;
assert (!fmt_is_string (f->type));
- s = data_out (&v, C_ENCODING, f);
+ s = data_out (&v, C_ENCODING, f, settings_get_fmt_settings ());
dst = alloc_string (e, strlen (s));
strcpy (dst.string, s);
free (s);
assert (fmt_get_category (*format) != FMT_CAT_STRING);
- if (!data_in_msg (lex_tokss (lexer), "UTF-8", *format, &v, 0, NULL))
+ if (!data_in_msg (lex_tokss (lexer), "UTF-8", *format,
+ settings_get_fmt_settings (), &v, 0, NULL))
return false;
lex_get (lexer);
ds_put_format (&title, ", %s=", var_to_string (var));
/* Insert the formatted value of VAR without any leading spaces. */
- s = data_out (value, var_get_encoding (var), var_get_print_format (var));
+ s = data_out (value, var_get_encoding (var), var_get_print_format (var),
+ settings_get_fmt_settings ());
ds_put_cstr (&title, s + strspn (s, " "));
free (s);
}
{
name = data_out_pool (value, dict_get_encoding (old_dict),
var_get_write_format (flip->new_names_var),
- flip->pool);
+ settings_get_fmt_settings (), flip->pool);
}
var_names_add (flip->pool, &flip->new_names, name);
}
c = case_create (casereader_get_proto (reader));
data_in (ss_cstr (flip->old_names.names[flip->cases_read]), flip->encoding,
- FMT_A, case_data_rw_idx (c, 0), 8, flip->encoding);
+ FMT_A, settings_get_fmt_settings (), case_data_rw_idx (c, 0),
+ 8, flip->encoding);
for (i = 0; i < flip->n_cases; i++)
{
static char *
show_cc (enum fmt_type type)
{
- const struct fmt_number_style *cc = settings_get_style (type);
+ const struct fmt_number_style *cc = fmt_settings_get_style (
+ settings_get_fmt_settings (), type);
struct string out;
ds_init_empty (&out);
static char *
show_decimals (const struct dataset *ds UNUSED)
{
- return xasprintf ("`%c'", settings_get_decimal_char (FMT_F));
+ return xasprintf ("`%c'", settings_get_fmt_settings ()->decimal);
}
static char *
char *error;
error = data_in (ss_buffer (CHAR_CAST_BUG (char *, value), width),
- C_ENCODING, FMT_F, &uv, 0, encoding);
+ C_ENCODING, FMT_F, settings_get_fmt_settings (),
+ &uv, 0, encoding);
match = error == NULL;
free (error);
if (bw->id_var)
{
char *s = data_out (case_data_idx (cx, bw->id_idx),
- var_get_encoding (bw->id_var),
- var_get_print_format (bw->id_var));
+ var_get_encoding (bw->id_var),
+ var_get_print_format (bw->id_var),
+ settings_get_fmt_settings ());
ds_put_cstr (&o->label, s);
free (s);
pivot_table_assign_label_depth (CONST_CAST (struct pivot_table *, table));
- int old_decimal = settings_get_decimal_char (FMT_COMMA);
+ int old_decimal = settings_get_fmt_settings ()->decimal;
if (table->decimal == '.' || table->decimal == ',')
settings_set_decimal_char (table->decimal);
if (show & SETTINGS_VALUE_SHOW_VALUE)
{
char *s = data_out (&(union value) { .f = value->numeric.x },
- "UTF-8", &value->numeric.format);
+ "UTF-8", &value->numeric.format,
+ settings_get_fmt_settings ());
ds_put_cstr (out, s + strspn (s, " "));
free (s);
}
else
{
union value v = { .f = mapping->to.d };
- mapping->to.s = data_out_stretchy (&v, NULL, format, NULL);
+ mapping->to.s = data_out_stretchy (&v, NULL, format,
+ settings_get_fmt_settings (),
+ NULL);
mapping->to.width = strlen (mapping->to.s);
}
}
if (label_series->values[i].width < 0)
{
union value v = { .f = label_series->values[i].d };
- dest = data_out_stretchy (&v, "UTF-8", &s->format, NULL);
+ dest = data_out_stretchy (&v, "UTF-8", &s->format,
+ settings_get_fmt_settings (), NULL);
}
else
dest = label_series->values[i].s;
&& len == 23
&& data->s[len] == '\0')
{
- double date = calendar_gregorian_to_offset (year, month, day,
- NULL);
+ double date = calendar_gregorian_to_offset (
+ year, month, day, settings_get_fmt_settings (), NULL);
if (date != SYSMIS)
{
v->type = PIVOT_VALUE_NUMERIC;
{
gchar *s;
- s = data_out_stretchy (&v, encoding, format, NULL);
+ s = data_out_stretchy (&v, encoding, format, settings_get_fmt_settings (),
+ NULL);
if (fmt_is_numeric (format->type))
g_strchug (s);
else
}
value_init (val, width);
- char *err = data_in (ss_cstr (text), UTF8, format->type, val, width, encoding);
+ char *err = data_in (ss_cstr (text), UTF8, format->type,
+ settings_get_fmt_settings (), val, width, encoding);
if (err)
{
value_init(vp, var_width);
error_txt = data_in (ss_cstr(text), "UTF-8", dialog->format.type,
- vp, var_width, dialog->encoding);
+ settings_get_fmt_settings (), vp, var_width,
+ dialog->encoding);
if (error_txt)
{
err_dialog (error_txt, GTK_WINDOW (dialog));
if (vp == NULL)
{
xx = data_in (ss_cstr (in), psppire_dict_encoding (store->dict),
- fmt->type, &val, width, "UTF-8");
+ fmt->type, settings_get_fmt_settings (),
+ &val, width, "UTF-8");
}
GVariant *vrnt = value_variant_new (&val, width);
int new_width = var_get_width (aux->new_variable);
const char *enc = dict_get_encoding (aux->dict);
const struct fmt_spec *newfmt = var_get_print_format (aux->new_variable);
- char *s = data_out (old, enc, var_get_print_format (aux->old_variable));
+ char *s = data_out (old, enc, var_get_print_format (aux->old_variable),
+ settings_get_fmt_settings ());
enum fmt_type type = (fmt_usable_for_input (newfmt->type)
? newfmt->type
: FMT_DOLLAR);
- free (data_in (ss_cstr (s), enc, type, new, new_width, enc));
+ free (data_in (ss_cstr (s), enc, type, settings_get_fmt_settings (),
+ new, new_width, enc));
free (s);
}
FALSE);
value_init (&value, width);
ok = (datasheet_get_value (ds->datasheet, casenum, idx, &value)
- && data_in_msg (input, UTF8, fmt->type, &value, width,
- dict_get_encoding (dict->dict))
+ && data_in_msg (input, UTF8, fmt->type, settings_get_fmt_settings (),
+ &value, width, dict_get_encoding (dict->dict))
&& datasheet_put_value (ds->datasheet, casenum, idx, &value));
value_destroy (&value, width);
char *xx = data_in (ss_cstr (ss),
"UTF-8",
var_get_write_format (var)->type,
+ settings_get_fmt_settings (),
v, var_get_width (var), "UTF-8");
free (xx);
new_text = gtk_entry_get_text (entry);
return data_in_msg (ss_cstr (new_text), UTF8,
- obj->format.type,
+ obj->format.type, settings_get_fmt_settings (),
value, width, obj->encoding);
}
}
union value v;
v.f = 1234.56;
- sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l));
+ sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l,
+ settings_get_fmt_settings ()));
gtk_label_set_text (GTK_LABEL (dialog->label_psample), sample_text);
g_free (sample_text);
v.f = -v.f;
- sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l));
+ sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l,
+ settings_get_fmt_settings ()));
gtk_label_set_text (GTK_LABEL (dialog->label_nsample), sample_text);
g_free (sample_text);
}
#include "libpspp/cast.h"
#include "libpspp/i18n.h"
#include "libpspp/message.h"
+#include "data/settings.h"
#include "libpspp/str.h"
#include "libpspp/misc.h"
bool ok;
v_in.f = number;
- s = data_out (&v_in, "FIXME", format);
+ s = data_out (&v_in, "FIXME", format, settings_get_fmt_settings ());
/* FIXME: UTF8 encoded strings will fail here */
- error = data_in (ss_cstr (s), C_ENCODING, format->type, &v_out, 0, NULL);
+ error = data_in (ss_cstr (s), C_ENCODING, format->type,
+ settings_get_fmt_settings (), &v_out, 0, NULL);
ok = error == NULL;
free (error);