Use convert cell range instead of doing it ourselves
[pspp] / src / ui / gui / page-file.c
index 6422fa6ab463c49cda1a8f75b90089d067fecef9..a3aaf03749995da85ec84fd9f81d88cddaab57f5 100644 (file)
@@ -80,43 +80,46 @@ update_assistant (struct import_assistant *ia)
 
   struct file *file = &ia->file;
   struct separators_page *sepp = &ia->separators;
-  int col;
   int rows = 0;
-  struct ccase *c;
-  
-  sepp->column_cnt = dict_get_var_cnt (ssp->dict);
-  sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns));
-  for (col = 0; col < sepp->column_cnt ; ++col)
+  if (ssp->dict)
     {
-      const struct variable *var = dict_get_var (ssp->dict, col);
-      sepp->columns[col].name = xstrdup (var_get_name (var));
-      sepp->columns[col].contents = NULL;
-    }
+      struct ccase *c;
+      int col;
 
-  for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c))
-    {
-      rows++;
+      sepp->column_cnt = dict_get_var_cnt (ssp->dict);
+      sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns));
       for (col = 0; col < sepp->column_cnt ; ++col)
        {
-         char *ss;
          const struct variable *var = dict_get_var (ssp->dict, col);
+         sepp->columns[col].name = xstrdup (var_get_name (var));
+         sepp->columns[col].contents = NULL;
+       }
 
-         sepp->columns[col].contents = xrealloc (sepp->columns[col].contents,
-                                                 sizeof (struct substring) * rows);
+      for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c))
+       {
+         rows++;
+         for (col = 0; col < sepp->column_cnt ; ++col)
+           {
+             char *ss;
+             const struct variable *var = dict_get_var (ssp->dict, col);
 
-         ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict), 
-                        var_get_print_format (var));
+             sepp->columns[col].contents = xrealloc (sepp->columns[col].contents,
+                                                     sizeof (struct substring) * rows);
 
-         sepp->columns[col].contents[rows - 1] = ss_cstr (ss);
-       }
+             ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict), 
+                            var_get_print_format (var));
 
-      if (rows > MAX_PREVIEW_LINES)
-       {
-         case_unref (c);
-         break;
+             sepp->columns[col].contents[rows - 1] = ss_cstr (ss);
+           }
+
+         if (rows > MAX_PREVIEW_LINES)
+           {
+             case_unref (c);
+             break;
+           }
        }
     }
-
+  
   file->line_cnt = rows;
   casereader_destroy (ssp->reader);
   ssp->reader = NULL;
@@ -164,7 +167,7 @@ init_file (struct import_assistant *ia, GtkWindow *parent_window)
       ia->file.type = FTYPE_ODS;
     }
     
-  if (creader)
+  if (creader && dict)
     {
       struct sheet_spec_page *ssp = &ia->sheet_spec;
       ssp->dict = dict;