struct variable *var
CODE:
SV *ret;
- const struct fmt_spec *fmt = var_get_print_format (var);
+ const struct fmt_spec fmt = var_get_print_format (var);
union value uv;
char *s;
make_value_from_scalar (&uv, val, var);
s = data_out (&uv, var_get_encoding (var), fmt, settings_get_fmt_settings ());
value_destroy (&uv, var_get_width (var));
- ret = newSVpv (s, fmt->w);
+ ret = newSVpv (s, fmt.w);
free (s);
RETVAL = ret;
OUTPUT:
struct input_format *input_format;
struct variable *v;
- op_fmt = fmt_for_output_from_input (&ip_fmt, settings_get_fmt_settings ());
+ op_fmt = fmt_for_output_from_input (ip_fmt, settings_get_fmt_settings ());
v = dict_create_var (dict->dict, name,
fmt_is_string (op_fmt.type) ? op_fmt.w : 0);
if ( NULL == v )
sv_setpv (errstr, "The variable could not be created (probably already exists).");
XSRETURN_UNDEF;
}
- var_set_both_formats (v, &op_fmt);
+ var_set_both_formats (v, op_fmt);
input_format = xmalloc (sizeof *input_format);
input_format->var = v;
struct variable *var
CODE:
HV *fmthash = (HV *) sv_2mortal ((SV *) newHV());
- const struct fmt_spec *fmt = var_get_write_format (var);
+ const struct fmt_spec fmt = var_get_write_format (var);
- hv_store (fmthash, "fmt", 3, newSVnv (fmt->type), 0);
- hv_store (fmthash, "decimals", 8, newSVnv (fmt->d), 0);
- hv_store (fmthash, "width", 5, newSVnv (fmt->w), 0);
+ hv_store (fmthash, "fmt", 3, newSVnv (fmt.type), 0);
+ hv_store (fmthash, "decimals", 8, newSVnv (fmt.d), 0);
+ hv_store (fmthash, "width", 5, newSVnv (fmt.w), 0);
RETVAL = newRV ((SV *) fmthash);
OUTPUT:
struct variable *var
CODE:
HV *fmthash = (HV *) sv_2mortal ((SV *) newHV());
- const struct fmt_spec *fmt = var_get_print_format (var);
+ const struct fmt_spec fmt = var_get_print_format (var);
- hv_store (fmthash, "fmt", 3, newSVnv (fmt->type), 0);
- hv_store (fmthash, "decimals", 8, newSVnv (fmt->d), 0);
- hv_store (fmthash, "width", 5, newSVnv (fmt->w), 0);
+ hv_store (fmthash, "fmt", 3, newSVnv (fmt.type), 0);
+ hv_store (fmthash, "decimals", 8, newSVnv (fmt.d), 0);
+ hv_store (fmthash, "width", 5, newSVnv (fmt.w), 0);
RETVAL = newRV ((SV *) fmthash);
OUTPUT:
struct variable *var
output_format fmt
CODE:
- var_set_write_format (var, &fmt);
+ var_set_write_format (var, fmt);
void
struct variable *var
output_format fmt
CODE:
- var_set_print_format (var, &fmt);
+ var_set_print_format (var, fmt);
void
pxs_set_output_format (var, fmt)
struct variable *var
output_format fmt
CODE:
- var_set_both_formats (var, &fmt);
+ var_set_both_formats (var, fmt);
int
$var.d = decimals ? SvIV (*decimals) :
fmt_takes_decimals ($var.type) ?
MIN (2, fmt_max_output_decimals ($var.type, $var.w)) : 0;
- if ( ! fmt_check_output (&$var))
+ if ( ! fmt_check_output ($var))
{
char buf[FMT_STRING_LEN_MAX + 1];
- fmt_to_string (&$var, buf);
+ fmt_to_string ($var, buf);
croak (\"%s is an invalid output format\", buf);
}
$var.d = decimals ? SvIV (*decimals) :
fmt_takes_decimals ($var.type) ?
MIN (2, fmt_max_input_decimals ($var.type, $var.w)) : 0;
- if ( ! fmt_check_input (&$var))
+ if ( ! fmt_check_input ($var))
{
char buf[FMT_STRING_LEN_MAX + 1];
- fmt_to_string (&$var, buf);
+ fmt_to_string ($var, buf);
croak (\"%s is an invalid input format\", buf);
}
cv->width = var_get_width (var);
cv->case_index = var_get_case_index (var);
- cv->format = *var_get_print_format (var);
+ cv->format = var_get_print_format (var);
if (opts->recode_user_missing)
mv_copy (&cv->missing, var_get_missing_values (var));
else
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)
static void rounder_format (const struct rounder *, int decimals,
char *output);
\f
-typedef void data_out_converter_func (const union value *,
- const struct fmt_spec *,
+typedef void data_out_converter_func (const union value *, struct fmt_spec,
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 *,
+static bool output_decimal (const struct rounder *, struct fmt_spec,
const struct fmt_number_style *,
bool require_affixes, char *);
-static bool output_scientific (double, const struct fmt_spec *,
+static bool output_scientific (double, struct fmt_spec,
const struct fmt_number_style *,
bool require_affixes, char *);
static double power10 (int) PURE_FUNCTION;
static double power256 (int) PURE_FUNCTION;
-static void output_infinite (double, const struct fmt_spec *, char *);
-static void output_missing (const struct fmt_spec *, char *);
-static void output_overflow (const struct fmt_spec *, char *);
+static void output_infinite (double, struct fmt_spec, char *);
+static void output_missing (struct fmt_spec, char *);
+static void output_overflow (struct fmt_spec, char *);
static bool output_bcd_integer (double, int digits, char *);
static void output_binary_integer (uint64_t, int bytes, enum integer_format,
char *);
when FORMAT's type is FMT_A. */
void
data_out_recode (const union value *input, const char *input_encoding,
- const struct fmt_spec *format,
- const struct fmt_settings *settings,
+ struct fmt_spec format, const struct fmt_settings *settings,
struct string *output, const char *output_encoding)
{
assert (fmt_check_output (format));
- if (format->type == FMT_A)
+ if (format.type == FMT_A)
{
char *in = CHAR_CAST (char *, input->s);
char *out = recode_string (output_encoding, input_encoding,
- in, format->w);
+ in, format.w);
ds_put_cstr (output, out);
free (out);
}
- else if (fmt_get_category (format->type) == FMT_CAT_BINARY)
- converters[format->type] (input, format, settings,
- ds_put_uninit (output, format->w));
+ else if (fmt_get_category (format.type) == FMT_CAT_BINARY)
+ converters[format.type] (input, format, settings,
+ ds_put_uninit (output, format.w));
else
{
char *utf8_encoded = data_out (input, input_encoding, format, settings);
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 fmt_spec format,
const struct fmt_settings *settings, struct pool *pool)
{
assert (fmt_check_output (format));
- if (format->type == FMT_A)
+ if (format.type == FMT_A)
{
char *in = CHAR_CAST (char *, input->s);
- return recode_string_pool (UTF8, input_encoding, in, format->w, pool);
+ return recode_string_pool (UTF8, input_encoding, in, format.w, pool);
}
- else if (fmt_get_category (format->type) == FMT_CAT_BINARY)
+ else if (fmt_get_category (format.type) == FMT_CAT_BINARY)
{
char tmp[16];
- assert (format->w + 1 <= sizeof tmp);
- converters[format->type] (input, format, settings, tmp);
+ assert (format.w + 1 <= sizeof tmp);
+ converters[format.type] (input, format, settings, tmp);
return binary_to_utf8 (tmp, pool);
}
else
{
const struct fmt_number_style *style = fmt_settings_get_style (
- settings, format->type);
- size_t size = format->w + style->extra_bytes + 1;
+ 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, settings, 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 fmt_spec format,
const struct fmt_settings *settings, struct pool *pool)
{
- if (fmt_get_category (format->type) & (FMT_CAT_BASIC | FMT_CAT_CUSTOM))
+ if (fmt_get_category (format.type) & (FMT_CAT_BASIC | FMT_CAT_CUSTOM))
{
const struct fmt_number_style *style
- = fmt_settings_get_style (settings, format->type);
- struct fmt_spec wide_format;
+ = fmt_settings_get_style (settings, format.type);
char tmp[128];
- size_t size;
-
- wide_format.type = format->type;
- wide_format.w = 40;
- wide_format.d = format->d;
-
- size = format->w + style->extra_bytes + 1;
- if (size <= sizeof tmp)
+ if (format.w + style->extra_bytes + 1 <= sizeof tmp)
{
- output_number (input, &wide_format, settings, tmp);
+ struct fmt_spec wide_format = {
+ .type = format.type,
+ .w = 40,
+ .d = format.d,
+ };
+ output_number (input, wide_format, settings, tmp);
return pool_strdup (pool, tmp + strspn (tmp, " "));
}
}
char *
data_out (const union value *input, const char *input_encoding,
- const struct fmt_spec *format, const struct fmt_settings *settings)
+ struct fmt_spec format, const struct fmt_settings *settings)
{
return data_out_pool (input, input_encoding, format, settings, NULL);
}
/* Outputs F, COMMA, DOT, DOLLAR, PCT, E, CCA, CCB, CCC, CCD, and
CCE formats. */
static void
-output_number (const union value *input, const struct fmt_spec *format,
+output_number (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings, char *output)
{
double number = input->f;
else
{
const struct fmt_number_style *style =
- fmt_settings_get_style (settings, format->type);
+ fmt_settings_get_style (settings, format.type);
- if (format->type != FMT_E && fabs (number) < 1.5 * power10 (format->w))
+ if (format.type != FMT_E && fabs (number) < 1.5 * power10 (format.w))
{
struct rounder r;
- rounder_init (&r, style, number, format->d);
+ rounder_init (&r, style, number, format.d);
if (output_decimal (&r, format, style, true, output)
|| output_scientific (number, format, style, true, output)
/* Outputs N format. */
static void
-output_N (const union value *input, const struct fmt_spec *format,
+output_N (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
- double number = input->f * power10 (format->d);
+ double number = input->f * power10 (format.d);
if (input->f == SYSMIS || number < 0)
output_missing (format, output);
else
{
char buf[128];
number = fabs (round (number));
- if (number < power10 (format->w)
- && c_snprintf (buf, 128, "%0*.0f", format->w, number) == format->w)
- memcpy (output, buf, format->w);
+ if (number < power10 (format.w)
+ && c_snprintf (buf, 128, "%0*.0f", format.w, number) == format.w)
+ memcpy (output, buf, format.w);
else
output_overflow (format, output);
}
- output[format->w] = '\0';
+ output[format.w] = '\0';
}
/* Outputs Z format. */
static void
-output_Z (const union value *input, const struct fmt_spec *format,
+output_Z (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
- double number = input->f * power10 (format->d);
+ double number = input->f * power10 (format.d);
char buf[128];
if (input->f == SYSMIS)
output_missing (format, output);
- else if (fabs (number) < power10 (format->w)
- && c_snprintf (buf, 128, "%0*.0f", format->w,
- fabs (round (number))) == format->w)
+ else if (fabs (number) < power10 (format.w)
+ && c_snprintf (buf, 128, "%0*.0f", format.w,
+ fabs (round (number))) == format.w)
{
- if (number < 0 && strspn (buf, "0") < format->w)
+ if (number < 0 && strspn (buf, "0") < format.w)
{
- char *p = &buf[format->w - 1];
+ char *p = &buf[format.w - 1];
*p = "}JKLMNOPQR"[*p - '0'];
}
- memcpy (output, buf, format->w);
- output[format->w] = '\0';
+ memcpy (output, buf, format.w);
+ output[format.w] = '\0';
}
else
output_overflow (format, output);
/* Outputs P format. */
static void
-output_P (const union value *input, const struct fmt_spec *format,
+output_P (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
- if (output_bcd_integer (fabs (input->f * power10 (format->d)),
- format->w * 2 - 1, output)
+ if (output_bcd_integer (fabs (input->f * power10 (format.d)),
+ format.w * 2 - 1, output)
&& input->f < 0.0)
- output[format->w - 1] |= 0xd;
+ output[format.w - 1] |= 0xd;
else
- output[format->w - 1] |= 0xf;
+ output[format.w - 1] |= 0xf;
}
/* Outputs PK format. */
static void
-output_PK (const union value *input, const struct fmt_spec *format,
+output_PK (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
- output_bcd_integer (input->f * power10 (format->d), format->w * 2, 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,
+output_IB (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
- double number = round (input->f * power10 (format->d));
+ double number = round (input->f * power10 (format.d));
if (input->f == SYSMIS
- || number >= power256 (format->w) / 2 - 1
- || number < -power256 (format->w) / 2)
- memset (output, 0, format->w);
+ || number >= power256 (format.w) / 2 - 1
+ || number < -power256 (format.w) / 2)
+ memset (output, 0, format.w);
else
{
uint64_t integer = fabs (number);
if (number < 0)
integer = -integer;
- output_binary_integer (integer, format->w,
+ output_binary_integer (integer, format.w,
settings_get_output_integer_format (),
output);
}
- output[format->w] = '\0';
+ output[format.w] = '\0';
}
/* Outputs PIB format. */
static void
-output_PIB (const union value *input, const struct fmt_spec *format,
+output_PIB (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
- double number = round (input->f * power10 (format->d));
+ double number = round (input->f * power10 (format.d));
if (input->f == SYSMIS
- || number < 0 || number >= power256 (format->w))
- memset (output, 0, format->w);
+ || number < 0 || number >= power256 (format.w))
+ memset (output, 0, format.w);
else
- output_binary_integer (number, format->w,
+ output_binary_integer (number, format.w,
settings_get_output_integer_format (), output);
- output[format->w] = '\0';
+ output[format.w] = '\0';
}
/* Outputs PIBHEX format. */
static void
-output_PIBHEX (const union value *input, const struct fmt_spec *format,
+output_PIBHEX (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
double number = round (input->f);
if (input->f == SYSMIS)
output_missing (format, output);
- else if (input->f < 0 || number >= power256 (format->w / 2))
+ else if (input->f < 0 || number >= power256 (format.w / 2))
output_overflow (format, output);
else
{
char tmp[8];
- output_binary_integer (number, format->w / 2, INTEGER_MSB_FIRST, tmp);
- output_hex (tmp, format->w / 2, output);
+ output_binary_integer (number, format.w / 2, INTEGER_MSB_FIRST, tmp);
+ output_hex (tmp, format.w / 2, output);
}
}
/* Outputs RB format. */
static void
-output_RB (const union value *input, const struct fmt_spec *format,
+output_RB (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
double d = input->f;
- memcpy (output, &d, format->w);
+ memcpy (output, &d, format.w);
- output[format->w] = '\0';
+ output[format.w] = '\0';
}
/* Outputs RBHEX format. */
static void
-output_RBHEX (const union value *input, const struct fmt_spec *format,
+output_RBHEX (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
double d = input->f;
- output_hex (&d, format->w / 2, output);
+ output_hex (&d, format.w / 2, output);
}
/* Outputs DATE, ADATE, EDATE, JDATE, SDATE, QYR, MOYR, WKYR,
DATETIME, TIME, and DTIME formats. */
static void
-output_date (const union value *input, const struct fmt_spec *format,
+output_date (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings, char *output)
{
double number = input->f;
int year, month, day, yday;
- const char *template = fmt_date_template (format->type, format->w);
+ const char *template = fmt_date_template (format.type, format.w);
char tmp[64];
char *p = tmp;
if (number == SYSMIS)
goto missing;
- if (fmt_get_category (format->type) == FMT_CAT_DATE)
+ if (fmt_get_category (format.type) == FMT_CAT_DATE)
{
if (number <= 0)
goto missing;
{
if (year <= 9999)
p += sprintf (p, "%04d", year);
- else if (format->type == FMT_DATETIME
- || format->type == FMT_YMDHMS)
+ else if (format.type == FMT_DATETIME || format.type == FMT_YMDHMS)
p = stpcpy (p, "****");
else
goto overflow;
number = fabs (number);
p += sprintf (p, "%02d", (int) floor (number / 60.));
number = fmod (number, 60.);
- excess_width = format->w - (p - tmp);
+ excess_width = format.w - (p - tmp);
if (excess_width < 0
- || (format->type == FMT_MTIME && excess_width < 3))
+ || (format.type == FMT_MTIME && excess_width < 3))
goto overflow;
if (excess_width == 3 || excess_width == 4
- || (excess_width >= 5 && format->d == 0))
+ || (excess_width >= 5 && format.d == 0))
p += sprintf (p, ":%02d", (int) number);
else if (excess_width >= 5)
{
- int d = MIN (format->d, excess_width - 4);
+ int d = MIN (format.d, excess_width - 4);
int w = d + 3;
c_snprintf (p, 64, ":%0*.*f", w, d, number);
if (settings->decimal != '.')
}
done:
- buf_copy_lpad (output, format->w, tmp, p - tmp, ' ');
- output[format->w] = '\0';
+ buf_copy_lpad (output, format.w, tmp, p - tmp, ' ');
+ output[format.w] = '\0';
return;
overflow:
/* Outputs WKDAY format. */
static void
-output_WKDAY (const union value *input, const struct fmt_spec *format,
+output_WKDAY (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
static const char *const weekdays[7] =
if (input->f >= 1 && input->f < 8)
{
- buf_copy_str_rpad (output, format->w,
+ buf_copy_str_rpad (output, format.w,
weekdays[(int) input->f - 1], ' ');
- output[format->w] = '\0';
+ output[format.w] = '\0';
}
else
{
/* Outputs MONTH format. */
static void
-output_MONTH (const union value *input, const struct fmt_spec *format,
+output_MONTH (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
static const char *const months[12] =
if (input->f >= 1 && input->f < 13)
{
- buf_copy_str_rpad (output, format->w, months[(int) input->f - 1], ' ');
- output[format->w] = '\0';
+ buf_copy_str_rpad (output, format.w, months[(int) input->f - 1], ' ');
+ output[format.w] = '\0';
}
else
{
/* Outputs A format. */
static void
output_A (const union value *input UNUSED,
- const struct fmt_spec *format UNUSED,
+ 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,
+output_AHEX (const union value *input, struct fmt_spec format,
const struct fmt_settings *settings UNUSED, char *output)
{
- output_hex (input->s, format->w / 2, output);
+ output_hex (input->s, format.w / 2, output);
}
\f
/* Decimal and scientific formatting. */
by FORMAT's style must be included; otherwise, they may be
omitted to make the number fit. */
static bool
-output_decimal (const struct rounder *r, const struct fmt_spec *format,
+output_decimal (const struct rounder *r, struct fmt_spec format,
const struct fmt_number_style *style, bool require_affixes,
char *output)
{
int decimals;
- for (decimals = format->d; decimals >= 0; decimals--)
+ for (decimals = format.d; decimals >= 0; decimals--)
{
/* Formatted version of magnitude of NUMBER. */
char magnitude[64];
width += style->neg_suffix.width;
if (add_neg_prefix)
width += style->neg_prefix.width;
- if (width > format->w)
+ if (width > format.w)
continue;
/* If there's room for the prefix and suffix, allocate
space. If the affixes are required, but there's no
space, give up. */
add_affixes = allocate_space (fmt_affix_width (style),
- format->w, &width);
+ format.w, &width);
if (!add_affixes && require_affixes)
continue;
requested but they were all dropped. */
add_grouping = (style->grouping != 0
&& integer_digits > 3
- && (format->d == 0 || decimals > 0)
+ && (format.d == 0 || decimals > 0)
&& allocate_space ((integer_digits - 1) / 3,
- format->w, &width));
+ format.w, &width));
/* Format the number's magnitude. */
rounder_format (r, decimals, magnitude);
/* Assemble number. */
p = output;
- if (format->w > width)
- p = mempset (p, ' ', format->w - width);
+ if (format.w > width)
+ p = mempset (p, ' ', format.w - width);
if (add_neg_prefix)
p = stpcpy (p, style->neg_prefix.s);
if (add_affixes)
else
p = mempset (p, ' ', style->neg_suffix.width);
- assert (p >= output + format->w);
- assert (p <= output + format->w + style->extra_bytes);
+ assert (p >= output + format.w);
+ assert (p <= output + format.w + style->extra_bytes);
*p = '\0';
return true;
/* Formats NUMBER into OUTPUT in scientific notation according to FORMAT and
STYLE. */
static bool
-output_scientific (double number, const struct fmt_spec *format,
+output_scientific (double number, struct fmt_spec format,
const struct fmt_number_style *style,
bool require_affixes, char *output)
{
width = 6 + style->neg_suffix.width;
if (number < 0)
width += style->neg_prefix.width;
- if (width > format->w)
+ if (width > format.w)
return false;
/* Check for room for prefix and suffix. */
- add_affixes = allocate_space (fmt_affix_width (style), format->w, &width);
+ add_affixes = allocate_space (fmt_affix_width (style), format.w, &width);
if (require_affixes && !add_affixes)
return false;
if any. (If that turns out to be 1, then we'll output a
decimal point without any digits following; that's what the
# flag does in the call to c_snprintf, below.) */
- fraction_width = MIN (MIN (format->d + 1, format->w - width), 16);
- if (format->type != FMT_E && fraction_width == 1)
+ fraction_width = MIN (MIN (format.d + 1, format.w - width), 16);
+ if (format.type != FMT_E && fraction_width == 1)
fraction_width = 0;
width += fraction_width;
/* Format (except suffix). */
p = output;
- if (width < format->w)
- p = mempset (p, ' ', format->w - width);
+ if (width < format.w)
+ p = mempset (p, ' ', format.w - width);
if (number < 0)
p = stpcpy (p, style->neg_prefix.s);
if (add_affixes)
else
p = mempset (p, ' ', style->neg_suffix.width);
- assert (p >= output + format->w);
- assert (p <= output + format->w + style->extra_bytes);
+ assert (p >= output + format.w);
+ assert (p <= output + format.w + style->extra_bytes);
*p = '\0';
return true;
/* Formats non-finite NUMBER into OUTPUT according to the width
given in FORMAT. */
static void
-output_infinite (double number, const struct fmt_spec *format, char *output)
+output_infinite (double number, struct fmt_spec format, char *output)
{
assert (!isfinite (number));
- if (format->w >= 3)
+ if (format.w >= 3)
{
const char *s;
else
s = "Unknown";
- buf_copy_str_lpad (output, format->w, s, ' ');
+ buf_copy_str_lpad (output, format.w, s, ' ');
}
else
output_overflow (format, output);
- output[format->w] = '\0';
+ output[format.w] = '\0';
}
/* Formats OUTPUT as a missing value for the given FORMAT. */
static void
-output_missing (const struct fmt_spec *format, char *output)
+output_missing (struct fmt_spec format, char *output)
{
- memset (output, ' ', format->w);
+ memset (output, ' ', format.w);
- if (format->type != FMT_N)
+ if (format.type != FMT_N)
{
- int dot_ofs = (format->type == FMT_PCT ? 2
- : format->type == FMT_E ? 5
+ int dot_ofs = (format.type == FMT_PCT ? 2
+ : format.type == FMT_E ? 5
: 1);
- output[MAX (0, format->w - format->d - dot_ofs)] = '.';
+ output[MAX (0, format.w - format.d - dot_ofs)] = '.';
}
else
- output[format->w - 1] = '.';
+ output[format.w - 1] = '.';
- output[format->w] = '\0';
+ output[format.w] = '\0';
}
/* Formats OUTPUT for overflow given FORMAT. */
static void
-output_overflow (const struct fmt_spec *format, char *output)
+output_overflow (struct fmt_spec format, char *output)
{
- memset (output, '*', format->w);
- output[format->w] = '\0';
+ memset (output, '*', format.w);
+ output[format.w] = '\0';
}
/* Converts the integer part of NUMBER to a packed BCD number
union value;
char *data_out (const union value *input, const char *input_encoding,
- const struct fmt_spec *, const struct fmt_settings *);
+ struct fmt_spec, const struct fmt_settings *);
char *data_out_pool (const union value *input, const char *input_encoding,
- const struct fmt_spec *, const struct fmt_settings *,
+ 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 *, const struct fmt_settings *,
+ 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_settings *,
+ struct fmt_spec, const struct fmt_settings *,
struct string *output, const char *output_encoding);
#endif /* data-out.h */
if (var_get_measure (var) != MEASURE_UNKNOWN)
continue;
- const struct fmt_spec *f = var_get_print_format (var);
- enum measure m = var_default_measure_for_format (f->type);
+ struct fmt_spec f = var_get_print_format (var);
+ enum measure m = var_default_measure_for_format (f.type);
if (m != MEASURE_UNKNOWN)
{
var_set_measure (var, m);
struct fmt_spec
dict_get_weight_format (const struct dictionary *d)
{
- return d->weight ? *var_get_print_format (d->weight) : F_8_0;
+ return d->weight ? var_get_print_format (d->weight) : F_8_0;
}
/* Sets the weighting variable of D to V, or turning off
add_date_time (g, s);
}
-/* Guesses the format of the input previously added to G using
- fmt_guesser_add, storing the guess into *F. The guessed
- format may not actually a valid input or output format, in
- that its width and number of decimal places may be outside the
- valid range for the guessed format type. The caller must
- therefore adjust the format to make it valid, e.g. by calling
- fmt_fix. */
-void
-fmt_guesser_guess (struct fmt_guesser *g, struct fmt_spec *f)
+/* Returns a guess about the format of the input previously added to G using
+ fmt_guesser_add(). The guessed format may not actually a valid input or
+ output format, in that its width and number of decimal places may be outside
+ the valid range for the guessed format type. The caller must therefore
+ adjust the format to make it valid, e.g. by calling fmt_fix(). */
+struct fmt_spec
+fmt_guesser_guess (struct fmt_guesser *g)
{
if (g->count > 0)
{
/* Set defaults. The guesser functions typically override
the width and type. */
- f->type = FMT_A;
- f->w = g->width;
- f->d = 0;
+ struct fmt_spec f = { .type = FMT_A, .w = g->width };
if (g->any_numeric > g->count / 2)
- guess_numeric (g, f);
+ guess_numeric (g, &f);
else if (g->any_date > g->count / 2)
- guess_date_time (g, f);
+ guess_date_time (g, &f);
+
+ return f;
}
else
{
/* No data at all. Use fallback default. */
- *f = fmt_default_for_width (0);
+ return fmt_default_for_width (0);
}
}
\f
void fmt_guesser_destroy (struct fmt_guesser *);
void fmt_guesser_clear (struct fmt_guesser *);
void fmt_guesser_add (struct fmt_guesser *, struct substring);
-void fmt_guesser_guess (struct fmt_guesser *, struct fmt_spec *);
+struct fmt_spec fmt_guesser_guess (struct fmt_guesser *);
#endif /* format-guesser.h */
fmt_for_input (enum fmt_type type, int w, int d)
{
struct fmt_spec f = { .type = type, .w = w, .d = d };
- assert (fmt_check_input (&f));
+ assert (fmt_check_input (f));
return f;
}
fmt_for_output (enum fmt_type type, int w, int d)
{
struct fmt_spec f = { .type = type, .w = w, .d = d };
- assert (fmt_check_output (&f));
+ assert (fmt_check_output (f));
return f;
}
/* 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 (struct fmt_spec input,
const struct fmt_settings *settings)
{
struct fmt_spec output;
assert (fmt_check_input (input));
- output.type = fmt_input_to_output (input->type);
- output.w = input->w;
+ output.type = fmt_input_to_output (input.type);
+ output.w = input.w;
if (output.w > fmt_max_output_width (output.type))
output.w = fmt_max_output_width (output.type);
else if (output.w < fmt_min_output_width (output.type))
output.w = fmt_min_output_width (output.type);
- output.d = input->d;
+ output.d = input.d;
- switch (input->type)
+ switch (input.type)
{
case FMT_Z:
output.w++;
case FMT_PCT:
{
const struct fmt_number_style *style =
- fmt_settings_get_style (settings, input->type);
+ fmt_settings_get_style (settings, input.type);
output.w += fmt_affix_width (style);
- if (style->grouping != 0 && input->w - input->d >= 3)
- output.w += (input->w - input->d - 1) / 3;
+ if (style->grouping != 0 && input.w - input.d >= 3)
+ output.w += (input.w - input.d - 1) / 3;
if (output.d > 0)
output.w++;
}
break;
case FMT_E:
- output.d = MAX (input->d, 3);
- output.w = MAX (input->w, output.d + 7);
+ output.d = MAX (input.d, 3);
+ output.w = MAX (input.w, output.d + 7);
break;
case FMT_PIBHEX:
- output.w = max_digits_for_bytes (input->w / 2) + 1;
+ output.w = max_digits_for_bytes (input.w / 2) + 1;
break;
case FMT_RB:
case FMT_P:
case FMT_PK:
- output.w = 2 * input->w + (input->d > 0);
+ output.w = 2 * input.w + (input.d > 0);
break;
case FMT_IB:
case FMT_PIB:
- output.w = max_digits_for_bytes (input->w) + 1;
+ output.w = max_digits_for_bytes (input.w) + 1;
if (output.d > 0)
output.w++;
break;
break;
case FMT_AHEX:
- output.w = input->w / 2;
+ output.w = input.w / 2;
break;
case FMT_DATE:
break;
case FMT_MTIME:
- if (input->d)
- output.w = MAX (input->w, input->d + 6);
+ if (input.d)
+ output.w = MAX (input.w, input.d + 6);
break;
case FMT_YMDHMS:
- if (input->w)
- output.w = MAX (input->w, input->d + 20);
+ if (input.w)
+ output.w = MAX (input.w, input.d + 20);
break;
default:
if (output.w > fmt_max_output_width (output.type))
output.w = fmt_max_output_width (output.type);
- assert (fmt_check_output (&output));
+ assert (fmt_check_output (output));
return output;
}
returns a malloc()'d string that describes the error. The caller must
eventually free() the string. */
char *
-fmt_check__ (const struct fmt_spec *spec, enum fmt_use use)
+fmt_check__ (struct fmt_spec spec, enum fmt_use use)
{
char str[FMT_STRING_LEN_MAX + 1];
int min_w, max_w, max_d;
- assert (is_fmt_type (spec->type));
+ assert (is_fmt_type (spec.type));
fmt_to_string (spec, str);
- if (use == FMT_FOR_INPUT && !fmt_usable_for_input (spec->type))
+ if (use == FMT_FOR_INPUT && !fmt_usable_for_input (spec.type))
return xasprintf (_("Format %s may not be used for input."), str);
- if (spec->w % fmt_step_width (spec->type))
+ if (spec.w % fmt_step_width (spec.type))
{
- assert (fmt_step_width (spec->type) == 2);
+ assert (fmt_step_width (spec.type) == 2);
return (use == FMT_FOR_INPUT
? xasprintf (_("Input format %s specifies width %d, "
"but %s requires an even width."),
- str, spec->w, fmt_name (spec->type))
+ str, spec.w, fmt_name (spec.type))
: xasprintf (_("Output format %s specifies width %d, "
"but %s requires an even width."),
- str, spec->w, fmt_name (spec->type)));
+ str, spec.w, fmt_name (spec.type)));
}
- min_w = fmt_min_width (spec->type, use);
- max_w = fmt_max_width (spec->type, use);
- if (spec->w < min_w || spec->w > max_w)
+ min_w = fmt_min_width (spec.type, use);
+ max_w = fmt_max_width (spec.type, use);
+ if (spec.w < min_w || spec.w > max_w)
return (use == FMT_FOR_INPUT
? xasprintf (_("Input format %s specifies width %d, but "
"%s requires a width between %d and %d."),
- str, spec->w, fmt_name (spec->type), min_w, max_w)
+ str, spec.w, fmt_name (spec.type), min_w, max_w)
: xasprintf (_("Output format %s specifies width %d, but "
"%s requires a width between %d and %d."),
- str, spec->w, fmt_name (spec->type), min_w, max_w));
+ str, spec.w, fmt_name (spec.type), min_w, max_w));
- max_d = fmt_max_decimals (spec->type, spec->w, use);
- if (!fmt_takes_decimals (spec->type) && spec->d != 0)
+ max_d = fmt_max_decimals (spec.type, spec.w, use);
+ if (!fmt_takes_decimals (spec.type) && spec.d != 0)
return (use == FMT_FOR_INPUT
? xasprintf (ngettext (
"Input format %s specifies %d decimal "
"Input format %s specifies %d decimal "
"places, but %s does not allow any "
"decimals.",
- spec->d),
- str, spec->d, fmt_name (spec->type))
+ spec.d),
+ str, spec.d, fmt_name (spec.type))
: xasprintf (ngettext (
"Output format %s specifies %d decimal "
"place, but %s does not allow any decimals.",
"Output format %s specifies %d decimal places, but "
"%s does not allow any decimals.",
- spec->d),
- str, spec->d, fmt_name (spec->type)));
- else if (spec->d > max_d)
+ spec.d),
+ str, spec.d, fmt_name (spec.type)));
+ else if (spec.d > max_d)
{
if (max_d > 0)
return (use == FMT_FOR_INPUT
"but width %d allows at most %d decimals.",
"Input format %s specifies %d decimal places, "
"but width %d allows at most %d decimals.",
- spec->d),
- str, spec->d, spec->w, max_d)
+ spec.d),
+ str, spec.d, spec.w, max_d)
: xasprintf (ngettext (
"Output format %s specifies %d decimal place, "
"but width %d allows at most %d decimals.",
"Output format %s specifies %d decimal places, "
"but width %d allows at most %d decimals.",
- spec->d),
- str, spec->d, spec->w, max_d));
+ spec.d),
+ str, spec.d, spec.w, max_d));
else
return (use == FMT_FOR_INPUT
? xasprintf (ngettext (
"but width %d does not allow for any decimals.",
"Input format %s specifies %d decimal places, "
"but width %d does not allow for any decimals.",
- spec->d),
- str, spec->d, spec->w)
+ spec.d),
+ str, spec.d, spec.w)
: xasprintf (ngettext (
"Output format %s specifies %d decimal place, "
"but width %d does not allow for any decimals.",
"Output format %s specifies %d decimal places, "
"but width %d does not allow for any decimals.",
- spec->d),
- str, spec->d, spec->w));
+ spec.d),
+ str, spec.d, spec.w));
}
return NULL;
}
char *
-fmt_check_input__ (const struct fmt_spec *spec)
+fmt_check_input__ (struct fmt_spec spec)
{
return fmt_check__ (spec, FMT_FOR_INPUT);
}
char *
-fmt_check_output__ (const struct fmt_spec *spec)
+fmt_check_output__ (struct fmt_spec spec)
{
return fmt_check__ (spec, FMT_FOR_OUTPUT);
}
/* Returns true if SPEC is valid for USE, false otherwise. */
bool
-fmt_check (const struct fmt_spec *spec, enum fmt_use use)
+fmt_check (struct fmt_spec spec, enum fmt_use use)
{
return error_to_bool (fmt_check__ (spec, use));
}
/* Returns true if SPEC is valid as an input format, otherwise false. */
bool
-fmt_check_input (const struct fmt_spec *spec)
+fmt_check_input (struct fmt_spec spec)
{
return fmt_check (spec, FMT_FOR_INPUT);
}
/* Returnst true SPEC is valid as an output format, false otherwise. */
bool
-fmt_check_output (const struct fmt_spec *spec)
+fmt_check_output (struct fmt_spec spec)
{
return fmt_check (spec, FMT_FOR_OUTPUT);
}
caller must eventually free(). VARNAME is optional and only used in the
error message.*/
char *
-fmt_check_type_compat__ (const struct fmt_spec *format, const char *varname,
+fmt_check_type_compat__ (struct fmt_spec format, const char *varname,
enum val_type var_type)
{
assert (val_type_is_valid (var_type));
- if ((var_type == VAL_STRING) != (fmt_is_string (format->type) != 0))
+ if ((var_type == VAL_STRING) != (fmt_is_string (format.type) != 0))
{
char str[FMT_STRING_LEN_MAX + 1];
fmt_to_string (format, str);
/* Returns FORMAT is appropriate for a variable of the given VAR_TYPE and
returns true if so, otherwise false. */
bool
-fmt_check_type_compat (const struct fmt_spec *format, enum val_type var_type)
+fmt_check_type_compat (struct fmt_spec format, enum val_type var_type)
{
return error_to_bool (fmt_check_type_compat__ (format, NULL, var_type));
}
caller must eventually free(). VARNAME is optional and only used in the
error message. */
char *
-fmt_check_width_compat__ (const struct fmt_spec *format, const char *varname,
+fmt_check_width_compat__ (struct fmt_spec format, const char *varname,
int width)
{
char *error = fmt_check_type_compat__ (format, varname,
fmt_to_string (format, format_str);
char better_str[FMT_STRING_LEN_MAX + 1];
- if (format->type == FMT_A)
+ if (format.type == FMT_A)
snprintf (better_str, sizeof better_str, "A%d", width);
else
snprintf (better_str, sizeof better_str, "AHEX%d", width * 2);
/* Checks that FORMAT is appropriate for a variable of the given WIDTH and
returns true if so, otherwise false. */
bool
-fmt_check_width_compat (const struct fmt_spec *format, int width)
+fmt_check_width_compat (struct fmt_spec format, int width)
{
return error_to_bool (fmt_check_width_compat__ (format, NULL, width));
}
/* Returns the width corresponding to FORMAT. The return value
is the width of the `union value's required by FORMAT. */
int
-fmt_var_width (const struct fmt_spec *format)
+fmt_var_width (struct fmt_spec format)
{
- return (format->type == FMT_AHEX ? format->w / 2
- : format->type == FMT_A ? format->w
+ return (format.type == FMT_AHEX ? format.w / 2
+ : format.type == FMT_A ? format.w
: 0);
}
even if F's format type does not allow decimals, to allow
accurately presenting incorrect formats to the user. */
char *
-fmt_to_string (const struct fmt_spec *f, char buffer[FMT_STRING_LEN_MAX + 1])
+fmt_to_string (struct fmt_spec f, char buffer[FMT_STRING_LEN_MAX + 1])
{
- if (fmt_takes_decimals (f->type) || f->d > 0)
+ if (fmt_takes_decimals (f.type) || f.d > 0)
snprintf (buffer, FMT_STRING_LEN_MAX + 1,
- "%s%d.%d", fmt_name (f->type), f->w, f->d);
+ "%s%d.%d", fmt_name (f.type), f.w, f.d);
else
snprintf (buffer, FMT_STRING_LEN_MAX + 1,
- "%s%d", fmt_name (f->type), f->w);
+ "%s%d", fmt_name (f.type), f.w);
return buffer;
}
/* Returns true if A and B are identical formats,
false otherwise. */
bool
-fmt_equal (const struct fmt_spec *a, const struct fmt_spec *b)
+fmt_equal (struct fmt_spec a, struct fmt_spec b)
{
- return a->type == b->type && a->w == b->w && a->d == b->d;
+ return a.type == b.type && a.w == b.w && a.d == b.d;
}
/* Adjusts FMT to be valid for a value of the given WIDTH if necessary.
if (loose)
fmt_fix_output (f);
- else if (!fmt_check_output (f))
+ else if (!fmt_check_output (*f))
return false;
- return fmt_check_width_compat (f, width);
+ return fmt_check_width_compat (*f, width);
}
/* Returns true if TYPE may be used as an input format,
/* 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 (struct fmt_spec,
const struct fmt_settings *);
struct fmt_spec fmt_default_for_width (int width);
/* Verifying formats. */
-bool fmt_check (const struct fmt_spec *, enum fmt_use);
-bool fmt_check_input (const struct fmt_spec *);
-bool fmt_check_output (const struct fmt_spec *);
-bool fmt_check_type_compat (const struct fmt_spec *, enum val_type);
-bool fmt_check_width_compat (const struct fmt_spec *, int var_width);
-
-char *fmt_check__ (const struct fmt_spec *, enum fmt_use);
-char *fmt_check_input__ (const struct fmt_spec *);
-char *fmt_check_output__ (const struct fmt_spec *);
-char *fmt_check_type_compat__ (const struct fmt_spec *, const char *varname,
+bool fmt_check (struct fmt_spec, enum fmt_use);
+bool fmt_check_input (struct fmt_spec);
+bool fmt_check_output (struct fmt_spec);
+bool fmt_check_type_compat (struct fmt_spec, enum val_type);
+bool fmt_check_width_compat (struct fmt_spec, int var_width);
+
+char *fmt_check__ (struct fmt_spec, enum fmt_use);
+char *fmt_check_input__ (struct fmt_spec);
+char *fmt_check_output__ (struct fmt_spec);
+char *fmt_check_type_compat__ (struct fmt_spec, const char *varname,
enum val_type);
-char *fmt_check_width_compat__ (const struct fmt_spec *, const char *varname,
+char *fmt_check_width_compat__ (struct fmt_spec, const char *varname,
int var_width);
/* Working with formats. */
-int fmt_var_width (const struct fmt_spec *);
-char *fmt_to_string (const struct fmt_spec *, char s[FMT_STRING_LEN_MAX + 1]);
-bool fmt_equal (const struct fmt_spec *, const struct fmt_spec *);
+int fmt_var_width (struct fmt_spec);
+char *fmt_to_string (struct fmt_spec, char s[FMT_STRING_LEN_MAX + 1]);
+bool fmt_equal (struct fmt_spec, struct fmt_spec);
bool fmt_resize (struct fmt_spec *, int new_width);
void fmt_fix (struct fmt_spec *, enum fmt_use);
{
const char *text = CHAR_CAST (const char *, xv);
- const struct fmt_spec *fmt = var_get_write_format (var);
+ const struct fmt_spec fmt = var_get_write_format (var);
- char *m = data_in (ss_cstr (text), "UTF-8", fmt->type,
+ char *m = data_in (ss_cstr (text), "UTF-8", fmt.type,
settings_get_fmt_settings (), v, var_get_width (var),
"UTF-8");
static enum val_numeric_type
var_get_numeric_type_ (const struct variable *var)
{
- const struct fmt_spec *print = var_get_print_format (var);
+ const struct fmt_spec print = var_get_print_format (var);
if (var_get_type (var) == VAL_STRING)
return VAL_STRING_TYPE;
if (var_has_value_labels (var))
return VAL_CATEGORICAL_TYPE;
- if (print->d > 0)
+ if (print.d > 0)
return VAL_DECIMAL_TYPE;
- if (print->type == FMT_DATETIME)
+ if (print.type == FMT_DATETIME)
return VAL_DATETIME_TYPE;
- if (print->type == FMT_F)
+ if (print.type == FMT_F)
return VAL_INTEGER_TYPE;
return VAL_CATEGORICAL_TYPE;
value_copy_str_rpad (v, var_get_width (var), xmv->text, ' ');
else
{
- const struct fmt_spec *fmt = var_get_write_format (var);
- enum fmt_category fc = fmt_get_category (fmt->type);
+ const struct fmt_spec fmt = var_get_write_format (var);
+ enum fmt_category fc = fmt_get_category (fmt.type);
assert (fc != FMT_CAT_STRING);
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,
+ char *m = data_in (ss_cstr (text), "UTF-8", fmt.type,
settings_get_fmt_settings (), v,
var_get_width (var), "UTF-8");
else
fmt = fmt_default_for_width (width);
- var_set_both_formats (var, &fmt);
+ var_set_both_formats (var, fmt);
}
if (n_var_specs == 0)
var->format.w = (format >> 8) & 0xff;
var->format.d = format & 0xff;
fmt_fix_output (&var->format);
- var->width = fmt_var_width (&var->format);
+ var->width = fmt_var_width (var->format);
if (var_label_ofs)
{
}
/* Set formats. */
- var_set_both_formats (var, &rec->format);
+ var_set_both_formats (var, rec->format);
}
return true;
.d = portable_format[2],
};
- if (fmt_check_output (&format)
- && fmt_check_width_compat (&format, var_get_width (v)))
+ if (fmt_check_output (format)
+ && fmt_check_width_compat (format, var_get_width (v)))
return format;
if (*report_error)
{
char fmt_string[FMT_STRING_LEN_MAX + 1];
- fmt_to_string (&format, fmt_string);
+ fmt_to_string (format, fmt_string);
if (var_is_numeric (v))
warning (r, _("Numeric variable %s has invalid format "
"specifier %s."),
print = convert_format (r, &fmt[0], v, &report_error);
write = convert_format (r, &fmt[3], v, &report_error);
- var_set_print_format (v, &print);
- var_set_write_format (v, &write);
+ var_set_print_format (v, print);
+ var_set_write_format (v, write);
/* Range missing values. */
mv_init (&miss, width);
buf_write (w, "7", 1);
write_int (w, width);
write_string (w, var_get_short_name (v, 0));
- write_format (w, *var_get_print_format (v), width);
- write_format (w, *var_get_write_format (v), width);
+ write_format (w, var_get_print_format (v), width);
+ write_format (w, var_get_write_format (v), width);
/* Write missing values. */
mv_copy (&mv, var_get_missing_values (v));
#endif
static struct variable *
-create_var (struct psql_reader *r, const struct fmt_spec *fmt,
+create_var (struct psql_reader *r, struct fmt_spec fmt,
int width, const char *suggested_name, int col)
{
unsigned long int vx = 0;
fmt.w = width = PSQL_DEFAULT_WIDTH;
- var = create_var (r, &fmt, width, PQfname (qres, i), i);
+ var = create_var (r, fmt, width, PQfname (qres, i), i);
if (type == NUMERICOID && n_tuples > 0)
{
const uint8_t *vptr = (const uint8_t *) PQgetvalue (qres, 0, i);
fmt.type = FMT_E;
fmt.w = fmt_max_output_width (fmt.type) ;
fmt.d = MIN (dscale, fmt_max_output_decimals (fmt.type, fmt.w));
- var_set_both_formats (var, &fmt);
+ var_set_both_formats (var, fmt);
}
/* Timezones need an extra variable */
fmt.w = 8;
fmt.d = 2;
- create_var (r, &fmt, 0, ds_cstr (&name), -1);
+ create_var (r, fmt, 0, ds_cstr (&name), -1);
ds_destroy (&name);
}
fmt.w = 3;
fmt.d = 0;
- create_var (r, &fmt, 0, ds_cstr (&name), -1);
+ create_var (r, fmt, 0, ds_cstr (&name), -1);
ds_destroy (&name);
}
/* Default format for variables created by transformations and by
DATA LIST {FREE,LIST}. */
-const struct fmt_spec *
+struct fmt_spec
settings_get_format (void)
{
- return &the_settings.default_format;
+ return the_settings.default_format;
}
/* Set default format for variables created by transformations
and by DATA LIST {FREE,LIST}. */
void
-settings_set_format (const struct fmt_spec *default_format)
+settings_set_format (const struct fmt_spec default_format)
{
- the_settings.default_format = *default_format;
+ the_settings.default_format = default_format;
}
/* Are we in testing mode? (e.g. --testing-mode command line
which must be of type FMT_DOLLAR. The caller must free the
string. */
char *
-settings_dollar_template (const struct fmt_spec *fmt)
+settings_dollar_template (const struct fmt_spec fmt)
{
struct string str = DS_EMPTY_INITIALIZER;
int c;
const struct fmt_number_style *fns ;
- assert (fmt->type == FMT_DOLLAR);
+ assert (fmt.type == FMT_DOLLAR);
- fns = fmt_settings_get_style (&the_settings.styles, fmt->type);
+ fns = fmt_settings_get_style (&the_settings.styles, fmt.type);
ds_put_byte (&str, '$');
- for (c = MAX (fmt->w - fmt->d - 1, 0); c > 0;)
+ for (c = MAX (fmt.w - fmt.d - 1, 0); c > 0;)
{
ds_put_byte (&str, '#');
if (--c % 4 == 0 && c > 0)
--c;
}
}
- if (fmt->d > 0)
+ if (fmt.d > 0)
{
ds_put_byte (&str, fns->decimal);
- ds_put_byte_multiple (&str, '#', fmt->d);
+ ds_put_byte_multiple (&str, '#', fmt.d);
}
return ds_cstr (&str);
size_t settings_get_workspace_cases (const struct caseproto *);
void settings_set_workspace (size_t);
-const struct fmt_spec *settings_get_format (void);
-void settings_set_format (const struct fmt_spec *);
+struct fmt_spec settings_get_format (void);
+void settings_set_format (const struct fmt_spec);
bool settings_get_testing_mode (void);
void settings_set_testing_mode (bool);
double settings_get_small (void);
void settings_set_small (double);
-char * settings_dollar_template (const struct fmt_spec *fmt);
+char *settings_dollar_template (struct fmt_spec);
/* Routing of different kinds of output. */
enum settings_output_devices
if (fmt_from_u32 (format, var_get_width (v), false, &f))
{
if (which == PRINT_FORMAT)
- var_set_print_format (v, &f);
+ var_set_print_format (v, f);
else
- var_set_write_format (v, &f);
+ var_set_write_format (v, f);
}
else if (format == 0)
{
static void
write_format (struct sfm_writer *w, struct fmt_spec fmt, int width)
{
- assert (fmt_check_output (&fmt));
+ assert (fmt_check_output (fmt));
assert (sfm_width_to_segments (width) == 1);
if (width > 0)
write_int (w, 0);
/* Print and write formats. */
- write_format (w, *var_get_print_format (v), seg0_width);
- write_format (w, *var_get_write_format (v), seg0_width);
+ write_format (w, var_get_print_format (v), seg0_width);
+ write_format (w, var_get_write_format (v), seg0_width);
/* Short name.
The full name is in a translation table written
};
\f
-static void var_set_print_format_quiet (struct variable *v, const struct fmt_spec *print);
-static void var_set_write_format_quiet (struct variable *v, const struct fmt_spec *write);
+static void var_set_print_format_quiet (struct variable *v, struct fmt_spec);
+static void var_set_write_format_quiet (struct variable *v, struct fmt_spec);
static void var_set_label_quiet (struct variable *v, const char *label);
static void var_set_name_quiet (struct variable *v, const char *name);
if (print)
{
- var_set_print_format_quiet (v, print);
+ var_set_print_format_quiet (v, *print);
traits |= VAR_TRAIT_PRINT_FORMAT;
}
if (write)
{
- var_set_write_format_quiet (v, write);
+ var_set_write_format_quiet (v, *write);
traits |= VAR_TRAIT_WRITE_FORMAT;
}
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 (" "));
/* Print and write formats. */
/* Returns V's print format specification. */
-const struct fmt_spec *
+struct fmt_spec
var_get_print_format (const struct variable *v)
{
- return &v->print;
+ return v->print;
}
/* Sets V's print format specification to PRINT, which must be a
(ordinarily an output format, but input formats are not
rejected). */
static void
-var_set_print_format_quiet (struct variable *v, const struct fmt_spec *print)
+var_set_print_format_quiet (struct variable *v, struct fmt_spec print)
{
- if (!fmt_equal (&v->print, print))
+ if (!fmt_equal (v->print, print))
{
assert (fmt_check_width_compat (print, v->width));
- v->print = *print;
+ v->print = print;
}
}
(ordinarily an output format, but input formats are not
rejected). */
void
-var_set_print_format (struct variable *v, const struct fmt_spec *print)
+var_set_print_format (struct variable *v, struct fmt_spec print)
{
struct variable *ov = var_clone (v);
var_set_print_format_quiet (v, print);
}
/* Returns V's write format specification. */
-const struct fmt_spec *
+struct fmt_spec
var_get_write_format (const struct variable *v)
{
- return &v->write;
+ return v->write;
}
/* Sets V's write format specification to WRITE, which must be a
(ordinarily an output format, but input formats are not
rejected). */
static void
-var_set_write_format_quiet (struct variable *v, const struct fmt_spec *write)
+var_set_write_format_quiet (struct variable *v, struct fmt_spec write)
{
- if (!fmt_equal (&v->write, write))
+ if (!fmt_equal (v->write, write))
{
assert (fmt_check_width_compat (write, v->width));
- v->write = *write;
+ v->write = write;
}
}
(ordinarily an output format, but input formats are not
rejected). */
void
-var_set_write_format (struct variable *v, const struct fmt_spec *write)
+var_set_write_format (struct variable *v, struct fmt_spec write)
{
struct variable *ov = var_clone (v);
var_set_write_format_quiet (v, write);
V's width (ordinarily an output format, but input formats are
not rejected). */
void
-var_set_both_formats (struct variable *v, const struct fmt_spec *format)
+var_set_both_formats (struct variable *v, struct fmt_spec format)
{
struct variable *ov = var_clone (v);
var_set_print_format_quiet (v, format);
void var_clear_value_labels (struct variable *);
/* Print and write formats. */
-const struct fmt_spec *var_get_print_format (const struct variable *);
-void var_set_print_format (struct variable *, const struct fmt_spec *);
-const struct fmt_spec *var_get_write_format (const struct variable *);
-void var_set_write_format (struct variable *, const struct fmt_spec *);
-void var_set_both_formats (struct variable *, const struct fmt_spec *);
+struct fmt_spec var_get_print_format (const struct variable *);
+void var_set_print_format (struct variable *, struct fmt_spec);
+struct fmt_spec var_get_write_format (const struct variable *);
+void var_set_write_format (struct variable *, struct fmt_spec);
+void var_set_both_formats (struct variable *, struct fmt_spec);
struct fmt_spec var_default_formats (int width);
f = fmt_for_output (FMT_F, 8, 2);
else
f = function->format;
- var_set_both_formats (v->dest, &f);
+ var_set_both_formats (v->dest, f);
}
if (dest_label[i])
var_set_label (v->dest, dest_label[i]);
spec->width = var_get_width (src_vars[i]);
spec->src_idx = var_get_case_index (src_vars[i]);
spec->src_name = xstrdup (var_get_name (src_vars[i]));
- spec->format = *var_get_print_format (src_vars[i]);
+ spec->format = var_get_print_format (src_vars[i]);
const char *label = var_get_label (src_vars[i]);
spec->label = xstrdup_if_nonnull (label);
size_t n_items = hmap_count (&spec->items->ht);
char *longest_value = xasprintf ("%zu", n_items);
struct fmt_spec format = { .type = FMT_F, .w = strlen (longest_value) };
- var_set_both_formats (dst, &format);
+ var_set_both_formats (dst, format);
free (longest_value);
/* Create array of pointers to items. */
old_values->root, pivot_value_new_value (
&item->from, item->width,
(item->width
- ? &(struct fmt_spec) { .type = FMT_F, .w = item->width }
- : &spec->format),
+ ? (struct fmt_spec) { .type = FMT_F, .w = item->width }
+ : spec->format),
dict_get_encoding (dict)));
pivot_table_put2 (table, 0, old_value_idx,
pivot_value_new_integer (item->to));
var_name, subcommand);
return false;
}
- var_set_both_formats (*var, &format);
+ var_set_both_formats (*var, format);
}
else
*var = NULL;
return (struct fmt_spec) { .type = FMT_PCT, .w = 40, .d = 1 };
case CTF_GENERAL:
- return *var_get_print_format (var);
+ return var_get_print_format (var);
default:
NOT_REACHED ();
if (!parse_format_specifier (lexer, format))
return false;
- char *error = fmt_check_output__ (format);
+ char *error = fmt_check_output__ (*format);
if (!error)
- error = fmt_check_type_compat__ (format, NULL, VAL_NUMERIC);
+ error = fmt_check_type_compat__ (*format, NULL, VAL_NUMERIC);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
if (!parse_variables (lexer, dict, &vars, &n_vars, PV_NO_SCRATCH))
return false;
- const struct fmt_spec *common_format = var_get_print_format (vars[0]);
+ struct fmt_spec common_format = var_get_print_format (vars[0]);
+ bool has_common_format = true;
for (size_t i = 1; i < n_vars; i++)
{
- const struct fmt_spec *f = var_get_print_format (vars[i]);
- if (f->type != common_format->type)
+ struct fmt_spec f = var_get_print_format (vars[i]);
+ if (f.type != common_format.type)
{
- common_format = NULL;
+ has_common_format = false;
break;
}
}
bool parse_strings
- = (common_format
- && (fmt_get_category (common_format->type)
+ = (has_common_format
+ && (fmt_get_category (common_format.type)
& (FMT_CAT_DATE | FMT_CAT_TIME | FMT_CAT_DATE_COMPONENT)));
struct ctables_categories *c = xmalloc (sizeof *c);
switch (cat->type)
{
case CCT_POSTCOMPUTE:
- cat->parse_format = parse_strings ? common_format->type : FMT_F;
+ cat->parse_format = parse_strings ? common_format.type : FMT_F;
struct msg_location *cats_location
= lex_ofs_location (lexer, cats_start_ofs, cats_end_ofs);
bool ok = ctables_recursive_check_postcompute (
{
double n;
if (!parse_category_string (cat->location, cat->string, dict,
- common_format->type, &n))
+ common_format.type, &n))
goto error;
ss_dealloc (&cat->string);
n[0] = -DBL_MAX;
else if (!parse_category_string (cat->location,
cat->srange[0], dict,
- common_format->type, &n[0]))
+ common_format.type, &n[0]))
goto error;
if (!cat->srange[1].string)
n[1] = DBL_MAX;
else if (!parse_category_string (cat->location,
cat->srange[1], dict,
- common_format->type, &n[1]))
+ common_format.type, &n[1]))
goto error;
ss_dealloc (&cat->srange[0]);
}
static char *
-ctables_format (double d, const struct fmt_spec *format,
+ctables_format (double d, struct fmt_spec format,
const struct fmt_settings *settings)
{
const union value v = { .f = d };
value = pivot_value_new_user_text (ct->missing, SIZE_MAX);
else if (is_ctables_format)
value = pivot_value_new_user_text_nocopy (
- ctables_format (d, &format, &ct->ctables_formats));
+ ctables_format (d, format, &ct->ctables_formats));
else
{
value = pivot_value_new_number (d);
/* Create variables and var specs. */
size_t name_idx = 0;
for (struct fmt_spec *f = formats; f < &formats[n_formats]; f++)
- if (!execute_placement_format (f, &record, &column))
+ if (!execute_placement_format (*f, &record, &column))
{
/* Create variable. */
const char *name = names[name_idx++];
- int width = fmt_var_width (f);
+ int width = fmt_var_width (*f);
struct variable *v = dict_create_var (dict, name, width);
if (v != NULL)
{
/* Success. */
struct fmt_spec output = fmt_for_output_from_input (
- f, settings_get_fmt_settings ());
- var_set_both_formats (v, &output);
+ *f, settings_get_fmt_settings ());
+ var_set_both_formats (v, output);
}
else
{
return false;
}
- data_parser_add_fixed_field (parser, f,
+ data_parser_add_fixed_field (parser, *f,
var_get_case_index (v),
var_get_name (v), record, column);
input.d = 0;
}
- char *error = fmt_check_input__ (&input);
+ char *error = fmt_check_input__ (input);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
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
{
lex_match (lexer, T_ASTERISK);
input = fmt_for_input (FMT_F, 8, 0);
- output = *settings_get_format ();
+ output = settings_get_format ();
}
for (size_t i = 0; i < n_names; i++)
{
struct variable *v = dict_create_var (dict, names[i],
- fmt_var_width (&input));
+ fmt_var_width (input));
if (!v)
{
lex_ofs_error (lexer, vars_start, vars_end,
_("%s is a duplicate variable name."), names[i]);
return false;
}
- var_set_both_formats (v, &output);
+ var_set_both_formats (v, output);
data_parser_add_delimited_field (parser,
- &input, var_get_case_index (v),
+ input, var_get_case_index (v),
var_get_name (v));
}
}
}
static void
-add_field (struct data_parser *p, const struct fmt_spec *format, int case_idx,
+add_field (struct data_parser *p, struct fmt_spec format, int case_idx,
const char *name, int record, int first_column)
{
struct field *field;
if (p->n_fields == p->field_allocated)
p->fields = x2nrealloc (p->fields, &p->field_allocated, sizeof *p->fields);
field = &p->fields[p->n_fields++];
- field->format = *format;
- field->case_idx = case_idx;
- field->name = xstrdup (name);
- field->record = record;
- field->first_column = first_column;
+ *field = (struct field) {
+ .format = format,
+ .case_idx = case_idx,
+ .name = xstrdup (name),
+ .record = record,
+ .first_column = first_column,
+ };
}
/* Adds a delimited field to the field parsed by PARSER, which
against variable NAME. */
void
data_parser_add_delimited_field (struct data_parser *parser,
- const struct fmt_spec *format, int case_idx,
+ struct fmt_spec format, int case_idx,
const char *name)
{
assert (parser->type == DP_DELIMITED);
increased as needed. */
void
data_parser_add_fixed_field (struct data_parser *parser,
- const struct fmt_spec *format, int case_idx,
+ struct fmt_spec format, int case_idx,
const char *name,
int record, int first_column)
{
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),
+ value, fmt_var_width (f->format),
output_encoding);
if (error == NULL)
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);
+ fmt_var_width (f->format), output_encoding);
if (error != NULL)
parse_error (reader, f, first_column, last_column, error);
}
f->name);
for (; f < end; f++)
value_set_missing (case_data_rw_idx (c, f->case_idx),
- fmt_var_width (&f->format));
+ fmt_var_width (f->format));
goto exit;
}
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);
+ fmt_var_width (f->format), output_encoding);
if (error != NULL)
parse_error (reader, f, first_column, last_column, error);
}
char str[FMT_STRING_LEN_MAX + 1];
pivot_table_put2 (table, 2, variable_idx,
pivot_value_new_user_text (
- fmt_to_string (&f->format, str), -1));
+ fmt_to_string (f->format, str), -1));
}
char str[FMT_STRING_LEN_MAX + 1];
pivot_table_put2 (table, 0, variable_idx,
pivot_value_new_user_text (
- fmt_to_string (&f->format, str), -1));
+ fmt_to_string (f->format, str), -1));
}
pivot_table_submit (table);
/* Field setup and parsing. */
void data_parser_add_delimited_field (struct data_parser *,
- const struct fmt_spec *, int fv,
+ struct fmt_spec, int fv,
const char *name);
void data_parser_add_fixed_field (struct data_parser *,
- const struct fmt_spec *, int fv,
- const char *name,
+ struct fmt_spec, int fv, const char *name,
int record, int first_column);
bool data_parser_any_fields (const struct data_parser *);
bool data_parser_parse (struct data_parser *, struct dfm_reader *,
}
if (!parse_format_specifier (lexer, &f))
goto fail;
- char *error = fmt_check_output__ (&f);
+ char *error = fmt_check_output__ (f);
if (!error)
- error = fmt_check_width_compat__ (&f, var_get_name (v[0]), width);
+ error = fmt_check_width_compat__ (f, var_get_name (v[0]), width);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
for (i = 0; i < cv; i++)
{
if (print_format)
- var_set_print_format (v[i], &f);
+ var_set_print_format (v[i], f);
if (write_format)
- var_set_write_format (v[i], &f);
+ var_set_write_format (v[i], f);
}
free (v);
v = NULL;
{
if (!parse_format_specifier (lexer, &input))
goto error;
- error = fmt_check_input__ (&input);
+ error = fmt_check_input__ (input);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
free (error);
goto error;
}
- output = fmt_for_output_from_input (&input,
+ output = fmt_for_output_from_input (input,
settings_get_fmt_settings ());
}
else
/* Compose input format. */
input = (struct fmt_spec) { .type = fmt_type, .w = lc - fc + 1 };
- error = fmt_check_input__ (&input);
+ error = fmt_check_input__ (input);
if (error)
{
lex_ofs_error (lexer, start_ofs, end_ofs, "%s", error);
if (w != 0)
{
output = (struct fmt_spec) { .type = fmt_type, .w = w, .d = d };
- error = fmt_check_output__ (&output);
+ error = fmt_check_output__ (output);
if (error)
{
lex_ofs_error (lexer, start_ofs, end_ofs, "%s", error);
}
}
else
- output = fmt_for_output_from_input (&input,
+ output = fmt_for_output_from_input (input,
settings_get_fmt_settings ());
}
- struct variable *v = dict_create_var (dict, name, fmt_var_width (&input));
+ struct variable *v = dict_create_var (dict, name, fmt_var_width (input));
if (!v)
{
lex_ofs_error (lexer, name_ofs, name_ofs,
_("%s is a duplicate variable name."), name);
goto error;
}
- var_set_both_formats (v, &output);
+ var_set_both_formats (v, output);
if (type == DP_DELIMITED)
- data_parser_add_delimited_field (parser, &input,
+ data_parser_add_delimited_field (parser, input,
var_get_case_index (v),
name);
else
- data_parser_add_fixed_field (parser, &input, var_get_case_index (v),
+ data_parser_add_fixed_field (parser, input, var_get_case_index (v),
name, record, fc);
free (name);
name = NULL;
*tv = true;
var_set_measure (v, MEASURE_NOMINAL);
- var_set_both_formats (v, &(struct fmt_spec) { .type = FMT_F, .w = 4 });
+ var_set_both_formats (v, (struct fmt_spec) { .type = FMT_F, .w = 4 });
}
return true;
0);
var_set_measure (mf.svars[0], MEASURE_NOMINAL);
var_set_both_formats (
- mf.svars[0], &(struct fmt_spec) { .type = FMT_F, .w = 4 });
+ mf.svars[0], (struct fmt_spec) { .type = FMT_F, .w = 4 });
mf.n_svars = 1;
lex_get (lexer);
}
{
struct variable *v = input_vars[i];
mf.cvars[mf.n_cvars++] = v;
- var_set_both_formats (v, &(struct fmt_spec) { .type = FMT_F, .w = 10,
- .d = 4 });
+ var_set_both_formats (v, (struct fmt_spec) { .type = FMT_F, .w = 10,
+ .d = 4 });
}
if (!mf.n_cvars)
{
format_fits (struct fmt_spec format, double x)
{
char *s = data_out (&(union value) { .f = x }, NULL,
- &format, settings_get_fmt_settings ());
+ format, settings_get_fmt_settings ());
bool fits = *s != '*' && !strchr (s, 'E');
free (s);
return fits;
double f = gsl_matrix_get (m, y, x);
char *s = (numeric
? data_out (&(union value) { .f = f / scale}, NULL,
- &format, settings_get_fmt_settings ())
+ format, settings_get_fmt_settings ())
: trimmed_string (f));
ds_put_format (&line, " %s", s);
free (s);
write->format = xmalloc (sizeof *write->format);
*write->format = (struct fmt_spec) { .type = format, .w = w };
- char *error = fmt_check_output__ (write->format);
+ char *error = fmt_check_output__ (*write->format);
if (error)
{
msg (SE, "%s", error);
}
}
- if (write->format && fmt_var_width (write->format) > sizeof (double))
+ if (write->format && fmt_var_width (*write->format) > sizeof (double))
{
char fs[FMT_STRING_LEN_MAX + 1];
- fmt_to_string (write->format, fs);
+ fmt_to_string (*write->format, fs);
lex_ofs_error (s->lexer, format_ofs, format_ofs,
_("Format %s is too wide for %zu-byte matrix elements."),
fs, sizeof (double));
v.f = f;
else
v.s = (uint8_t *) &f;
- s = data_out (&v, NULL, write->format, settings);
+ s = data_out (&v, NULL, *write->format, settings);
}
else
{
if (NULL == cell_spec[stat].rc)
{
const struct variable *dv = mt->dep_vars[v];
- pv->numeric.format = * var_get_print_format (dv);
+ pv->numeric.format = var_get_print_format (dv);
}
pivot_table_put (pt, indexes, pt->n_dimensions, pv);
}
struct pivot_value *value
= pivot_value_new_number (entries[i]);
if (i == 1)
- value->numeric.format = *var_get_print_format (rs->var);
+ value->numeric.format = var_get_print_format (rs->var);
pivot_table_put2 (table, i, var_idx, value);
}
}
{
while (!lex_match (lexer, T_RPAREN))
{
- enum fmt_type type = var_get_print_format (v[0])->type;
+ enum fmt_type type = var_get_print_format (v[0]).type;
double x, y;
if (!parse_num_range (lexer, &x, &y, &type))
pivot_table_put2 (table, 2, row,
pivot_value_new_value (
&mrset->counted, mrset->width,
- &F_8_0, dict_get_encoding (dict)));
+ F_8_0, dict_get_encoding (dict)));
/* Variable names. */
struct string var_names = DS_EMPTY_INITIALIZER;
if (!parse_format_specifier (lexer, &f))
goto done;
- char *error = fmt_check_output__ (&f);
+ char *error = fmt_check_output__ (f);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
char str[FMT_STRING_LEN_MAX + 1];
lex_next_error (lexer, -1, -1,
_("Format type %s may not be used with a numeric "
- "variable."), fmt_to_string (&f, str));
+ "variable."), fmt_to_string (f, str));
goto done;
}
lex_ofs_error (lexer, vars_start, vars_end,
_("There is already a variable named %s."), v[i]);
else
- var_set_both_formats (new_var, &f);
+ var_set_both_formats (new_var, f);
}
ok = true;
|| !parse_format_specifier (lexer, &f))
goto done;
- char *error = fmt_check_type_compat__ (&f, NULL, VAL_STRING);
+ char *error = fmt_check_type_compat__ (f, NULL, VAL_STRING);
if (!error)
- error = fmt_check_output__ (&f);
+ error = fmt_check_output__ (f);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
goto done;
/* Create each variable. */
- int width = fmt_var_width (&f);
+ int width = fmt_var_width (f);
for (size_t i = 0; i < nv; i++)
{
struct variable *new_var = dict_create_var (dataset_dict (ds), v[i],
lex_ofs_error (lexer, vars_start, vars_end,
_("There is already a variable named %s."), v[i]);
else
- var_set_both_formats (new_var, &f);
+ var_set_both_formats (new_var, f);
}
ok = true;
goto error;
if (width <= 0)
- {
- const struct fmt_spec *dflt = settings_get_format ();
- width = dflt->w;
- }
+ width = settings_get_format ().w;
if (!fmt_from_name (type, &fmt.type))
{
const struct string_set_node *node;
const char *s;
STRING_SET_FOR_EACH (s, node, &rc_names)
- if (!pivot_result_class_change (s, &fmt))
+ if (!pivot_result_class_change (s, fmt))
lex_error (lexer, _("Unknown cell class %s."), s);
}
}
int end_ofs = lex_ofs (lexer) - 1;
struct fmt_spec format = { .type = type, .w = w, .d = d };
- char *error = fmt_check__ (&format, use);
+ char *error = fmt_check__ (format, use);
if (error)
{
lex_ofs_error (lexer, start_ofs, end_ofs, "%s", error);
_("Unknown format type `%s'."), type);
return false;
}
- char *error = fmt_check__ (&f, use);
+ char *error = fmt_check__ (f, use);
if (error)
{
lex_ofs_error (lexer, ofs, ofs, "%s", error);
as appropriate, and returns true. Otherwise, returns false
without any side effects. */
bool
-execute_placement_format (const struct fmt_spec *format,
+execute_placement_format (const struct fmt_spec format,
int *record, int *column)
{
- switch ((int) format->type)
+ switch ((int) format.type)
{
case PRS_TYPE_X:
- *column += format->w;
+ *column += format.w;
return true;
case PRS_TYPE_T:
- *column = format->w;
+ *column = format.w;
return true;
case PRS_TYPE_NEW_REC:
return true;
default:
- assert (format->type < FMT_NUMBER_OF_FORMATS);
+ assert (format.type < FMT_NUMBER_OF_FORMATS);
return false;
}
}
bool parse_var_placements (struct lexer *, struct pool *, size_t n_vars,
enum fmt_use,
struct fmt_spec **, size_t *n_formats);
-bool execute_placement_format (const struct fmt_spec *,
- int *record, int *column);
+bool execute_placement_format (struct fmt_spec, int *record, int *column);
bool parse_column (struct lexer *lexer, int base, int *column);
bool parse_column_range (struct lexer *, int base,
int *first_column, int *last_column,
{
const struct variable *v = vars[i];
formats[i] = (which_formats == PRINT
- ? *var_get_print_format (v)
- : *var_get_write_format (v));
+ ? var_get_print_format (v)
+ : var_get_write_format (v));
}
add_space = which_formats == PRINT;
}
size_t var_idx = 0;
for (f = formats; f < &formats[n_formats]; f++)
- if (!execute_placement_format (f, record, column))
+ if (!execute_placement_format (*f, record, column))
{
const struct variable *var = vars[var_idx++];
- char *error = fmt_check_width_compat__ (f, var_get_name (var),
+ char *error = fmt_check_width_compat__ (*f, var_get_name (var),
var_get_width (var));
if (error)
{
char fmt_string[FMT_STRING_LEN_MAX + 1];
pivot_table_put2 (table, 2, row, pivot_value_new_user_text (
- fmt_to_string (&spec->format, fmt_string), -1));
+ fmt_to_string (spec->format, fmt_string), -1));
}
int row = pivot_category_create_leaf (
char *s;
s = data_out (input, var_get_encoding (spec->var),
- &spec->format, settings_get_fmt_settings ());
+ 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, settings_get_fmt_settings (),
+ spec->format, settings_get_fmt_settings (),
&line, trns->encoding);
else
ds_put_byte_multiple (&line, encoded_space, spec->format.w);
struct variable *var;
var = dict_create_var_assert (d, rs->dest_names[i], 0);
- var_set_both_formats (var, &dest_format[rs->rfunc]);
+ var_set_both_formats (var, dest_format[rs->rfunc]);
var_set_label (var, rs->dest_labels[i]);
var_set_measure (var, rank_measures[rs->rfunc]);
if (!parse_format_specifier (lexer, &fmt))
return false;
- char *error = fmt_check_output__ (&fmt);
+ char *error = fmt_check_output__ (fmt);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
lex_ofs_error (lexer, start, end,
_("%s requires numeric output format as an argument. "
"Specified format %s is of type string."),
- "FORMAT", fmt_to_string (&fmt, str));
+ "FORMAT", fmt_to_string (fmt, str));
return false;
}
- settings_set_format (&fmt);
+ settings_set_format (fmt);
return true;
}
}
static int
-compare_formats (const struct fmt_spec *a, const struct fmt_spec *b)
+compare_formats (struct fmt_spec a, struct fmt_spec b)
{
- int retval = compare_ints (fmt_to_io (a->type), fmt_to_io (b->type));
+ int retval = compare_ints (fmt_to_io (a.type), fmt_to_io (b.type));
if (!retval)
- retval = compare_ints (a->w, b->w);
+ retval = compare_ints (a.w, b.w);
if (!retval)
- retval = compare_ints (a->d, b->d);
+ retval = compare_ints (a.d, b.d);
return retval;
}
if (flags & DF_PRINT_FORMAT)
{
- const struct fmt_spec *print = var_get_print_format (v);
+ struct fmt_spec print = var_get_print_format (v);
char s[FMT_STRING_LEN_MAX + 1];
pivot_table_put2 (
if (flags & DF_WRITE_FORMAT)
{
- const struct fmt_spec *write = var_get_write_format (v);
+ struct fmt_spec write = var_get_write_format (v);
char s[FMT_STRING_LEN_MAX + 1];
pivot_table_put2 (
seen_format = true;
if (!parse_format_specifier (lexer, &format))
goto error;
- char *error = fmt_check_output__ (&format);
+ char *error = fmt_check_output__ (format);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
{
char *name = xasprintf ("%s%zu", vectors[i], j + 1);
vars[j] = dict_create_var_assert (dict, name,
- fmt_var_width (&format));
- var_set_both_formats (vars[j], &format);
+ fmt_var_width (format));
+ var_set_both_formats (vars[j], format);
free (name);
}
dict_create_vector_assert (dict, vectors[i], vars, n_vars);
lex_match (lexer, T_EQUALS);
if (!parse_format_specifier (lexer, &format))
goto done;
- char *error = fmt_check_output__ (&format);
+ char *error = fmt_check_output__ (format);
if (!error)
- error = fmt_check_type_compat__ (&format, NULL, VAL_NUMERIC);
+ error = fmt_check_type_compat__ (format, NULL, VAL_NUMERIC);
if (error)
{
lex_next_error (lexer, -1, -1, "%s", error);
if (has_format)
{
char *output = data_out (&(const union value) { .f = d },
- NULL, &format,
+ NULL, format,
settings_get_fmt_settings ());
output_log ("%s => %s", title, output);
free (output);
# Format types.
Type.new_atom('format'),
- Type.new_leaf('ni_format', 'const struct fmt_spec *',
+ Type.new_leaf('ni_format', 'struct fmt_spec',
'format', 'f', 'num_input_format'),
- Type.new_leaf('no_format', 'const struct fmt_spec *',
+ Type.new_leaf('no_format', 'struct fmt_spec',
'format', 'f', 'num_output_format'),
# Integer types.
expression e;
expr_node n;
{
- if (s.length > f->w)
- s.length = f->w;
+ if (s.length > f.w)
+ s.length = f.w;
union value out;
- char *error = data_in (s, C_ENCODING, f->type, settings_get_fmt_settings (),
+ char *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,
+ data_in_imply_decimals (s, C_ENCODING, f.type, f.d,
settings_get_fmt_settings (), &out);
else
{
msg_at (SE, expr_location (e, n->args[0]),
_("Cannot parse \"%.*s\" as format %s: %s"),
- (int) s.length, s.string, fmt_name (f->type), error);
+ (int) s.length, s.string, fmt_name (f.type), error);
free (error);
}
return out.f;
v.f = x;
- assert (!fmt_is_string (f->type));
+ assert (!fmt_is_string (f.type));
s = data_out (&v, C_ENCODING, f, settings_get_fmt_settings ());
dst = alloc_string (e, strlen (s));
strcpy (dst.string, s);
return s;
}
-static const struct fmt_spec *
+static struct fmt_spec
get_format_arg (struct expr_node *n, size_t arg_idx)
{
assert (arg_idx < n->n_args);
assert (n->args[arg_idx]->type == OP_ni_format
|| n->args[arg_idx]->type == OP_no_format);
- return &n->args[arg_idx]->format;
+ return n->args[arg_idx]->format;
}
static const struct expr_node *
}
static void
-emit_format (struct expression *e, const struct fmt_spec *f)
+emit_format (struct expression *e, struct fmt_spec f)
{
- allocate_aux (e, OP_format)->format = pool_clone (e->expr_pool,
- f, sizeof *f);
+ allocate_aux (e, OP_format)->format = f;
}
static void
case OP_ni_format:
case OP_no_format:
- emit_format (e, &arg->format);
+ emit_format (e, arg->format);
break;
case OP_pos_int:
case OP_ni_format:
if (arg->type == OP_format
- && fmt_check_input (&arg->format)
- && fmt_check_type_compat (&arg->format, VAL_NUMERIC))
+ && fmt_check_input (arg->format)
+ && fmt_check_type_compat (arg->format, VAL_NUMERIC))
{
if (do_coercion)
arg->type = OP_ni_format;
case OP_no_format:
if (arg->type == OP_format
- && fmt_check_output (&arg->format)
- && fmt_check_type_compat (&arg->format, VAL_NUMERIC))
+ && fmt_check_output (arg->format)
+ && fmt_check_type_compat (arg->format, VAL_NUMERIC))
{
if (do_coercion)
arg->type = OP_no_format;
msg_enable ();
if (ok)
- return expr_allocate_format (e, &fmt);
+ return expr_allocate_format (e, fmt);
/* All attempts failed. */
lex_error (lexer, _("Unknown identifier %s."), lex_tokcstr (lexer));
if ((expected == OP_ni_format || expected == OP_no_format)
&& actual == OP_format)
{
- const struct fmt_spec *f = &node->args[i]->format;
+ struct fmt_spec f = node->args[i]->format;
char *error = fmt_check__ (f, (ops->args[i] == OP_ni_format
? FMT_FOR_INPUT : FMT_FOR_OUTPUT));
if (!error)
}
struct expr_node *
-expr_allocate_format (struct expression *e, const struct fmt_spec *format)
+expr_allocate_format (struct expression *e, struct fmt_spec format)
{
struct expr_node *n = pool_alloc (e->expr_pool, sizeof *n);
- *n = (struct expr_node) { .type = OP_format, .format = *format };
+ *n = (struct expr_node) { .type = OP_format, .format = format };
return n;
}
struct substring string;
const struct variable *variable;
const struct vector *vector;
- struct fmt_spec *format;
+ struct fmt_spec format;
const struct expr_node *expr_node;
int integer;
};
struct expr_node *expr_allocate_string (struct expression *e, struct substring);
struct expr_node *expr_allocate_variable (struct expression *e,
const struct variable *);
-struct expr_node *expr_allocate_format (struct expression *e,
- const struct fmt_spec *);
+struct expr_node *expr_allocate_format (struct expression *, struct fmt_spec);
struct expr_node *expr_allocate_expr_node (struct expression *,
const struct expr_node *);
struct expr_node *expr_allocate_vector (struct expression *e,
{
int width = var_get_width (var);
if (width == 0)
- return parse_number (lexer, &v->f, &var_get_print_format (var)->type);
+ {
+ struct fmt_spec format = var_get_print_format (var);
+ return parse_number (lexer, &v->f, &format.type);
+ }
else if (lex_force_string (lexer))
{
struct substring out;
int
cmd_debug_format_guesser (struct lexer *lexer, struct dataset *ds UNUSED)
{
- struct fmt_guesser *g;
- struct fmt_spec format;
- char format_string[FMT_STRING_LEN_MAX + 1];
-
- g = fmt_guesser_create ();
+ struct fmt_guesser *g = fmt_guesser_create ();
while (lex_is_string (lexer))
{
fprintf (stderr, "\"%s\" ", lex_tokcstr (lexer));
lex_get (lexer);
}
- fmt_guesser_guess (g, &format);
- fmt_to_string (&format, format_string);
+ struct fmt_spec format = fmt_guesser_guess (g);
+ char format_string[FMT_STRING_LEN_MAX + 1];
+ fmt_to_string (format, format_string);
fprintf (stderr, "=> %s", format_string);
- if (!fmt_check_input (&format))
+ if (!fmt_check_input (format))
{
fmt_fix_input (&format);
- fmt_to_string (&format, format_string);
+ fmt_to_string (format, format_string);
fprintf (stderr, " (%s)", format_string);
}
putc ('\n', stderr);
{
if (!strcmp (s, PIVOT_RC_OTHER))
{
- *format = *settings_get_format ();
+ *format = settings_get_format ();
*honor_small = true;
}
else if (!strcmp (s, PIVOT_RC_COUNT) && !overridden_count_format)
include the RC_ prefix) to *FORMAT. Returns true if successful, false if S
does not name a known result class. */
bool
-pivot_result_class_change (const char *s_, const struct fmt_spec *format)
+pivot_result_class_change (const char *s_, struct fmt_spec format)
{
char *s = xasprintf ("RC_%s", s_);
struct result_class *rc = pivot_result_class_find (s);
if (rc)
{
- rc->format = *format;
+ rc->format = format;
if (!strcmp (s, PIVOT_RC_COUNT))
overridden_count_format = true;
}
const struct variable *wv)
{
if (wv)
- pivot_table_set_weight_format (table, *var_get_print_format (wv));
+ pivot_table_set_weight_format (table, var_get_print_format (wv));
}
/* Sets the format used for PIVOT_RC_COUNT cells to WFMT, which should be the
}
}
}
- value->numeric.format = *settings_get_format ();
+ value->numeric.format = settings_get_format ();
value->numeric.honor_small = true;
done:;
value->numeric.value_label != NULL);
if (show & SETTINGS_VALUE_SHOW_VALUE)
{
- const struct fmt_spec *f = &value->numeric.format;
- const struct fmt_spec *format
- = (f->type == FMT_F
+ struct fmt_spec f = value->numeric.format;
+ const struct fmt_spec format
+ = (f.type == FMT_F
&& value->numeric.honor_small
&& value->numeric.x != 0
&& fabs (value->numeric.x) < pt->small
- ? &(struct fmt_spec) { .type = FMT_E, .w = 40, .d = f->d }
+ ? (struct fmt_spec) { .type = FMT_E, .w = 40, .d = f.d }
: f);
char *s = data_out (&(union value) { .f = value->numeric.x },
encoding. */
struct pivot_value *
pivot_value_new_value (const union value *value, int width,
- const struct fmt_spec *format, const char *encoding)
+ struct fmt_spec format, const char *encoding)
{
struct pivot_value *pv = XZALLOC (struct pivot_value);
if (width > 0)
pv->type = PIVOT_VALUE_STRING;
pv->string.s = s;
- pv->string.hex = format->type == FMT_AHEX;
+ pv->string.hex = format.type == FMT_AHEX;
}
else
{
pv->type = PIVOT_VALUE_NUMERIC;
pv->numeric.x = value->f;
- pv->numeric.format = *format;
+ pv->numeric.format = format;
}
return pv;
#define PIVOT_RC_RESIDUAL ("RC_RESIDUAL")
#define PIVOT_RC_COUNT ("RC_COUNT")
-bool pivot_result_class_change (const char *, const struct fmt_spec *);
+bool pivot_result_class_change (const char *, struct fmt_spec);
bool is_pivot_result_class (const char *);
\f
/* Styling for a pivot table.
struct pivot_value *pivot_value_new_var_value (
const struct variable *, const union value *);
struct pivot_value *pivot_value_new_value (const union value *, int width,
- const struct fmt_spec *,
+ struct fmt_spec,
const char *encoding);
/* Values from variable names. */
else
{
union value v = { .f = mapping->to.d };
- mapping->to.s = data_out_stretchy (&v, NULL, format,
+ 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,
+ dest = data_out_stretchy (&v, "UTF-8", s->format,
settings_get_fmt_settings (), NULL);
}
else
}
static void
-put_format (struct buf *buf, const struct fmt_spec *f, bool honor_small)
+put_format (struct buf *buf, struct fmt_spec f, bool honor_small)
{
- int type = f->type == FMT_F && honor_small ? 40 : fmt_to_io (f->type);
- put_u32 (buf, (type << 16) | (f->w << 8) | f->d);
+ int type = f.type == FMT_F && honor_small ? 40 : fmt_to_io (f.type);
+ put_u32 (buf, (type << 16) | (f.w << 8) | f.d);
}
static int
{
put_byte (buf, 2);
put_value_mod (buf, value, NULL);
- put_format (buf, &value->numeric.format, value->numeric.honor_small);
+ put_format (buf, value->numeric.format, value->numeric.honor_small);
put_double (buf, value->numeric.x);
put_string (buf, value->numeric.var_name);
put_string (buf, value->numeric.value_label);
{
put_byte (buf, 1);
put_value_mod (buf, value, NULL);
- put_format (buf, &value->numeric.format, value->numeric.honor_small);
+ put_format (buf, value->numeric.format, value->numeric.honor_small);
put_double (buf, value->numeric.x);
}
break;
put_value_mod (buf, value, NULL);
size_t len = strlen (value->string.s);
if (value->string.hex)
- put_format (buf, &(struct fmt_spec) { .type = FMT_AHEX, .w = len * 2 },
+ put_format (buf, (struct fmt_spec) { .type = FMT_AHEX, .w = len * 2 },
false);
else
- put_format (buf, &(struct fmt_spec) { .type = FMT_A, .w = len }, false);
+ put_format (buf, (struct fmt_spec) { .type = FMT_A, .w = len }, false);
put_string (buf, value->string.value_label);
put_string (buf, value->string.var_name);
put_show_values (buf, value->string.show);
if (ok)
{
fmt_fix_output (out);
- ok = fmt_check_width_compat (out, 0);
+ ok = fmt_check_width_compat (*out, 0);
}
if (!ok)
const union value *v)
{
const struct numeric_comparator *nc = (const struct numeric_comparator *) cmptr;
- const struct fmt_spec *fs = var_get_print_format (cmptr->var);
+ struct fmt_spec fs = var_get_print_format (cmptr->var);
- double c = nearbyint (v->f * int_pow10 (fs->d));
+ double c = nearbyint (v->f * int_pow10 (fs.d));
return c == nc->rounded_ref;
}
cmptr->flags = 0;
cmptr->var = var;
cmptr->compare = value_compare;
- const struct fmt_spec *fs = var_get_write_format (var);
+ struct fmt_spec fs = var_get_write_format (var);
union value val;
text_to_value (target, var, &val);
- nc->rounded_ref = nearbyint (val.f * int_pow10 (fs->d));
+ nc->rounded_ref = nearbyint (val.f * int_pow10 (fs.d));
value_destroy (&val, var_get_width (var));
return cmptr;
Returns an allocated string. The returned string must be freed when no
longer required. */
gchar *
-value_to_text__ (union value v,
- const struct fmt_spec *format, const char *encoding)
+value_to_text__ (union value v, struct fmt_spec format, const char *encoding)
{
gchar *s;
s = data_out_stretchy (&v, encoding, format, settings_get_fmt_settings (),
NULL);
- if (fmt_is_numeric (format->type))
+ if (fmt_is_numeric (format.type))
g_strchug (s);
else
g_strchomp (s);
*/
union value *
text_to_value__ (const gchar *text,
- const struct fmt_spec *format,
+ struct fmt_spec format,
const gchar *encoding,
union value *val)
{
int width = fmt_var_width (format);
- if (format->type != FMT_A)
+ if (format.type != FMT_A)
{
if (! text) return NULL;
}
value_init (val, width);
- char *err = data_in (ss_cstr (text), UTF8, format->type,
+ char *err = data_in (ss_cstr (text), UTF8, format.type,
settings_get_fmt_settings (), val, width, encoding);
if (err)
}
gchar * value_to_text (union value v, const struct variable *);
-gchar * value_to_text__ (union value v, const struct fmt_spec *,
- const char *encoding);
+gchar * value_to_text__ (union value v, struct fmt_spec, const char *encoding);
union value *text_to_value (const gchar *text, const struct variable *,
union value *);
-union value *text_to_value__ (const gchar *text, const struct fmt_spec *,
+union value *text_to_value__ (const gchar *text, struct fmt_spec,
const gchar *encoding, union value *);
/* Create a deep copy of SRC */
static gboolean
try_missing_value(const PsppireMissingValDialog *dialog, const gchar *text, union value *vp)
{
- const int var_width = fmt_var_width (&dialog->format);
+ const int var_width = fmt_var_width (dialog->format);
char *error_txt = NULL;
value_init(vp, var_width);
missing_val_dialog_acceptable (gpointer data)
{
PsppireMissingValDialog *dialog = data;
- int var_width = fmt_var_width (&dialog->format);
+ int var_width = fmt_var_width (dialog->format);
if (gtk_toggle_button_get_active (dialog->button_discrete))
{
else
mv_copy (&dialog->mvl, vmv);
dialog->encoding = g_strdup (var_get_encoding (var));
- dialog->format = *var_get_print_format (var);
+ dialog->format = var_get_print_format (var);
}
else
{
gtk_widget_set_sensitive (dialog->high, FALSE);
gtk_widget_set_sensitive (dialog->discrete, FALSE);
- var_type = val_type_from_width (fmt_var_width (&dialog->format));
+ var_type = val_type_from_width (fmt_var_width (dialog->format));
gtk_widget_set_sensitive (GTK_WIDGET (dialog->button_range),
var_type == VAL_NUMERIC);
mv_get_range (&dialog->mvl, &low.f, &high.f);
- low_text = value_to_text__ (low, &dialog->format, dialog->encoding);
- high_text = value_to_text__ (high, &dialog->format, dialog->encoding);
+ low_text = value_to_text__ (low, dialog->format, dialog->encoding);
+ high_text = value_to_text__ (high, dialog->format, dialog->encoding);
gtk_entry_set_text (GTK_ENTRY (dialog->low), low_text);
gtk_entry_set_text (GTK_ENTRY (dialog->high), high_text);
{
gchar *text;
text = value_to_text__ (*mv_get_value (&dialog->mvl, 0),
- &dialog->format, dialog->encoding);
+ dialog->format, dialog->encoding);
gtk_entry_set_text (GTK_ENTRY (dialog->discrete), text);
g_free (text);
}
gchar *text ;
text = value_to_text__ (*mv_get_value (&dialog->mvl, i),
- &dialog->format, dialog->encoding);
+ dialog->format, dialog->encoding);
gtk_entry_set_text (GTK_ENTRY (dialog->mv[i]), text);
g_free (text);
}
static gboolean psppire_data_store_data_in (PsppireDataStore *ds,
casenumber casenum, gint idx,
struct substring input,
- const struct fmt_spec *fmt);
+ struct fmt_spec);
static GObjectClass *parent_class = NULL;
const struct variable *variable = psppire_dict_get_variable (store->dict, col);
g_return_val_if_fail (variable, FALSE);
- const struct fmt_spec *fmt = var_get_print_format (variable);
+ struct fmt_spec fmt = var_get_print_format (variable);
int width = var_get_width (variable);
if (vp == NULL)
{
xx = data_in (ss_cstr (in), psppire_dict_encoding (store->dict),
- fmt->type, settings_get_fmt_settings (),
+ fmt.type, settings_get_fmt_settings (),
&val, width, "UTF-8");
}
var_is_value_missing (variable, val) == MV_SYSTEM)
return g_strdup ("");
- const struct fmt_spec *fmt = var_get_print_format (variable);
+ struct fmt_spec fmt = var_get_print_format (variable);
return value_to_text__ (*val, fmt, psppire_dict_encoding (store->dict));
}
const struct resize_datum_aux *aux = aux_;
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);
+ struct fmt_spec newfmt = var_get_print_format (aux->new_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
+ enum fmt_type type = (fmt_usable_for_input (newfmt.type)
+ ? newfmt.type
: FMT_DOLLAR);
free (data_in (ss_cstr (s), enc, type, settings_get_fmt_settings (),
new, new_width, enc));
/* Set the IDXth value of case C using D_IN */
static gboolean
psppire_data_store_data_in (PsppireDataStore *ds, casenumber casenum, gint idx,
- struct substring input, const struct fmt_spec *fmt)
+ struct substring input, struct fmt_spec fmt)
{
union value value;
int width;
FALSE);
value_init (&value, width);
ok = (datasheet_get_value (ds->datasheet, casenum, idx, &value)
- && data_in_msg (input, UTF8, fmt->type, settings_get_fmt_settings (),
+ && 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);
struct string strx;
ds_init_empty (&strx);
- syntax_gen_value (&strx, val, var_get_width (act->grp_var),
- var_get_print_format (act->grp_var));
+ struct fmt_spec f = var_get_print_format (act->grp_var);
+ syntax_gen_value (&strx, val, var_get_width (act->grp_var), &f);
g_string_append (str, ds_cstr (&strx));
ds_destroy (&strx);
struct string strx;
ds_init_empty (&strx);
+ struct fmt_spec f = var_get_print_format (act->grp_var);
syntax_gen_value (&strx, &act->grp_val[1], var_get_width (act->grp_var),
- var_get_print_format (act->grp_var));
+ &f);
g_string_append (str, ds_cstr (&strx));
ds_destroy (&strx);
struct string str;
ds_init_empty (&str);
- syntax_gen_value (&str, &val, var_get_width (var),
- var_get_print_format (var));
+ struct fmt_spec f = var_get_print_format (var);
+ syntax_gen_value (&str, &val, var_get_width (var), &f);
g_string_append (string, ds_cstr (&str));
ds_destroy (&str);
return path;
}
-const struct fmt_spec *var_get_write_format (const struct variable *);
+struct fmt_spec var_get_write_format (const struct variable *);
static void
tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter,
var = iter->user_data;
- const struct fmt_spec *fs = var_get_write_format (var);
+ struct fmt_spec fs = var_get_write_format (var);
switch (column)
{
break;
case DICT_TVM_COL_WIDTH:
g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, fs->w);
+ g_value_set_int (value, fs.w);
break;
case DICT_TVM_COL_DECIMAL:
g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, fs->d);
+ g_value_set_int (value, fs.d);
break;
case DICT_TVM_COL_LABEL:
g_value_init (value, G_TYPE_STRING);
g_object_set (cell,
"stock-size", GTK_ICON_SIZE_MENU,
- "icon-name", get_var_measurement_stock_id (var_get_print_format (var)->type,
+ "icon-name", get_var_measurement_stock_id (var_get_print_format (var).type,
var_get_measure (var)),
NULL);
caseproto. See bug #58298 */
char *xx = data_in (ss_cstr (ss),
"UTF-8",
- var_get_write_format (var)->type,
+ var_get_write_format (var).type,
settings_get_fmt_settings (),
v, var_get_width (var), "UTF-8");
struct caseproto *proto = caseproto_create ();
for (i = 0 ; i < n_vars; ++i)
{
- struct fmt_spec fs;
- fmt_guesser_guess (fg[i], &fs);
+ struct fmt_spec fs = fmt_guesser_guess (fg[i]);
fmt_fix (&fs, FMT_FOR_INPUT);
struct variable *var = dict_get_var (ia->dict, i);
- int width = fmt_var_width (&fs);
+ int width = fmt_var_width (fs);
var_set_width_and_formats (var, width,
&fs, &fs);
enum measure measure = var_get_measure (var);
enum var_role role = var_get_role (var);
enum alignment alignment = var_get_alignment (var);
- const struct fmt_spec *format = var_get_print_format (var);
+ struct fmt_spec format = var_get_print_format (var);
if (var_has_missing_values (var))
{
{
if (j)
ds_put_cstr (s, ", ");
- syntax_gen_value (s, mv_get_value (mv, j), width, format);
+ syntax_gen_value (s, mv_get_value (mv, j), width, &format);
}
if (mv_has_range (mv))
if (mv_has_value (mv))
ds_put_cstr (s, ", ");
mv_get_range (mv, &low, &high);
- syntax_gen_num_range (s, low, high, format);
+ syntax_gen_num_range (s, low, high, &format);
}
ds_put_cstr (s, ").\n");
}
{
const struct val_lab *vl = labels[j];
ds_put_cstr (s, "\n ");
- syntax_gen_value (s, &vl->value, width, format);
+ syntax_gen_value (s, &vl->value, width, &format);
ds_put_byte (s, ' ');
syntax_gen_string (s, ss_cstr (val_lab_get_escaped_label (vl)));
}
break;
case PROP_FORMAT:
- psppire_value_entry_set_format (obj, g_value_get_boxed (value));
+ {
+ const struct fmt_spec *f = g_value_get_boxed (value);
+ psppire_value_entry_set_format (obj, *f);
+ }
break;
case PROP_ENCODING:
if (var != NULL)
{
psppire_value_entry_set_value_labels (obj, var_get_value_labels (var));
- obj->format = *var_get_print_format (var);
+ obj->format = var_get_print_format (var);
psppire_value_entry_set_encoding (obj, var_get_encoding (var));
}
else
if (val_labs != NULL)
{
int width = val_labs_get_width (val_labs);
- if (width != fmt_var_width (&obj->format))
+ if (width != fmt_var_width (obj->format))
obj->format = fmt_default_for_width (width);
}
void
psppire_value_entry_set_format (PsppireValueEntry *obj,
- const struct fmt_spec *format)
+ struct fmt_spec format)
{
- if (!fmt_equal (format, &obj->format))
+ if (!fmt_equal (format, obj->format))
{
obj->cur_value = NULL;
- obj->format = *format;
+ obj->format = format;
if (obj->val_labs
&& val_labs_get_width (obj->val_labs) != fmt_var_width (format))
}
}
-const struct fmt_spec *
+struct fmt_spec
psppire_value_entry_get_format (const PsppireValueEntry *obj)
{
- return &obj->format;
+ return obj->format;
}
void
void
psppire_value_entry_set_width (PsppireValueEntry *obj, int width)
{
- if (width != fmt_var_width (&obj->format))
+ if (width != fmt_var_width (obj->format))
{
struct fmt_spec format = fmt_default_for_width (width);
- psppire_value_entry_set_format (obj, &format);
+ psppire_value_entry_set_format (obj, format);
}
}
int
psppire_value_entry_get_width (const PsppireValueEntry *obj)
{
- return fmt_var_width (&obj->format);
+ return fmt_var_width (obj->format);
}
void
}
}
- string = value_to_text__ (*value, &obj->format, obj->encoding);
+ string = value_to_text__ (*value, obj->format, obj->encoding);
gtk_entry_set_text (entry, string);
g_free (string);
}
GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (obj)));
GtkTreeIter iter;
- g_return_val_if_fail (fmt_var_width (&obj->format) == width, FALSE);
+ g_return_val_if_fail (fmt_var_width (obj->format) == width, FALSE);
if (obj->cur_value)
{
const struct val_labs *
psppire_value_entry_get_value_labels (const PsppireValueEntry *);
-void psppire_value_entry_set_format (PsppireValueEntry *,
- const struct fmt_spec *);
-const struct fmt_spec *
-psppire_value_entry_get_format (const PsppireValueEntry *);
+void psppire_value_entry_set_format (PsppireValueEntry *, struct fmt_spec);
+struct fmt_spec psppire_value_entry_get_format (const PsppireValueEntry *);
void psppire_value_entry_set_encoding (PsppireValueEntry *, const gchar *);
const gchar *psppire_value_entry_get_encoding (const PsppireValueEntry *);
gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_ALIGNMENT]),
alignment_to_string (var_get_alignment (var)));
- const struct fmt_spec *pf = var_get_print_format (var);
+ struct fmt_spec pf = var_get_print_format (var);
char xx[FMT_STRING_LEN_MAX + 1];
gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_PRINT_FORMAT]),
fmt_to_string (pf, xx));
- const struct fmt_spec *wf = var_get_write_format (var);
+ struct fmt_spec wf = var_get_write_format (var);
gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_WRITE_FORMAT]),
fmt_to_string (wf, xx));
if (var == NULL)
return;
- const struct fmt_spec *format = var_get_write_format (var);
- struct fmt_spec fmt = *format;
+ struct fmt_spec fmt = var_get_write_format (var);
GtkWindow *win = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sheet)));
if (GTK_RESPONSE_OK == psppire_var_type_dialog_run (win, &fmt))
- {
- var_set_width_and_formats (var, fmt_var_width (&fmt), &fmt, &fmt);
- }
+ var_set_width_and_formats (var, fmt_var_width (fmt), &fmt, &fmt);
}
static void
gint width = g_value_get_int (value);
if (var_is_numeric (var))
{
- struct fmt_spec format = *var_get_print_format (var);
+ struct fmt_spec format = var_get_print_format (var);
fmt_change_width (&format, width, FMT_FOR_OUTPUT);
- var_set_both_formats (var, &format);
+ var_set_both_formats (var, format);
}
else
{
gint decimals = g_value_get_int (value);
if (decimals >= 0)
{
- struct fmt_spec format = *var_get_print_format (var);
+ struct fmt_spec format = var_get_print_format (var);
fmt_change_decimals (&format, decimals, FMT_FOR_OUTPUT);
- var_set_both_formats (var, &format);
+ var_set_both_formats (var, format);
}
}
break;
if (col == DICT_TVM_COL_TYPE)
{
- const struct fmt_spec *print = var_get_print_format (var);
- return strdup (fmt_gui_name (print->type));
+ struct fmt_spec print = var_get_print_format (var);
+ return strdup (fmt_gui_name (print.type));
}
else if (col == DICT_TVM_COL_MISSING_VALUES)
return missing_values_to_string (var, NULL);
text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
- text_to_value__ (text, &dialog->format, dialog->encoding, &v);
+ text_to_value__ (text, dialog->format, dialog->encoding, &v);
if (val_labs_find (dialog->labs, &v))
{
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
union value v;
- text_to_value__ (text, &dialog->format, dialog->encoding, &v);
+ text_to_value__ (text, dialog->format, dialog->encoding, &v);
g_signal_handler_block (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
union value v;
- if (text_to_value__ (val_text, &dialog->format, dialog->encoding, &v))
+ if (text_to_value__ (val_text, dialog->format, dialog->encoding, &v))
{
val_labs_replace (dialog->labs, &v,
gtk_entry_get_text (GTK_ENTRY (dialog->label_entry)));
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
- if (text_to_value__ (text, &dialog->format, dialog->encoding, &v))
+ if (text_to_value__ (text, dialog->format, dialog->encoding, &v))
{
if (val_labs_add (dialog->labs, &v,
gtk_entry_get_text
if (! get_selected_tuple (dialog, &value, &label))
return;
- text = value_to_text__ (value, &dialog->format, dialog->encoding);
+ text = value_to_text__ (value, dialog->format, dialog->encoding);
g_signal_handler_block (GTK_ENTRY (dialog->value_entry),
dialog->value_handler_id);
const struct val_lab *vl = labels[i];
gchar *const vstr =
- value_to_text__ (vl->value, &dialog->format, dialog->encoding);
+ value_to_text__ (vl->value, dialog->format, dialog->encoding);
gchar *const text = g_strdup_printf (_("%s = `%s'"), vstr,
val_lab_get_escaped_label (vl));
{
dialog->labs = val_labs_clone (var_get_value_labels (var));
dialog->encoding = g_strdup (var_get_encoding (var));
- dialog->format = *var_get_print_format (var);
+ dialog->format = var_get_print_format (var);
}
else
dialog->format = F_8_0;
static void psppire_var_type_dialog_set_state (PsppireVarTypeDialog *);
static void psppire_var_type_dialog_set_format (PsppireVarTypeDialog *dialog,
- const struct fmt_spec *format);
+ struct fmt_spec format);
-static int find_format (const struct fmt_spec *target,
+static int find_format (struct fmt_spec target,
const struct fmt_spec formats[], int n_formats);
static int find_format_type (int target, const int types[], int n_types);
switch (prop_id)
{
case PROP_FORMAT:
- psppire_var_type_dialog_set_format (obj, g_value_get_boxed (value));
+ {
+ const struct fmt_spec *f = g_value_get_boxed (value);
+ psppire_var_type_dialog_set_format (obj, *f);
+ }
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
static void
psppire_var_type_dialog_set_format (PsppireVarTypeDialog *dialog,
- const struct fmt_spec *format)
+ struct fmt_spec format)
{
- dialog->base_format = *format;
+ dialog->base_format = format;
psppire_var_type_dialog_set_state (dialog);
}
-static const struct fmt_spec *
+static struct fmt_spec
psppire_var_type_dialog_get_format (const PsppireVarTypeDialog *dialog)
{
- return &dialog->fmt_l;
+ return dialog->fmt_l;
}
static void
gint result = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
if (result == GTK_RESPONSE_OK)
- *format = *psppire_var_type_dialog_get_format (dialog);
+ *format = psppire_var_type_dialog_get_format (dialog);
gtk_widget_destroy (GTK_WIDGET (dialog));
dialog->fmt_l.type = FMT_A;
break;
case BUTTON_DATE:
- indx = find_format (&dialog->fmt_l, date_format,
+ indx = find_format (dialog->fmt_l, date_format,
sizeof date_format / sizeof *date_format);
select_treeview_at_index (dialog->date_format_treeview, indx);
dialog->fmt_l = date_format[indx];
break;
case BUTTON_DOLLAR:
- indx = find_format (&dialog->fmt_l, dollar_format,
+ indx = find_format (dialog->fmt_l, dollar_format,
sizeof dollar_format / sizeof *dollar_format);
select_treeview_at_index (dialog->dollar_treeview, indx);
dialog->fmt_l = dollar_format[indx];
text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_width));
dialog->fmt_l.w = atoi (text);
- if (! fmt_check_output (&dialog->fmt_l))
+ if (! fmt_check_output (dialog->fmt_l))
{
gtk_label_set_text (GTK_LABEL (dialog->label_psample), "---");
gtk_label_set_text (GTK_LABEL (dialog->label_nsample), "---");
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);
for (i = 0 ; i < sizeof (date_format) / sizeof (date_format[0]) ; ++i)
{
- const struct fmt_spec *f = &date_format[i];
+ struct fmt_spec f = date_format[i];
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
- 0, fmt_date_template (f->type, f->w),
+ 0, fmt_date_template (f.type, f.w),
-1);
}
for (i = 0 ; i < sizeof (dollar_format)/sizeof (dollar_format[0]) ; ++i)
{
- char *template = settings_dollar_template (&dollar_format[i]);
+ char *template = settings_dollar_template (dollar_format[i]);
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
0, template,
}
static int
-find_format (const struct fmt_spec *target,
+find_format (struct fmt_spec target,
const struct fmt_spec formats[], int n_formats)
{
int i;
for (i = 0; i < n_formats; i++)
- if (fmt_equal (target, &formats[i]))
+ if (fmt_equal (target, formats[i]))
return i;
return 0;
bool ok;
v_in.f = number;
- s = data_out (&v_in, "FIXME", format, settings_get_fmt_settings ());
+ 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,
syntax_gen_value (struct string *output, const union value *value, int width,
const struct fmt_spec *format)
{
- assert (format == NULL || fmt_var_width (format) == width);
+ assert (format == NULL || fmt_var_width (*format) == width);
if (width == 0)
syntax_gen_number (output, value->f, format);
else
if (ok)
{
- if (!fmt_check_output (&fmt)
- || !fmt_check_type_compat (&fmt, VAL_NUMERIC))
+ if (!fmt_check_output (fmt)
+ || !fmt_check_type_compat (fmt, VAL_NUMERIC))
exit (1);
value->numeric.format = fmt;