Added coefficient-handling routines
[pspp-builds.git] / src / frequencies.q
index fa380dea0fef49b18a78a4b94b93da1f483a6759..5754be7e61e6de277491488c814ba99af96c2057 100644 (file)
@@ -14,8 +14,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 /*
   TODO:
 #include "vfm.h"
 #include "settings.h"
 #include "chart.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
 /* (headers) */
 
 #include "debug-print.h"
@@ -183,7 +188,7 @@ static double scale, incr;  /* FIXME */
 static int normal;             /* FIXME */
 
 /* Variables for which to calculate statistics. */
-static int n_variables;
+static size_t n_variables;
 static struct variable **v_variables;
 
 /* Arenas used to store semi-permanent storage. */
@@ -488,7 +493,7 @@ static int
 calc (struct ccase *c, void *aux UNUSED)
 {
   double weight;
-  int i;
+  size_t i;
   int bad_warn = 1;
 
   weight = dict_get_case_weight (default_dict, c, &bad_warn);
@@ -542,7 +547,7 @@ calc (struct ccase *c, void *aux UNUSED)
 static void
 precalc (void *aux UNUSED)
 {
-  int i;
+  size_t i;
 
   pool_destroy (gen_pool);
   gen_pool = pool_create ();
@@ -586,7 +591,7 @@ precalc (void *aux UNUSED)
 static void
 postcalc (void *aux UNUSED)
 {
-  int i;
+  size_t i;
 
   for (i = 0; i < n_variables; i++)
     {
@@ -692,7 +697,7 @@ not_missing (const void *f_, void *v_)
   const struct freq *f = f_;
   struct variable *v = v_;
 
-  return !is_missing (&f->v, v);
+  return !mv_is_value_missing (&v->miss, &f->v);
 }
 
 /* Summarizes the frequency table data for variable V. */
@@ -702,7 +707,7 @@ postprocess_freq_tab (struct variable *v)
   hsh_compare_func *compare;
   struct freq_tab *ft;
   size_t count;
-  void **data;
+  void *const *data;
   struct freq *freqs, *f;
   size_t i;
 
@@ -715,7 +720,7 @@ postprocess_freq_tab (struct variable *v)
   data = hsh_data (ft->data);
 
   /* Copy dereferenced data into freqs. */
-  freqs = xmalloc (count * sizeof *freqs);
+  freqs = xnmalloc (count, sizeof *freqs);
   for (i = 0; i < count; i++) 
     {
       struct freq *f = data[i];
@@ -768,8 +773,8 @@ frq_custom_variables (struct cmd_frequencies *cmd UNUSED)
   int mode;
   int min = 0, max = 0;
 
-  int old_n_variables = n_variables;
-  int i;
+  size_t old_n_variables = n_variables;
+  size_t i;
 
   lex_match ('=');
   if (token != T_ALL && (token != T_ID
@@ -830,8 +835,8 @@ frq_custom_variables (struct cmd_frequencies *cmd UNUSED)
        {
          vf->tab.min = min;
          vf->tab.max = max;
-         vf->tab.vector = pool_alloc (int_pool,
-                                       sizeof (struct freq) * (max - min + 1));
+         vf->tab.vector = pool_nalloc (int_pool,
+                                        max - min + 1, sizeof *vf->tab.vector);
        }
       else
        vf->tab.vector = NULL;
@@ -851,14 +856,14 @@ frq_custom_grouped (struct cmd_frequencies *cmd UNUSED)
       || token == T_ID)
     for (;;)
       {
-       int i;
+       size_t i;
 
        /* Max, current size of list; list itself. */
        int nl, ml;
        double *dl;
 
        /* Variable list. */
-       int n;
+       size_t n;
        struct variable **v;
 
        if (!parse_variables (default_dict, &v, &n,
@@ -873,7 +878,7 @@ frq_custom_grouped (struct cmd_frequencies *cmd UNUSED)
                if (nl >= ml)
                  {
                    ml += 16;
-                   dl = pool_realloc (int_pool, dl, ml * sizeof (double));
+                   dl = pool_nrealloc (int_pool, dl, ml, sizeof *dl);
                  }
                dl[nl++] = tokval;
                lex_get ();
@@ -944,9 +949,8 @@ add_percentile (double x)
 
   if (i >= n_percentiles || tokval != percentiles[i].p)
     {
-      percentiles
-        = pool_realloc (int_pool, percentiles,
-                        (n_percentiles + 1) * sizeof (struct percentile ));
+      percentiles = pool_nrealloc (int_pool, percentiles,
+                                   n_percentiles + 1, sizeof *percentiles);
 
       if (i < n_percentiles)
           memmove (&percentiles[i + 1], &percentiles[i],
@@ -1559,7 +1563,7 @@ freq_tab_to_hist(const struct freq_tab *ft, const struct variable *var)
   /* Find out the extremes of the x value */
   for ( frq = hsh_first(fh, &hi); frq != 0; frq = hsh_next(fh, &hi) ) 
     {
-      if ( is_missing(&frq->v, var))
+      if ( mv_is_value_missing(&var->miss, &frq->v))
        continue;
 
       if ( frq->v.f < x_min ) x_min = frq->v.f ;
@@ -1598,7 +1602,7 @@ freq_tab_to_slice_array(const struct freq_tab *frq_tab,
 
   *n_slices = frq_tab->n_valid;
   
-  slices = xmalloc ( *n_slices * sizeof (struct slice ) );
+  slices = xnmalloc (*n_slices, sizeof *slices);
 
   for (i = 0 ; i < *n_slices ; ++i ) 
     {