Add another expression test and fix the bugs it found.
[pspp-builds.git] / src / aggregate.c
index ffd29166142cb2bd44512ebb80cb17d2b935f7f6..a2569837eea9d5e3c0cca06d30262f5b5276a104 100644 (file)
@@ -161,15 +161,8 @@ cmd_aggregate (void)
   /* Have we seen these subcommands? */
   unsigned seen = 0;
 
-  agr.writer = NULL;
-  agr.sink = NULL;
+  memset(&agr, 0 , sizeof (agr));
   agr.missing = ITEMWISE;
-  agr.sort = NULL;
-  agr.break_vars = NULL;
-  agr.agr_vars = NULL;
-  agr.dict = NULL;
-  agr.case_cnt = 0;
-  agr.prev_break = NULL;
   
   agr.dict = dict_create ();
   dict_set_label (agr.dict, dict_get_label (default_dict));
@@ -428,7 +421,9 @@ parse_aggregate_functions (struct agr_proc *agr)
              lex_error (_("expecting `('"));
              goto error;
            }
-       } else {
+       }
+      else
+        {
          /* Parse list of source variables. */
          {
            int pv_opts = PV_NO_SCRATCH;
@@ -521,8 +516,6 @@ parse_aggregate_functions (struct agr_proc *agr)
 
            if (src)
              {
-               int output_width;
-
                v->src = src[i];
                
                if (src[i]->type == ALPHA)
@@ -530,28 +523,29 @@ parse_aggregate_functions (struct agr_proc *agr)
                    v->function |= FSTRING;
                    v->string = xmalloc (src[i]->width);
                  }
-               
-               if (v->src->type == NUMERIC || function->alpha_type == NUMERIC)
-                 output_width = 0;
-               else
-                 output_width = v->src->width;
 
                if (function->alpha_type == ALPHA)
                  destvar = dict_clone_var (agr->dict, v->src, dest[i]);
-               else
-                 {
-                   destvar = dict_create_var (agr->dict, dest[i], output_width);
-                   if (output_width == 0)
-                     destvar->print = destvar->write = function->format;
-                   if (output_width == 0 && dict_get_weight (default_dict) != NULL
-                       && (func_index == N || func_index == N_NO_VARS
-                           || func_index == NU || func_index == NU_NO_VARS))
-                     {
-                       struct fmt_spec f = {FMT_F, 8, 2};
-                     
-                       destvar->print = destvar->write = f;
-                     }
-                 }
+               else if (v->src->type == NUMERIC
+                         || function->alpha_type == NUMERIC)
+                  {
+                    destvar = dict_create_var (agr->dict, dest[i], 0);
+                        
+                    if ((func_index == N
+                            || func_index == N_NO_VARS
+                            || func_index == NMISS)
+                        && dict_get_weight (default_dict) != NULL)
+                      {
+                        static const struct fmt_spec f8_2 = {FMT_F, 8, 2};
+                            
+                        destvar->print = destvar->write = f8_2; 
+                      }
+                    else
+                      destvar->print = destvar->write = function->format;
+                  }
+                else 
+                  destvar = dict_create_var (agr->dict, dest[i],
+                                             v->src->width);
              } else {
                v->src = NULL;
                destvar = dict_create_var (agr->dict, dest[i], 0);
@@ -575,8 +569,6 @@ parse_aggregate_functions (struct agr_proc *agr)
                destvar->label = dest_label[i];
                dest_label[i] = NULL;
              }
-           else if (function->alpha_type == ALPHA)
-             destvar->print = destvar->write = function->format;
 
            v->dest = destvar;
          }
@@ -670,6 +662,7 @@ agr_destroy (struct agr_proc *agr)
     }
   if (agr->dict != NULL)
     dict_destroy (agr->dict);
+
   case_destroy (&agr->agr_case);
 }
 \f