treewide: Replace <name>_cnt by n_<name>s and <name>_cap by allocated_<name>.
[pspp] / src / ui / gui / psppire-import-textfile.c
index 0d9562a54fb5961dab1c30bb358b3785c75309d5..af10780a93aac477df1420d2292da5a7896632a6 100644 (file)
@@ -74,10 +74,9 @@ choose_likely_separators (PsppireImportAssistant *ia)
 
   gboolean valid;
   GtkTreeIter iter;
-  int j;
 
   struct hmap count_map[SEPARATOR_CNT];
-  for (j = 0; j < SEPARATOR_CNT; ++j)
+  for (int j = 0; j < SEPARATOR_CNT; ++j)
     hmap_init (count_map + j);
 
   GtkTreePath *p = gtk_tree_path_new_from_indices (first_line, -1);
@@ -89,7 +88,7 @@ choose_likely_separators (PsppireImportAssistant *ia)
       gchar *line_text = NULL;
       gtk_tree_model_get (GTK_TREE_MODEL (ia->text_file), &iter, 1, &line_text, -1);
 
-      gint *counts = xzalloc (sizeof *counts * SEPARATOR_CNT);
+      gint *counts = XCALLOC (SEPARATOR_CNT, gint);
 
       struct substring cs = ss_cstr (line_text);
       for (;
@@ -121,7 +120,7 @@ choose_likely_separators (PsppireImportAssistant *ia)
 
              if (cn == NULL)
                {
-                 struct separator_count_node *new_cn = xzalloc (sizeof *new_cn);
+                 struct separator_count_node *new_cn = XZALLOC (struct separator_count_node);
                  new_cn->occurance = counts[j];
                  new_cn->quantity = 1;
                  hmap_insert (&count_map[j], &new_cn->node, hash);
@@ -140,7 +139,7 @@ choose_likely_separators (PsppireImportAssistant *ia)
     {
       int most_frequent = -1;
       int largest = 0;
-      for (j = 0; j < SEPARATOR_CNT; ++j)
+      for (int j = 0; j < SEPARATOR_CNT; ++j)
         {
           struct separator_count_node *cn;
           struct separator_count_node *next;
@@ -421,8 +420,8 @@ intro_on_enter (PsppireImportAssistant *ia, GtkWidget *page, enum IMPORT_ASSISTA
                                       "preview purposes in the following screens.  ",
                                       "Only the first %zu lines of the file will be shown for "
                                       "preview purposes in the following screens.  ",
-                                      ia->text_file->line_cnt),
-                        ia->text_file->line_cnt);
+                                      ia->text_file->n_lines),
+                        ia->text_file->n_lines);
        }
     }
 
@@ -578,7 +577,7 @@ on_separators_custom_cb_toggle (GtkToggleButton *custom_cb,
 static void
 on_quote_combo_change (GtkComboBox *combo, PsppireImportAssistant *ia)
 {
-  //  revise_fields_preview (ia);
+  revise_fields_preview (ia);
 }
 
 /* Called when the user toggles the checkbox that enables
@@ -616,8 +615,11 @@ reset_separators_page (PsppireImportAssistant *ia)
 /* Called just before the separators page becomes visible in the
    assistant. */
 static void
-prepare_separators_page (PsppireImportAssistant *ia)
+prepare_separators_page (PsppireImportAssistant *ia, GtkWidget *new_page, enum IMPORT_ASSISTANT_DIRECTION dir)
 {
+  if (dir != IMPORT_ASSISTANT_FORWARDS)
+    return;
+
   gtk_tree_view_set_model (GTK_TREE_VIEW (ia->fields_tree_view),
                           GTK_TREE_MODEL (ia->delimiters_model));
 
@@ -719,6 +721,7 @@ my_read (struct casereader *reader, void *aux, casenumber idx)
              char *xx = data_in (ss_cstr (ss),
                                  "UTF-8",
                                  var_get_write_format (var)->type,
+                                  settings_get_fmt_settings (),
                                  v, var_get_width (var), "UTF-8");
 
              free (xx);
@@ -747,7 +750,7 @@ my_advance (struct casereader *reader, void *aux, casenumber cnt)
 static struct casereader *
 textfile_create_reader (PsppireImportAssistant *ia)
 {
-  int n_vars = dict_get_var_cnt (ia->dict);
+  int n_vars = dict_get_n_vars (ia->dict);
 
   int i;
 
@@ -821,7 +824,7 @@ ia_variable_changed_cb (GObject *obj, gint var_num, guint what,
   PsppireImportAssistant *ia  = PSPPIRE_IMPORT_ASSISTANT (data);
 
   struct caseproto *proto = caseproto_create();
-  for (int i = 0; i < dict_get_var_cnt (ia->dict); i++)
+  for (int i = 0; i < dict_get_n_vars (ia->dict); i++)
     {
       const struct variable *var = dict_get_var (ia->dict, i);
       int width = var_get_width (var);
@@ -878,10 +881,9 @@ first_line_append_syntax (const PsppireImportAssistant *ia, struct string *s)
 static void
 apply_dict (const struct dictionary *dict, struct string *s)
 {
-  size_t var_cnt = dict_get_var_cnt (dict);
-  size_t i;
+  size_t n_vars = dict_get_n_vars (dict);
 
-  for (i = 0; i < var_cnt; i++)
+  for (size_t i = 0; i < n_vars; i++)
     {
       struct variable *var = dict_get_var (dict, i);
       const char *name = var_get_name (var);
@@ -920,12 +922,11 @@ apply_dict (const struct dictionary *dict, struct string *s)
           const struct val_labs *vls = var_get_value_labels (var);
           const struct val_lab **labels = val_labs_sorted (vls);
           size_t n_labels = val_labs_count (vls);
-          size_t i;
 
           syntax_gen_pspp (s, "VALUE LABELS %ss", name);
-          for (i = 0; i < n_labels; i++)
+          for (size_t j = 0; j < n_labels; j++)
             {
-              const struct val_lab *vl = labels[i];
+              const struct val_lab *vl = labels[j];
               ds_put_cstr (s, "\n  ");
               syntax_gen_value (s, &vl->value, width, format);
               ds_put_byte (s, ' ');
@@ -971,22 +972,19 @@ intro_append_syntax (const PsppireImportAssistant *ia, struct string *s)
 static void
 formats_append_syntax (const PsppireImportAssistant *ia, struct string *s)
 {
-  int i;
-  int var_cnt;
-
   g_return_if_fail (ia->dict);
 
   ds_put_cstr (s, "  /VARIABLES=\n");
 
-  var_cnt = dict_get_var_cnt (ia->dict);
-  for (i = 0; i < var_cnt; i++)
+  int n_vars = dict_get_n_vars (ia->dict);
+  for (int i = 0; i < n_vars; i++)
     {
       struct variable *var = dict_get_var (ia->dict, i);
       char format_string[FMT_STRING_LEN_MAX + 1];
       fmt_to_string (var_get_print_format (var), format_string);
       ds_put_format (s, "    %s %s%s\n",
                     var_get_name (var), format_string,
-                    i == var_cnt - 1 ? "." : "");
+                    i == n_vars - 1 ? "." : "");
     }
 }