struct fmt_spec
fmt_for_input (enum fmt_type type, int w, int d)
{
- struct fmt_spec f;
- f.type = type;
- f.w = w;
- f.d = d;
+ struct fmt_spec f = { .type = type, .w = w, .d = d };
assert (fmt_check_input (&f));
return f;
}
struct fmt_spec
fmt_for_output (enum fmt_type type, int w, int d)
{
- struct fmt_spec f;
- f.type = type;
- f.w = w;
- f.d = d;
+ struct fmt_spec f = { .type = type, .w = w, .d = d };
assert (fmt_check_output (&f));
return f;
}
static void
fmt_clamp_decimals (struct fmt_spec *fmt, enum fmt_use use)
{
- int max_d;
-
- max_d = fmt_max_decimals (fmt->type, fmt->w, use);
- if (fmt->d < 0)
- fmt->d = 0;
- else if (fmt->d > max_d)
+ int max_d = fmt_max_decimals (fmt->type, fmt->w, use);
+ if (fmt->d > max_d)
fmt->d = max_d;
}
\f
};
/* Format type. */
-enum fmt_type
+enum ATTRIBUTE ((packed)) fmt_type
{
#define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) FMT_##NAME,
#include "format.def"
struct fmt_spec
{
enum fmt_type type; /* One of FMT_*. */
- int w; /* Width. */
- int d; /* Number of decimal places. */
+ uint16_t w; /* Width. */
+ uint8_t d; /* Number of decimal places. */
};
/* Maximum width of any numeric format. */
{
char fmt_type_name[FMT_TYPE_LEN_MAX + 1];
enum fmt_type fmt_type;
- int w, d;
+ uint16_t w;
+ uint8_t d;
if (!parse_column_range (lexer, 0, &fc, &lc, NULL))
goto error;
static bool
parse_abstract_format_specifier__ (struct lexer *lexer,
char type[FMT_TYPE_LEN_MAX + 1],
- int *width, int *decimals)
+ uint16_t *width, uint8_t *decimals)
{
struct substring s;
struct substring type_ss, width_ss, decimals_ss;
bool
parse_abstract_format_specifier (struct lexer *lexer,
char type[FMT_TYPE_LEN_MAX + 1],
- int *width, int *decimals)
+ uint16_t *width, uint8_t *decimals)
{
bool ok = parse_abstract_format_specifier__ (lexer, type, width, decimals);
if (ok)
struct lexer;
bool parse_abstract_format_specifier (struct lexer *, char *type,
- int *width, int *decimals);
+ uint16_t *width, uint8_t *decimals);
enum fmt_type ;
struct fmt_spec;
old_values->root, pivot_value_new_value (
&item->from, item->width,
(item->width
- ? &(struct fmt_spec) { FMT_F, item->width, 0 }
+ ? &(struct fmt_spec) { .type = FMT_F, .w = item->width }
: &spec->format),
dict_get_encoding (dict)));
pivot_table_put2 (table, 0, old_value_idx,
else if (lex_match_id (lexer, "FORMAT"))
{
char type[FMT_TYPE_LEN_MAX + 1];
- int width = -1;
- int decimals = -1;
+ uint16_t width;
+ uint8_t decimals;
if (! lex_force_match (lexer, T_EQUALS))
goto error;
table->ref_cnt = 1;
table->show_title = true;
table->show_caption = true;
- table->weight_format = (struct fmt_spec) { FMT_F, 40, 0 };
+ table->weight_format = (struct fmt_spec) { .type = FMT_F, .w = 40 };
table->title = title;
table->subtype = subtype ? pivot_value_new_text (subtype) : NULL;
table->command_c = xstrdup_if_nonempty (output_get_command_name ());
pivot_value_new_integer (double x)
{
struct pivot_value *value = pivot_value_new_number (x);
- value->numeric.format = (struct fmt_spec) { FMT_F, 40, 0 };
+ value->numeric.format = (struct fmt_spec) { .type = FMT_F, .w = 40 };
return value;
}
vme->from);
char *error = spv_map_insert (map, from, vme->to, true,
- &(struct fmt_spec) { FMT_A, 40, 0 });
+ &(struct fmt_spec) { .type = FMT_A, .w = 40 });
if (error)
return error;
if (d < 0 || d > 15)
d = 2;
- struct fmt_spec f = (struct fmt_spec) { type, 40, d };
+ struct fmt_spec f = (struct fmt_spec) { .type = type, .w = 40, .d = d };
fmt_fix_output (&f);
return f;
}
put_value_mod (buf, value, NULL);
size_t len = strlen (value->string.s);
if (value->string.hex)
- put_format (buf, &(struct fmt_spec) { FMT_AHEX, len * 2, 0 }, false);
+ put_format (buf, &(struct fmt_spec) { .type = FMT_AHEX, .w = len * 2 },
+ false);
else
- put_format (buf, &(struct fmt_spec) { FMT_A, len, 0 }, 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);