treewide: Use struct fmt_spec by value instead of pointer in most cases.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 26 Feb 2023 00:51:00 +0000 (16:51 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 26 Feb 2023 00:51:00 +0000 (16:51 -0800)
struct fmt_spec is a small struct, only 4 bytes in size.  It doesn't make
sense to pass it by pointer in most cases.  This commit makes that change
treewide.

80 files changed:
perl-module/PSPP.xs
perl-module/typemap
src/data/csv-file-writer.c
src/data/data-out.c
src/data/data-out.h
src/data/dataset.c
src/data/dictionary.c
src/data/format-guesser.c
src/data/format-guesser.h
src/data/format.c
src/data/format.h
src/data/gnumeric-reader.c
src/data/mdd-writer.c
src/data/ods-reader.c
src/data/pc+-file-reader.c
src/data/por-file-reader.c
src/data/por-file-writer.c
src/data/psql-reader.c
src/data/settings.c
src/data/settings.h
src/data/sys-file-reader.c
src/data/sys-file-writer.c
src/data/variable.c
src/data/variable.h
src/language/commands/aggregate.c
src/language/commands/autorecode.c
src/language/commands/combine-files.c
src/language/commands/ctables.c
src/language/commands/data-list.c
src/language/commands/data-parser.c
src/language/commands/data-parser.h
src/language/commands/formats.c
src/language/commands/get-data.c
src/language/commands/matrix-data.c
src/language/commands/matrix.c
src/language/commands/means.c
src/language/commands/median.c
src/language/commands/missing-values.c
src/language/commands/mrsets.c
src/language/commands/numeric.c
src/language/commands/output.c
src/language/commands/placement-parser.c
src/language/commands/placement-parser.h
src/language/commands/print.c
src/language/commands/rank.c
src/language/commands/set.c
src/language/commands/sort-variables.c
src/language/commands/sys-file-info.c
src/language/commands/vector.c
src/language/expressions/evaluate.c
src/language/expressions/generate.py
src/language/expressions/operations.def
src/language/expressions/optimize.c
src/language/expressions/parse.c
src/language/expressions/private.h
src/language/lexer/value-parser.c
src/language/tests/format-guesser-test.c
src/output/pivot-table.c
src/output/pivot-table.h
src/output/spv/spv-legacy-decoder.c
src/output/spv/spv-writer.c
src/output/spv/spv.c
src/ui/gui/find-dialog.c
src/ui/gui/helper.c
src/ui/gui/helper.h
src/ui/gui/missing-val-dialog.c
src/ui/gui/psppire-data-store.c
src/ui/gui/psppire-dialog-action-indep-samps.c
src/ui/gui/psppire-dialog-action-roc.c
src/ui/gui/psppire-dict.c
src/ui/gui/psppire-dictview.c
src/ui/gui/psppire-import-textfile.c
src/ui/gui/psppire-value-entry.c
src/ui/gui/psppire-value-entry.h
src/ui/gui/psppire-var-info.c
src/ui/gui/psppire-variable-sheet.c
src/ui/gui/val-labs-dialog.c
src/ui/gui/var-type-dialog.c
src/ui/syntax-gen.c
tests/output/pivot-table-test.c

index 573dfab42afaf8603406392a4fd1fce65387ad64..b6e653e2a9ca923dd56e24fe00b9e62ccce7cfa4 100644 (file)
@@ -219,13 +219,13 @@ format_value (val, var)
  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:
@@ -378,7 +378,7 @@ CODE:
  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 )
@@ -386,7 +386,7 @@ CODE:
     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;
@@ -442,11 +442,11 @@ get_write_format (var)
  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:
@@ -457,11 +457,11 @@ get_print_format (var)
  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:
@@ -473,7 +473,7 @@ pxs_set_write_format (var, fmt)
  struct variable *var
  output_format fmt
 CODE:
- var_set_write_format (var, &fmt);
+ var_set_write_format (var, fmt);
 
 
 void
@@ -481,14 +481,14 @@ pxs_set_print_format (var, fmt)
  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
index cb003f24b978e71ba11da2798d923bfdd4fb77bb..daa58c949368cb0f940d2132bd86e57080d57d5b 100644 (file)
@@ -36,10 +36,10 @@ OUTPUT_FMT_SPEC
    $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);
    }
 
@@ -59,10 +59,10 @@ INPUT_FMT_SPEC
    $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);
    }
 
index c00a2cffed4df0a5a91e87b21f05ed8780d07fbe..3b76b36b53e213ecf7b1f2ec7825795da91be370 100644 (file)
@@ -120,7 +120,7 @@ csv_writer_open (struct file_handle *fh, const struct dictionary *dict,
       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
@@ -225,7 +225,7 @@ static void
 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)
index cda2b75fb0b01a48e0ac14d1e4300d2304922716..0815a5f7c5d3345f9d9cfefbe591f24ca4bb7737 100644 (file)
@@ -65,26 +65,25 @@ static int rounder_width (const struct rounder *, int decimals,
 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 *);
@@ -110,22 +109,21 @@ static data_out_converter_func *const converters[FMT_NUMBER_OF_FORMATS] =
    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);
@@ -169,32 +167,32 @@ binary_to_utf8 (const char *in, struct pool *pool)
    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;
     }
 }
@@ -204,26 +202,23 @@ data_out_pool (const union value *input, const char *input_encoding,
    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, " "));
         }
     }
@@ -233,7 +228,7 @@ data_out_stretchy (const union value *input, const char *encoding,
 
 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);
 }
@@ -244,7 +239,7 @@ data_out (const union value *input, const char *input_encoding,
 /* 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;
@@ -256,12 +251,12 @@ output_number (const union value *input, const struct fmt_spec *format,
   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)
@@ -276,46 +271,46 @@ output_number (const union value *input, const struct fmt_spec *format,
 
 /* 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);
@@ -323,114 +318,114 @@ output_Z (const union value *input, const struct fmt_spec *format,
 
 /* 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;
@@ -438,7 +433,7 @@ output_date (const union value *input, const struct fmt_spec *format,
   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;
@@ -485,8 +480,7 @@ output_date (const union value *input, const struct fmt_spec *format,
             {
               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;
@@ -526,16 +520,16 @@ output_date (const union value *input, const struct fmt_spec *format,
           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 != '.')
@@ -555,8 +549,8 @@ output_date (const union value *input, const struct fmt_spec *format,
     }
 
  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:
@@ -570,7 +564,7 @@ output_date (const union value *input, const struct fmt_spec *format,
 
 /* 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] =
@@ -581,9 +575,9 @@ output_WKDAY (const union value *input, const struct fmt_spec *format,
 
   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
     {
@@ -596,7 +590,7 @@ output_WKDAY (const union value *input, const struct fmt_spec *format,
 
 /* 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] =
@@ -607,8 +601,8 @@ output_MONTH (const union value *input, const struct fmt_spec *format,
 
   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
     {
@@ -622,7 +616,7 @@ output_MONTH (const union value *input, const struct fmt_spec *format,
 /* 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 ();
@@ -630,10 +624,10 @@ output_A (const union value *input UNUSED,
 
 /* 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. */
@@ -661,13 +655,13 @@ allocate_space (int request, int max_width, int *width)
    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];
@@ -696,14 +690,14 @@ output_decimal (const struct rounder *r, const struct fmt_spec *format,
       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;
 
@@ -713,17 +707,17 @@ output_decimal (const struct rounder *r, const struct fmt_spec *format,
          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)
@@ -752,8 +746,8 @@ output_decimal (const struct rounder *r, const struct fmt_spec *format,
       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;
@@ -764,7 +758,7 @@ output_decimal (const struct rounder *r, const struct fmt_spec *format,
 /* 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)
 {
@@ -777,11 +771,11 @@ output_scientific (double number, const struct fmt_spec *format,
   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;
 
@@ -789,15 +783,15 @@ output_scientific (double number, const struct fmt_spec *format,
      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)
@@ -834,8 +828,8 @@ output_scientific (double number, const struct fmt_spec *format,
   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;
@@ -1070,11 +1064,11 @@ power256 (int x)
 /* 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;
 
@@ -1085,39 +1079,39 @@ output_infinite (double number, const struct fmt_spec *format, char *output)
       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
index f0bc9b24c871e445424461d14bf0739176478866..d431447a9dfd9dedff53da0fc587aea80d98dd3e 100644 (file)
@@ -27,18 +27,18 @@ struct string;
 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 */
index 7bc44c7c1017d257ea039143394282ce0a6973d3..a816570c0ed86f777dcac670dfe9560fd3abc78c 100644 (file)
@@ -1061,8 +1061,8 @@ measure_guesser_create__ (struct dictionary *dict)
       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);
index 800bad9463523fbc8e2b1b00f4ef66cc21966c0f..57fe2c08ef2b9b8c7098edea9fcae54a91221170 100644 (file)
@@ -1318,7 +1318,7 @@ dict_get_rounded_case_weight (const struct dictionary *d,
 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
index a9953a532cce8442362ba0193566773014f5b8ec..880fe7c646aa5da556b5064792447487bb7e3112 100644 (file)
@@ -251,33 +251,31 @@ fmt_guesser_add (struct fmt_guesser *g, struct substring s)
     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
index 395da5771e82ce086af5b14f63437aabe8b44fe6..7751e2bdcd35fcb6cc6fefd927a8250c09303aa2 100644 (file)
@@ -25,6 +25,6 @@ struct fmt_guesser *fmt_guesser_create (void);
 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 */
index 73e5dd60f4259df5932f60002a37a0c86c7225b0..87a40e2eed32a75785a9ef7302bd86bfcbe95f59 100644 (file)
@@ -199,7 +199,7 @@ struct fmt_spec
 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;
 }
 
@@ -209,29 +209,29 @@ struct fmt_spec
 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++;
@@ -246,11 +246,11 @@ fmt_for_output_from_input (const struct fmt_spec *input,
     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++;
       }
@@ -262,12 +262,12 @@ fmt_for_output_from_input (const struct fmt_spec *input,
       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:
@@ -278,12 +278,12 @@ fmt_for_output_from_input (const struct fmt_spec *input,
 
     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;
@@ -299,7 +299,7 @@ fmt_for_output_from_input (const struct fmt_spec *input,
       break;
 
     case FMT_AHEX:
-      output.w = input->w / 2;
+      output.w = input.w / 2;
       break;
 
     case FMT_DATE:
@@ -318,13 +318,13 @@ fmt_for_output_from_input (const struct fmt_spec *input,
       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:
@@ -334,7 +334,7 @@ fmt_for_output_from_input (const struct fmt_spec *input,
   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;
 }
 
@@ -352,42 +352,42 @@ fmt_default_for_width (int width)
    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 "
@@ -395,16 +395,16 @@ fmt_check__ (const struct fmt_spec *spec, enum fmt_use use)
                            "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
@@ -413,15 +413,15 @@ fmt_check__ (const struct fmt_spec *spec, enum fmt_use use)
                                "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 (
@@ -429,28 +429,28 @@ fmt_check__ (const struct fmt_spec *spec, enum fmt_use use)
                                "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);
 }
@@ -469,21 +469,21 @@ error_to_bool (char *error)
 
 /* 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);
 }
@@ -493,11 +493,11 @@ fmt_check_output (const struct fmt_spec *spec)
    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);
@@ -526,7 +526,7 @@ fmt_check_type_compat__ (const struct fmt_spec *format, const char *varname,
 /* 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));
 }
@@ -536,7 +536,7 @@ fmt_check_type_compat (const struct fmt_spec *format, enum val_type 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,
@@ -550,7 +550,7 @@ fmt_check_width_compat__ (const struct fmt_spec *format, const char *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);
@@ -572,7 +572,7 @@ fmt_check_width_compat__ (const struct fmt_spec *format, const char *varname,
 /* 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));
 }
@@ -580,10 +580,10 @@ fmt_check_width_compat (const struct fmt_spec *format, int 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);
 }
 
@@ -594,23 +594,23 @@ fmt_var_width (const struct fmt_spec *format)
    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.
@@ -1047,10 +1047,10 @@ fmt_from_u32 (uint32_t u32, int width, bool loose, struct fmt_spec *f)
 
   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,
index db40e13dd9fdba28aa6ae291264da2534872b54c..b01faa42c43a88431f7f4b58eb9152be24b9c583 100644 (file)
@@ -86,29 +86,29 @@ struct fmt_spec
 /* 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);
index 1378469c8a50e640ef563510cf746914cbf469dd..a7f2d04aabc2fbbf2a18df052dccbfa31a524c6d 100644 (file)
@@ -635,9 +635,9 @@ convert_xml_string_to_value (struct ccase *c, const struct variable *var,
     {
       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");
 
index b025e693b4625c572ac08beda09d691206ade99c..a0387843a235c03b1c0d9db423e0ea001476318d 100644 (file)
@@ -64,20 +64,20 @@ enum val_numeric_type
 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;
index dc861f29abcdab8916fc0b5d0534726467a8dc80..c95272364580179316c34c076ec43a4e5c90cc60 100644 (file)
@@ -661,8 +661,8 @@ convert_xml_to_value (struct ccase *c, const struct variable *var,
     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);
 
@@ -675,7 +675,7 @@ convert_xml_to_value (struct ccase *c, const struct variable *var,
          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");
 
@@ -954,7 +954,7 @@ ods_make_reader (struct spreadsheet *spreadsheet,
       else
        fmt = fmt_default_for_width (width);
 
-      var_set_both_formats (var, &fmt);
+      var_set_both_formats (var, fmt);
     }
 
   if (n_var_specs ==  0)
index 5832df8d7f923a264149a069038941b851e87781..6380fa97ed9974b6695d138b637433bb8c2f4939 100644 (file)
@@ -755,7 +755,7 @@ read_variables_record (struct pcp_reader *r)
       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)
         {
@@ -924,7 +924,7 @@ parse_variable_records (struct pcp_reader *r, struct dictionary *dict,
         }
 
       /* Set formats. */
-      var_set_both_formats (var, &rec->format);
+      var_set_both_formats (var, rec->format);
     }
 
   return true;
index 125d7be2598a37bb516c80b35d3839a794c3811a..2487ab2cb43f140d3fe6f9962b9a07afa4090d8e 100644 (file)
@@ -632,14 +632,14 @@ convert_format (struct pfm_reader *r, const int portable_format[3],
         .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."),
@@ -735,8 +735,8 @@ read_variables (struct pfm_reader *r, struct dictionary *dict)
 
       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);
index be35418ce7de9b7de7ed43688470ebe9f3c2a313..fee6b1aff8223b64bb6f5f23c50aa70c2cd4a117 100644 (file)
@@ -350,8 +350,8 @@ write_variables (struct pfm_writer *w, struct dictionary *dict)
       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));
index e372a859a98ea661be660c479e4be83184a9d638..8b83d018de0d9fe8de5a52889f6e896bf4f3b7ba 100644 (file)
@@ -177,7 +177,7 @@ dump (const unsigned char *x, int l)
 #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;
@@ -460,7 +460,7 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
        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);
@@ -477,7 +477,7 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
          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 */
@@ -492,7 +492,7 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
            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);
          }
@@ -507,7 +507,7 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict)
            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);
          }
index 5db8e12e249d51e5537ab12e9f909e6c0c6c2919..d4ed848a7e7336f47159debe4852a30ae027c82a 100644 (file)
@@ -509,18 +509,18 @@ settings_set_workspace (size_t workspace)
 
 /* 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
@@ -656,18 +656,18 @@ settings_set_small (double small)
    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)
@@ -676,10 +676,10 @@ settings_dollar_template (const struct fmt_spec *fmt)
           --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);
index 670c41003236f3891e7246bdcde64188892f6286..76988b2719c73dc70bf169060d5dced39ab4bf28 100644 (file)
@@ -107,8 +107,8 @@ size_t settings_get_workspace (void);
 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);
@@ -165,7 +165,7 @@ const struct fmt_settings *settings_get_fmt_settings (void);
 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
index 17e2754cc147ac974c367978db1c6848dc828f0a..66552dc4b46b85cdc58ffb8f6b509b168058199f 100644 (file)
@@ -1540,9 +1540,9 @@ parse_format_spec (struct sfm_reader *r, off_t pos, unsigned int format,
   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)
     {
index 2a6f5680eceab961284b047054510a071f84fefc..33215241c2c98433d153802e7dca1c450c4ee67f 100644 (file)
@@ -450,7 +450,7 @@ write_header (struct sfm_writer *w, const struct dictionary *d)
 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)
@@ -518,8 +518,8 @@ write_variable (struct sfm_writer *w, const struct variable *v)
     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
index 4fdfdcbb65d83609b14f8f29b14bf1ffe6b0741a..7d5286fb48933015adf7c42d21713dfcb1f181ff 100644 (file)
@@ -117,8 +117,8 @@ struct variable
   };
 \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);
 
@@ -343,13 +343,13 @@ var_set_width_and_formats (struct variable *v, int new_width,
 
   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;
     }
 
@@ -568,7 +568,7 @@ static void
 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 (" "));
@@ -619,10 +619,10 @@ var_append_value_name (const struct variable *v, const union value *value,
 /* 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
@@ -630,12 +630,12 @@ var_get_print_format (const struct variable *v)
    (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;
     }
 }
 
@@ -644,7 +644,7 @@ var_set_print_format_quiet (struct variable *v, const struct fmt_spec *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);
@@ -652,10 +652,10 @@ var_set_print_format (struct variable *v, const struct fmt_spec *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
@@ -663,12 +663,12 @@ var_get_write_format (const struct variable *v)
    (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;
     }
 }
 
@@ -677,7 +677,7 @@ var_set_write_format_quiet (struct variable *v, const struct fmt_spec *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);
@@ -690,7 +690,7 @@ var_set_write_format (struct variable *v, const struct fmt_spec *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);
index b5562ba827c5ca538b1bc3590b52f15113877fd1..4a1ac6f81acc81920a9d34c5c9208a6ee9e8681d 100644 (file)
@@ -109,11 +109,11 @@ void var_replace_value_label (struct variable *,
 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);
 
index 24b22722a79eddc6ebc8d8b2219b05559e5aa6af..fedfbaf5fc67772d07b56de9c699b114089b4ade 100644 (file)
@@ -625,7 +625,7 @@ parse_aggregate_functions (struct lexer *lexer, const struct dictionary *dict,
                 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]);
index 2e575f7b45f176a5d39d1739acfc629c431c2424..c854e0c2c25b43f6c712cda4073c52920c0a1b77 100644 (file)
@@ -246,7 +246,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
       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);
@@ -343,7 +343,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
       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. */
@@ -391,8 +391,8 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
                 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));
index 4c7b4661f0ce52eb28d0c62f2b6426542159d257..c6af498b866031ce44b9d50c5d15d2c6f361aa51 100644 (file)
@@ -621,7 +621,7 @@ create_flag_var (struct lexer *lexer, const char *subcommand,
                          var_name, subcommand);
           return false;
         }
-      var_set_both_formats (*var, &format);
+      var_set_both_formats (*var, format);
     }
   else
     *var = NULL;
index ffc284945eb5417921c6fd506f1157025865102f..224fe7ec60b0e3821dd1af79c60594fc547ef06d 100644 (file)
@@ -217,7 +217,7 @@ ctables_summary_default_format (enum ctables_summary_function function,
       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 ();
@@ -1292,9 +1292,9 @@ parse_ctables_format_specifier (struct lexer *lexer, struct fmt_spec *format,
       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);
@@ -4049,19 +4049,20 @@ ctables_table_parse_categories (struct lexer *lexer, struct dictionary *dict,
   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);
@@ -4314,7 +4315,7 @@ ctables_table_parse_categories (struct lexer *lexer, struct dictionary *dict,
           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 (
@@ -4344,7 +4345,7 @@ ctables_table_parse_categories (struct lexer *lexer, struct dictionary *dict,
                 {
                   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);
@@ -4365,14 +4366,14 @@ ctables_table_parse_categories (struct lexer *lexer, struct dictionary *dict,
                     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]);
@@ -4477,7 +4478,7 @@ ctables_table_add_section (struct ctables_table *t, enum pivot_axis_type a,
 }
 
 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 };
@@ -4917,7 +4918,7 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
                 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);
index 721ac2be524ec1f14e84651924bb50c589fb2132..cdc540bb2348dfa71b4d0451d20dd351c378981f 100644 (file)
@@ -365,18 +365,18 @@ parse_fixed (struct lexer *lexer, struct dictionary *dict,
       /* 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
               {
@@ -419,7 +419,7 @@ parse_fixed (struct lexer *lexer, struct dictionary *dict,
                 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);
 
@@ -478,7 +478,7 @@ parse_free (struct lexer *lexer, struct dictionary *dict,
               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);
@@ -493,30 +493,30 @@ parse_free (struct lexer *lexer, struct dictionary *dict,
           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));
        }
     }
index 09ea762fb0acd0a8084cf3e5d0edd22b92e441c2..5105bd5aa828d91c08f69fbf097ae2b4e38a7930 100644 (file)
@@ -274,7 +274,7 @@ data_parser_set_records (struct data_parser *parser, int records_per_case)
 }
 
 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;
@@ -282,11 +282,13 @@ add_field (struct data_parser *p, const struct fmt_spec *format, int case_idx,
   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
@@ -296,7 +298,7 @@ add_field (struct data_parser *p, const struct fmt_spec *format, int case_idx,
    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);
@@ -318,7 +320,7 @@ data_parser_add_delimited_field (struct data_parser *parser,
    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)
 {
@@ -552,7 +554,7 @@ parse_fixed (const struct data_parser *parser, struct dfm_reader *reader,
           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)
@@ -642,7 +644,7 @@ parse_delimited_span (const struct data_parser *parser,
       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);
     }
@@ -681,7 +683,7 @@ parse_delimited_no_span (const struct data_parser *parser,
                 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;
        }
 
@@ -689,7 +691,7 @@ parse_delimited_no_span (const struct data_parser *parser,
       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);
     }
@@ -748,7 +750,7 @@ dump_fixed_table (const struct data_parser *parser,
       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));
 
     }
 
@@ -783,7 +785,7 @@ dump_delimited_table (const struct data_parser *parser,
       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);
index 1ac9cbe610354313c7623f56c6e3a9c30c7f5546..0194c066f4b8a6be498dfb06fae23b606b62291b 100644 (file)
@@ -67,11 +67,10 @@ void data_parser_set_records (struct data_parser *, int records_per_case);
 
 /* 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 *,
index 907a47f9ae6efb68d5c6e4e6b1a64ab7752eb57f..e30c8c58fd6fc7b3953c6ca9ecc7459c941da728 100644 (file)
@@ -85,9 +85,9 @@ cmd_formats__ (struct lexer *lexer, struct dataset *ds,
        }
       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);
@@ -104,9 +104,9 @@ cmd_formats__ (struct lexer *lexer, struct dataset *ds,
       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;
index deff70e0cca77982e707081f0133e47b63fd0b3e..b74b0fa80286959f24ceb7bb882ae80b376592bf 100644 (file)
@@ -526,14 +526,14 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
         {
           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
@@ -560,7 +560,7 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
 
           /* 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);
@@ -572,7 +572,7 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
           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);
@@ -581,23 +581,23 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
                 }
             }
           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;
index cc72e7dbda51201ca6b1da054be8b4a01a2134d9..a1c23078854dc8af15d40d9550b783daf4dd421c 100644 (file)
@@ -902,7 +902,7 @@ parse_matrix_data_subvars (struct lexer *lexer, struct dictionary *dict,
       *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;
 
@@ -1038,7 +1038,7 @@ cmd_matrix_data (struct lexer *lexer, struct dataset *ds)
                                                     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);
             }
@@ -1154,8 +1154,8 @@ cmd_matrix_data (struct lexer *lexer, struct dataset *ds)
       {
         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)
     {
index 7ef6f3883aeae03cc33119e0f6985fbbf81c305a..f34e24edda0abd417e4b76766e098d5a35be0c89 100644 (file)
@@ -5472,7 +5472,7 @@ static bool
 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;
@@ -5607,7 +5607,7 @@ matrix_print_text (const struct matrix_print *print, const gsl_matrix *m,
           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);
@@ -7254,7 +7254,7 @@ matrix_write_parse (struct matrix_state *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);
@@ -7287,10 +7287,10 @@ matrix_write_parse (struct matrix_state *s)
         }
     }
 
-  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));
@@ -7351,7 +7351,7 @@ matrix_write_execute (struct matrix_write *write)
                 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
             {
index c1337ad949fbb63d8dd3560d759a075b935707d5..eacc74f3d9518a82286b7c32e11da85c5f5b2b52 100644 (file)
@@ -577,7 +577,7 @@ populate_table (const struct means *means, const struct mtable *mt,
          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);
         }
index c15108896ba575ca508a4dd14dc62089f668d5cb..10a4d40650480b2e37278f7a1b28a786d6dd254e 100644 (file)
@@ -377,7 +377,7 @@ show_test_statistics (const struct n_sample_test *nst,
           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);
         }
     }
index 187ddee3164f30ca25edc8a28c4df0b8cb9e86fa..a6e98950fe4d3632103ffee3c04298825da5aefb 100644 (file)
@@ -69,7 +69,7 @@ cmd_missing_values (struct lexer *lexer, struct dataset *ds)
             {
               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))
index fbcd1da215a46ec80bbe4baa76c5468a4fd3eeb3..0e267c051442e89048651cc7a9ada7b74f90899d 100644 (file)
@@ -596,7 +596,7 @@ parse_display (struct lexer *lexer, struct dictionary *dict)
         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;
index 4bf1ef94a1be3be59375314ecab70f74aad04458..73ca39b7da2bdb974b97875f7a66875a4b63cf6a 100644 (file)
@@ -56,7 +56,7 @@ cmd_numeric (struct lexer *lexer, struct dataset *ds)
          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);
@@ -69,7 +69,7 @@ cmd_numeric (struct lexer *lexer, struct dataset *ds)
               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;
            }
 
@@ -89,7 +89,7 @@ cmd_numeric (struct lexer *lexer, struct dataset *ds)
            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;
 
@@ -126,9 +126,9 @@ cmd_string (struct lexer *lexer, struct dataset *ds)
           || !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);
@@ -140,7 +140,7 @@ cmd_string (struct lexer *lexer, struct dataset *ds)
         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],
@@ -149,7 +149,7 @@ cmd_string (struct lexer *lexer, struct dataset *ds)
            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;
 
index 38d437ae18fa9a9050c234d699b31ee9d77a0176..a3515edbddbd277be4d25b53783f8cc511294e4d 100644 (file)
@@ -86,10 +86,7 @@ cmd_output_modify (struct lexer *lexer, struct dataset *ds UNUSED)
                     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))
                     {
@@ -112,7 +109,7 @@ cmd_output_modify (struct lexer *lexer, struct dataset *ds UNUSED)
               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);
             }
        }
index 9fc4d95b587af2aa7c246454b57f4dec58fa261e..178529a7ebf7f66b242ea6f9e39355ac90d04f12 100644 (file)
@@ -167,7 +167,7 @@ fixed_parse_columns (struct lexer *lexer, struct pool *pool, size_t n_vars,
   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);
@@ -247,7 +247,7 @@ fixed_parse_fortran (struct lexer *lexer, struct pool *pool, enum fmt_use use,
                                      _("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);
@@ -291,17 +291,17 @@ fixed_parse_fortran (struct lexer *lexer, struct pool *pool, enum fmt_use use,
    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:
@@ -310,7 +310,7 @@ execute_placement_format (const struct fmt_spec *format,
       return true;
 
     default:
-      assert (format->type < FMT_NUMBER_OF_FORMATS);
+      assert (format.type < FMT_NUMBER_OF_FORMATS);
       return false;
     }
 }
index 93daff98f0b1b5ba906f497663e38d1097366ae9..77ef6654959cbfd7f3202a2e97057e5490d3fb0b 100644 (file)
@@ -28,8 +28,7 @@ bool parse_record_placement (struct lexer *, int *record, int *column);
 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,
index 76acf143f82ab77cd9b125d8ff041bc399212aed..c2fd455dc0a24c9aea904ccd2bc8b94da4f933e5 100644 (file)
@@ -393,8 +393,8 @@ parse_variable_argument (struct lexer *lexer, const struct dictionary *dict,
         {
           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;
     }
@@ -402,10 +402,10 @@ parse_variable_argument (struct lexer *lexer, const struct dictionary *dict,
 
   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)
           {
@@ -471,7 +471,7 @@ dump_table (struct print_trns *trns)
 
       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 (
@@ -533,7 +533,7 @@ print_text_trns_proc (void *trns_, struct ccase **c,
               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;
@@ -636,7 +636,7 @@ print_binary_trns_proc (void *trns_, struct ccase **c,
           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);
index 7d04e080b45246c8821b4dbcad5e1512ef5f1f26..3157153b5389ddbeb3db3918a2db5d1de67dc8ec 100644 (file)
@@ -1041,7 +1041,7 @@ rank_cmd (struct dataset *ds, const struct rank *cmd)
           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]);
 
index 75ba7b413edbd75a24f90730cc438749770cb310..905b489f79afe8cc314e48cbe277c4abc3ec9aa6 100644 (file)
@@ -531,7 +531,7 @@ parse_FORMAT (struct lexer *lexer)
   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);
@@ -546,11 +546,11 @@ parse_FORMAT (struct lexer *lexer)
       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;
 }
 
index d30629feb0b7aa8c47837d5a5794e8c153405e91..58e833e9e7a59f6f5f57ecf8d0f198ef34b036a1 100644 (file)
@@ -65,13 +65,13 @@ compare_ints (int a, int b)
 }
 
 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;
 }
 
index 1b2b6784042807bc724e8a330f3c1bfd2c889e28..392e89b545e16b240c619942372b9f284ce2c0c0 100644 (file)
@@ -566,7 +566,7 @@ display_variables (const struct variable **vl, size_t n, int flags)
 
       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 (
@@ -576,7 +576,7 @@ display_variables (const struct variable **vl, size_t n, int flags)
 
       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 (
index fa4e3f996a5b8367b367b2a480756ff133a25c52..ba61dcae56de5f46704da4851d42b472f0a5a609 100644 (file)
@@ -145,7 +145,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds)
                   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);
@@ -202,8 +202,8 @@ cmd_vector (struct lexer *lexer, struct dataset *ds)
                {
                   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);
index edc1b4e7ae838a760f2d60125e18f48fcfd52d0c..8719e5e950e9772f4a4543db4615880402017a9e 100644 (file)
@@ -229,9 +229,9 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
           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);
@@ -282,7 +282,7 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
           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);
index 50e1f4d1c9518d5e41c1a8f5fe8a22dfbe890e41..43fadb017d128d6cdefcd892626fc0e7ef6aabfd 100644 (file)
@@ -51,9 +51,9 @@ def init_all_types():
 
         # 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.
index 7bcc02da3189260294a8b19bec560fa1784dcc7b..5bf8b10ce2d6a499684a39418466924c98d29ecd 100644 (file)
@@ -761,20 +761,20 @@ function NUMBER (string s, ni_format f)
   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;
@@ -789,7 +789,7 @@ absorb_miss string function STRING (x, no_format 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);
index 129dbc30e65056f8164ba0dae78812fe4fe0f60e..d893d1e9957233dfdd101557d2f424b9c597a44e 100644 (file)
@@ -191,13 +191,13 @@ get_string_args (struct expr_node *n, size_t arg_idx, size_t n_args,
   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 *
@@ -247,10 +247,9 @@ emit_string (struct expression *e, struct substring s)
 }
 
 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
@@ -340,7 +339,7 @@ flatten_composite (struct expr_node *n, struct expression *e)
 
         case OP_ni_format:
         case OP_no_format:
-          emit_format (e, &arg->format);
+          emit_format (e, arg->format);
           break;
 
         case OP_pos_int:
index 3a4466ad55e4cf8e93fc60b6d1573f6bd20c5a0d..72d706cc794bda1c23016ae43c5565ce3ec04076 100644 (file)
@@ -491,8 +491,8 @@ type_coercion__ (struct expression *e, struct expr_node *node, size_t arg_idx,
 
     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;
@@ -502,8 +502,8 @@ type_coercion__ (struct expression *e, struct expr_node *node, size_t arg_idx,
 
     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;
@@ -952,7 +952,7 @@ parse_primary__ (struct lexer *lexer, struct expression *e)
           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));
@@ -1295,7 +1295,7 @@ no_match (struct expression *e, const char *func_name, struct expr_node *node,
             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)
@@ -1582,10 +1582,10 @@ expr_allocate_variable (struct expression *e, const struct variable *v)
 }
 
 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;
 }
 
index 235c2ecf207771ec0e8c6500f72cd965ebb7bac3..cde96b877407a37c09af9763e965ab53f65fcaf7 100644 (file)
@@ -130,7 +130,7 @@ union operation_data
     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;
   };
@@ -173,8 +173,7 @@ struct expr_node *expr_allocate_pos_int (struct expression *e, int);
 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,
index e823cf34f1b2a0b8eb23fbe77e5905fc18f9ab02..de137fd31cf5e05113fbefd9e83c7fd5def39823 100644 (file)
@@ -141,7 +141,10 @@ parse_value (struct lexer *lexer, union value *v, const struct variable *var)
 {
   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;
index de68cb20d70a5339f1eb80ce3be4d76ff2cdf282..5b37aa7e6a4390ad972f24984475701a59113392 100644 (file)
 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));
@@ -40,13 +36,14 @@ cmd_debug_format_guesser (struct lexer *lexer, struct dataset *ds UNUSED)
       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);
index 213cfc028cc4ef81f70e9d21d003faccb45f4246..9251621676f2dd630ebde735ba955fba3b0b7f56 100644 (file)
@@ -776,7 +776,7 @@ pivot_table_use_rc (const struct pivot_table *table, const char *s,
     {
       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)
@@ -804,13 +804,13 @@ pivot_table_use_rc (const struct pivot_table *table, const char *s,
    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;
     }
@@ -1368,7 +1368,7 @@ pivot_table_set_weight_var (struct pivot_table *table,
                             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
@@ -1472,7 +1472,7 @@ pivot_table_put (struct pivot_table *table, const size_t *dindexes, size_t n,
                 }
             }
         }
-      value->numeric.format = *settings_get_format ();
+      value->numeric.format = settings_get_format ();
       value->numeric.honor_small = true;
 
     done:;
@@ -2409,13 +2409,13 @@ pivot_value_format_body (const struct pivot_value *value,
                              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 },
@@ -2870,7 +2870,7 @@ pivot_value_new_var_value (const struct variable *variable,
    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)
@@ -2883,13 +2883,13 @@ pivot_value_new_value (const union value *value, int width,
 
       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;
index 6fd97e19c8955b571ff4472ead6ca0707d955aca..24aa00acd7e9cafba184994393886e3188ae215c 100644 (file)
@@ -412,7 +412,7 @@ void pivot_category_destroy (struct pivot_category *);
 #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.
@@ -803,7 +803,7 @@ struct pivot_value *pivot_value_new_integer (double);
 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. */
index 904a6815f1849ac5cb0baab700224f703a2a4663..fb639cfcac9d80dc88480ac71246f7734a6202cf 100644 (file)
@@ -203,7 +203,7 @@ spv_map_insert (struct hmap *map, double from, const char *to,
       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);
@@ -808,7 +808,7 @@ decode_spvdx_source_variable (const struct spvxml_node *node,
             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
index 5a81002927e5f51fda7b8e92a4fbece5a53233ae..182cc5e5471b1b0a81003fb057957c43b8019588 100644 (file)
@@ -598,10 +598,10 @@ put_value_mod (struct buf *buf, const struct pivot_value *value,
 }
 
 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
@@ -629,7 +629,7 @@ put_value (struct buf *buf, const struct pivot_value *value)
         {
           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);
@@ -639,7 +639,7 @@ put_value (struct buf *buf, const struct pivot_value *value)
         {
           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;
@@ -649,10 +649,10 @@ put_value (struct buf *buf, const struct pivot_value *value)
       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);
index eb4d1cd792daf1f85cc204640a8dd7c8da8071c4..7a3dae4d3d4a733834bf534534a1483b9ae9772e 100644 (file)
@@ -890,7 +890,7 @@ spv_decode_fmt_spec (uint32_t u32, struct fmt_spec *out)
   if (ok)
     {
       fmt_fix_output (out);
-      ok = fmt_check_width_compat (out, 0);
+      ok = fmt_check_width_compat (*out, 0);
     }
 
   if (!ok)
index 16f5e365761a12ab3b13cec78ea4d91e42da3bce..104afba89b5602fa5e4f626a2800272e5f43521e 100644 (file)
@@ -473,9 +473,9 @@ value_compare (const struct comparator *cmptr,
               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;
 }
@@ -603,11 +603,11 @@ numeric_comparator_create (const struct variable *var, const char *target)
   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;
index 9b40c08ab5b741f819f416c81d7a34f66a2a849e..6d9fe603788f7437208880dc033c88122726e782 100644 (file)
@@ -70,14 +70,13 @@ value_to_text (union value v, const struct variable *var)
    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);
@@ -112,13 +111,13 @@ text_to_value (const gchar *text,
 */
 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;
 
@@ -136,7 +135,7 @@ text_to_value__ (const gchar *text,
     }
 
   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)
index 69841a5c491d95b42a504e02d37d6ee54851012b..6a9605f0228e59b1e28e2dcfe47b88e6e9567ccb 100644 (file)
@@ -45,13 +45,12 @@ null_if_empty_param (const gchar *name, const gchar *nick,
 }
 
 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 */
index d6f38a2d8f8e0dc3d8213ac62c78367f5fcb4050..3ee221d7613a45ccac3a39ba763fefd421fcc8c5 100644 (file)
@@ -196,7 +196,7 @@ err_dialog (const gchar *msg, GtkWindow *window)
 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);
@@ -233,7 +233,7 @@ static gboolean
 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))
     {
@@ -435,7 +435,7 @@ psppire_missing_val_dialog_set_variable (PsppireMissingValDialog *dialog,
       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
     {
@@ -452,7 +452,7 @@ psppire_missing_val_dialog_set_variable (PsppireMissingValDialog *dialog,
   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);
 
@@ -473,8 +473,8 @@ psppire_missing_val_dialog_set_variable (PsppireMissingValDialog *dialog,
       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);
@@ -485,7 +485,7 @@ psppire_missing_val_dialog_set_variable (PsppireMissingValDialog *dialog,
        {
          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);
        }
@@ -507,7 +507,7 @@ psppire_missing_val_dialog_set_variable (PsppireMissingValDialog *dialog,
              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);
            }
index 2a3efe639522ea320a515914eeb3a734df4db6f6..c93a39fd40f7e390f03d1cf70339a18fcd9d6180 100644 (file)
@@ -57,7 +57,7 @@ static gboolean psppire_data_store_insert_case (PsppireDataStore *ds,
 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;
 
@@ -146,7 +146,7 @@ psppire_data_store_string_to_value (GtkTreeModel *model, gint col, gint row,
   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);
 
@@ -164,7 +164,7 @@ psppire_data_store_string_to_value (GtkTreeModel *model, gint col, gint row,
   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");
     }
 
@@ -184,7 +184,7 @@ unlabeled_value (PsppireDataStore *store, const struct variable *variable, const
       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));
 }
 
@@ -388,11 +388,11 @@ resize_datum (const union value *old, union value *new, const void *aux_)
   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));
@@ -819,7 +819,7 @@ psppire_data_store_set_value (PsppireDataStore *ds, casenumber casenum,
 /* 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;
@@ -840,7 +840,7 @@ psppire_data_store_data_in (PsppireDataStore *ds, casenumber casenum, gint idx,
                         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);
index 31b8cc78c98ede6dc62ccb3f75bc7e57ca243e98..974c1e97f9935ba145859aa34b8dbd9c16c71b22 100644 (file)
@@ -384,8 +384,8 @@ generate_syntax (const PsppireDialogAction *a)
 
         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);
@@ -399,8 +399,9 @@ generate_syntax (const PsppireDialogAction *a)
             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);
index 23c6cae24ce1bab8eed7c38391a7837809c128ef..2a8deedd53a34147c789560e4d7a348e102dc3d5 100644 (file)
@@ -186,8 +186,8 @@ generate_syntax (const PsppireDialogAction *a)
       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);
index 70d3b4934551d7576c50f7383b1735e620c66ce8..5ba4246ac78417f769206cfc5fc5862351d30c26 100644 (file)
@@ -770,7 +770,7 @@ tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter)
   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,
@@ -783,7 +783,7 @@ 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)
     {
@@ -793,11 +793,11 @@ tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter,
       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);
index 5e998fc6f08946a562e565c2648de1103fe0382e..ae429ca1af612635cda8333af8bbc4aa46d31f7a 100644 (file)
@@ -385,7 +385,7 @@ var_icon_cell_data_func (GtkTreeViewColumn *col,
 
   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);
 
index 1b6a4d65bdd18163858b3aa19201d848d5895eab..4b5c0963c8da67fc9f7050b0224ebf4c0f782231 100644 (file)
@@ -640,7 +640,7 @@ my_read (struct casereader *reader, void *aux, casenumber idx)
                 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");
 
@@ -701,14 +701,13 @@ textfile_create_reader (PsppireImportAssistant *ia)
   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);
@@ -812,7 +811,7 @@ apply_dict (const struct dictionary *dict, struct string *s)
       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))
         {
@@ -824,7 +823,7 @@ apply_dict (const struct dictionary *dict, struct string *s)
             {
               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))
@@ -833,7 +832,7 @@ apply_dict (const struct dictionary *dict, struct string *s)
               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");
         }
@@ -848,7 +847,7 @@ apply_dict (const struct dictionary *dict, struct string *s)
             {
               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)));
             }
index 2ff858e3328c94e5b7823a0fbf8568c8115f0db9..f3d7f99a8e6b9db5948e743b155c8b42bb95a6c7 100644 (file)
@@ -78,7 +78,10 @@ psppire_value_entry_set_property (GObject      *object,
       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:
@@ -365,7 +368,7 @@ psppire_value_entry_set_variable (PsppireValueEntry *obj,
   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
@@ -386,7 +389,7 @@ psppire_value_entry_set_value_labels (PsppireValueEntry *obj,
       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);
         }
 
@@ -404,12 +407,12 @@ psppire_value_entry_get_value_labels (const PsppireValueEntry *obj)
 
 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))
@@ -419,10 +422,10 @@ psppire_value_entry_set_format (PsppireValueEntry *obj,
     }
 }
 
-const struct fmt_spec *
+struct fmt_spec
 psppire_value_entry_get_format (const PsppireValueEntry *obj)
 {
-  return &obj->format;
+  return obj->format;
 }
 
 void
@@ -444,17 +447,17 @@ psppire_value_entry_get_encoding (const PsppireValueEntry *obj)
 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
@@ -481,7 +484,7 @@ psppire_value_entry_set_value (PsppireValueEntry *obj,
         }
     }
 
-  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);
 }
@@ -494,7 +497,7 @@ psppire_value_entry_get_value (PsppireValueEntry *obj,
   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)
     {
index 940de30b27cbc0bc8f632b7a9195ec425c0e34ef..88c08a1eb09daa4c5e09d9e3afed1cf9447fb666 100644 (file)
@@ -83,10 +83,8 @@ void psppire_value_entry_set_value_labels (PsppireValueEntry *,
 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 *);
index fa15b78ad0a4b32de1f7ea3bbcf02bad57326fa7..725a52d19116ccab6c815bd678b034ca872db4c6 100644 (file)
@@ -165,12 +165,12 @@ __set_property (GObject      *object,
         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));
 
index 573e66e4cc8206ea0a2b5f8fb48dca9936537c7c..ffd6a167bd9b40cfdc15b5004933d128ff9d5f43 100644 (file)
@@ -51,13 +51,10 @@ set_var_type (PsppireVariableSheet *sheet)
   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
@@ -351,9 +348,9 @@ change_var_property (PsppireVariableSheet *var_sheet, gint col, gint row, const
       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
        {
@@ -366,9 +363,9 @@ change_var_property (PsppireVariableSheet *var_sheet, gint col, gint row, const
       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;
@@ -407,8 +404,8 @@ var_sheet_data_to_string (SswSheet *sheet, GtkTreeModel *m,
 
   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);
index 226021507f45796632a945e37c3ff44bccc661a0..50e704630d00070113d39229703d1b6235c3044d 100644 (file)
@@ -192,7 +192,7 @@ on_label_entry_change (GtkEntry *entry, gpointer data)
 
   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))
     {
@@ -271,7 +271,7 @@ on_value_entry_change (GtkEntry *entry, gpointer data)
   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);
@@ -359,7 +359,7 @@ do_change (PsppireValLabsDialog *dialog)
 
   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)));
@@ -383,7 +383,7 @@ on_add (GtkWidget *w, gpointer data)
 
   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
@@ -438,7 +438,7 @@ on_select_row (GtkTreeView *treeview, gpointer data)
   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);
@@ -586,7 +586,7 @@ repopulate_dialog (PsppireValLabsDialog *dialog)
       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));
@@ -622,7 +622,7 @@ psppire_val_labs_dialog_set_variable (PsppireValLabsDialog *dialog,
     {
       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;
index e8646e9d0bf18e5b6010f99de4a42e61c7839213..1f77eef4427bd87a7f807b320916a696a93e0a62 100644 (file)
@@ -91,9 +91,9 @@ static GObject *psppire_var_type_dialog_constructor (GType type, guint,
 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);
 
@@ -127,7 +127,10 @@ psppire_var_type_dialog_set_property (GObject      *object,
   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);
@@ -156,16 +159,16 @@ psppire_var_type_dialog_get_property (GObject      *object,
 
 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
@@ -220,7 +223,7 @@ psppire_var_type_dialog_run (GtkWindow *parent_window,
 
   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));
 
@@ -358,13 +361,13 @@ on_active_button_change (GtkToggleButton *togglebutton,
       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];
@@ -432,7 +435,7 @@ preview_custom (GtkWidget *w, gpointer data)
   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), "---");
@@ -443,13 +446,13 @@ preview_custom (GtkWidget *w, gpointer data)
       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);
@@ -636,10 +639,10 @@ psppire_var_type_dialog_constructor (GType                  type,
 
   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);
     }
 
@@ -670,7 +673,7 @@ psppire_var_type_dialog_constructor (GType                  type,
 
   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,
@@ -778,13 +781,13 @@ select_treeview_at_index (GtkTreeView *treeview, int index)
 }
 
 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;
index 54a7845b70d44722c6b3bcb531def0556a3365fd..4970f664a215250d70f02fb2884ffd1e35d9d524 100644 (file)
@@ -157,7 +157,7 @@ syntax_gen_number (struct string *output,
       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,
@@ -194,7 +194,7 @@ void
 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
index 8bed7550ebb0cc3d7143d04b8b2ac6e7a1d1875f..754db1eb8e8ef09304aa4e4b2a9908baf8d21f09 100644 (file)
@@ -592,8 +592,8 @@ read_value_option (struct lexer *lexer, const struct pivot_table *pt,
 
       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;