Provide wrapper for gtk_menu_popup_at_pointer.
[pspp] / src / ui / gui / psppire-delimited-text.c
index f95cb594a5183c6a4a5974b2a3323b02f6051cba..dd3715f6b97bb68a36bfefb855d980788daf9ed2 100644 (file)
@@ -51,63 +51,64 @@ static const struct enclosure enclosures[3] =
 static void
 count_delims (PsppireDelimitedText *tf)
 {
-  if (tf->child)
+  if (tf->child == NULL)
+    return;
+
+  tf->max_delimiters = 0;
+  GtkTreeIter iter;
+  gboolean valid;
+  for (valid = gtk_tree_model_get_iter_first (tf->child, &iter);
+       valid;
+       valid = gtk_tree_model_iter_next (tf->child, &iter))
     {
-      tf->max_delimiters = 0;
-      GtkTreeIter iter;
-      gboolean valid;
-      for (valid = gtk_tree_model_get_iter_first (tf->child, &iter);
-          valid;
-          valid = gtk_tree_model_iter_next (tf->child, &iter))
-       {
-         gint enc = -1;
-         // FIXME: Box these lines to avoid constant allocation/deallocation
-         gchar *foo = 0;
-         gtk_tree_model_get (tf->child, &iter, 1, &foo, -1);
+      gint enc = -1;
+      // FIXME: Box these lines to avoid constant allocation/deallocation
+      gchar *line = NULL;
+      gtk_tree_model_get (tf->child, &iter, 1, &line, -1);
+      {
+       char *p;
+       gint count = 0;
+       for (p = line; ; p = g_utf8_find_next_char (p, NULL))
          {
-           char *line = foo;
-           gint count = 0;
-           while (*line)
+           const gunichar c = g_utf8_get_char (p);
+           if (c == 0)
+             break;
+           if (enc == -1)
              {
-               const gunichar c = *line; //FIXME: Not multibyte safe!
-               if (enc == -1)
+               gint i;
+               for (i = 0; i < 3; ++i)
                  {
-                   gint i;
-                   for (i = 0; i < 3; ++i)
+                   if (c == enclosures[i].opening)
                      {
-                       if (c == enclosures[i].opening)
-                         {
-                           enc = i;
-                           break;
-                         }
+                       enc = i;
+                       break;
                      }
                  }
-               else if (c == enclosures[enc].closing)
-                 {
-                   enc = -1;
-                 }
-               if (enc == -1)
+             }
+           else if (c == enclosures[enc].closing)
+             {
+               enc = -1;
+             }
+           if (enc == -1)
+             {
+               GSList *del;
+               for (del = tf->delimiters; del; del = g_slist_next (del))
                  {
-                   GSList *del;
-                   for (del = tf->delimiters; del; del = g_slist_next (del))
-                     {
-                       if (c == GPOINTER_TO_INT (del->data))
-                         count++;
-                     }
+                   if (c == GPOINTER_TO_INT (del->data))
+                     count++;
                  }
-               line++;
              }
-           tf->max_delimiters = MAX (tf->max_delimiters, count);
          }
-         g_free (foo);
-       }
+       tf->max_delimiters = MAX (tf->max_delimiters, count);
+      }
+      g_free (line);
     }
 }
 
 static void
 cache_invalidate (PsppireDelimitedText *tf)
 {
-  memset (tf->cache_starts, 0, 512);
+  memset (tf->cache_starts, 0, sizeof tf->cache_starts);
   if (tf->const_cache.string)
     {
       ss_dealloc (&tf->const_cache);
@@ -369,7 +370,7 @@ split_row_into_fields (PsppireDelimitedText *file, gint n)
       return;
     }
 
-  memset (file->cache_starts, 0, 512);
+  memset (file->cache_starts, 0, sizeof file->cache_starts);
   /* Cache miss */
   if (file->const_cache.string)
     {
@@ -582,7 +583,7 @@ psppire_delimited_text_init (PsppireDelimitedText *text_file)
   text_file->const_cache.string = NULL;
   text_file->const_cache.length = 0;
   text_file->cache_row = -1;
-  memset (text_file->cache_starts, 0, 512);
+  memset (text_file->cache_starts, 0, sizeof text_file->cache_starts);
 
   text_file->max_delimiters = 0;
 
@@ -591,15 +592,13 @@ psppire_delimited_text_init (PsppireDelimitedText *text_file)
 }
 
 
-GtkTreeModel *
+PsppireDelimitedText *
 psppire_delimited_text_new (GtkTreeModel *child)
 {
-  PsppireDelimitedText *retval =
+  return
     g_object_new (PSPPIRE_TYPE_DELIMITED_TEXT,
                  "child", child,
                  NULL);
-
-  return GTK_TREE_MODEL (retval);
 }
 
 static void