]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrc.c
Don't use zip -r on the etc directory, to avoid including editor backup
[~andy/gtk] / gtk / gtkrc.c
index b28145e67d3adaee5361f029d1b706f55768da92..1c488973446c93db8dcef72314ff7fb51e77a236 100644 (file)
@@ -78,6 +78,7 @@ struct _GtkRcFile
   time_t mtime;
   gchar *name;
   gchar *canonical_name;
+  gchar *directory;
   guint reload;
 };
 
@@ -286,10 +287,11 @@ static gchar *im_module_file = NULL;
 #define GTK_RC_MAX_DEFAULT_FILES 128
 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
 
-/* A stack of directories for RC files we are parsing currently.
- * these are implicitely added to the end of PIXMAP_PATHS
+/* A stack of information of RC files we are parsing currently.
+ * The directories for these files are implicitely added to the end of
+ * PIXMAP_PATHS.
  */
-static GSList *rc_dir_stack = NULL;
+static GSList *current_files_stack = NULL;
 
 /* RC files and strings that are parsed for every context
  */
@@ -709,9 +711,10 @@ gtk_rc_parse_string (const gchar *rc_string)
   rc_file->is_string = TRUE;
   rc_file->name = g_strdup (rc_string);
   rc_file->canonical_name = NULL;
+  rc_file->directory = NULL;
   rc_file->mtime = 0;
   rc_file->reload = TRUE;
-
+  
   global_rc_files = g_slist_append (global_rc_files, rc_file);
 
   for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
@@ -740,6 +743,7 @@ add_to_rc_file_list (GSList     **rc_file_list,
   rc_file->is_string = FALSE;
   rc_file->name = g_strdup (filename);
   rc_file->canonical_name = NULL;
+  rc_file->directory = NULL;
   rc_file->mtime = 0;
   rc_file->reload = reload;
   
@@ -764,7 +768,7 @@ gtk_rc_context_parse_one_file (GtkRcContext *context,
   context->default_priority = priority;
 
   rc_file = add_to_rc_file_list (&context->rc_files, filename, reload);
-  
+
   if (!rc_file->canonical_name)
     {
       /* Get the absolute pathname */
@@ -779,32 +783,32 @@ gtk_rc_context_parse_one_file (GtkRcContext *context,
          rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
          g_free (cwd);
        }
+      
+      rc_file->directory = g_path_get_dirname (rc_file->canonical_name);
     }
 
+  /* If the file is already being parsed (recursion), do nothing
+   */
+  if (g_slist_find (current_files_stack, rc_file))
+    return;
+
   if (!lstat (rc_file->canonical_name, &statbuf))
     {
       gint fd;
-      GSList *tmp_list;
-
+      
       rc_file->mtime = statbuf.st_mtime;
 
       fd = open (rc_file->canonical_name, O_RDONLY);
       if (fd < 0)
        goto out;
 
-      /* Temporarily push directory name for this file on
-       * a stack of directory names while parsing it
+      /* Temporarily push information for this file on
+       * a stack of current files while parsing it.
        */
-      rc_dir_stack = 
-       g_slist_prepend (rc_dir_stack,
-                        g_path_get_dirname (rc_file->canonical_name));
+      current_files_stack = g_slist_prepend (current_files_stack, rc_file);
       gtk_rc_parse_any (context, filename, fd, NULL);
-      tmp_list = rc_dir_stack;
-      rc_dir_stack = rc_dir_stack->next;
-      g_free (tmp_list->data);
-      g_slist_free_1 (tmp_list);
+      current_files_stack = g_slist_delete_link (current_files_stack,
+                                                current_files_stack);
 
       close (fd);
     }
@@ -836,15 +840,11 @@ gtk_rc_context_parse_file (GtkRcContext *context,
   gchar *locale_suffixes[2];
   gint n_locale_suffixes = 0;
   gchar *p;
-  const gchar *locale;
+  gchar *locale;
   gint length, j;
   gboolean found = FALSE;
 
-#ifdef G_OS_WIN32      
-  locale = g_win32_getlocale ();
-#else      
-  locale = setlocale (LC_CTYPE, NULL);
-#endif      
+  locale = _gtk_get_lc_ctype ();
 
   if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
     {
@@ -869,6 +869,8 @@ gtk_rc_context_parse_file (GtkRcContext *context,
          locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
        }
     }
+
+  g_free (locale);
   
   gtk_rc_context_parse_one_file (context, filename, priority, reload);
   for (j = 0; j < n_locale_suffixes; j++)
@@ -1467,6 +1469,7 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings,
 
          if (rc_file->canonical_name != rc_file->name)
            g_free (rc_file->canonical_name);
+         g_free (rc_file->directory);
          g_free (rc_file->name);
          g_free (rc_file);
 
@@ -2283,7 +2286,7 @@ gtk_rc_parse_assignment (GScanner      *scanner,
     case G_TOKEN_LEFT_BRACE:
       if (!negate)
        {
-         GString *gstring = g_string_new ("");
+         GString *gstring = g_string_new (NULL);
 
          token = rc_parse_token_or_compound (scanner, gstring, 0);
          if (token == G_TOKEN_NONE)
@@ -2348,10 +2351,11 @@ parse_include_file (GtkRcContext *context,
        * so we can give meaningful error messages, and because on reparsing
        * non-absolute paths don't make sense.
        */
-      GSList *tmp_list = rc_dir_stack;
+      GSList *tmp_list = current_files_stack;
       while (tmp_list)
        {
-         gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
+         GtkRcFile *curfile = tmp_list->data;
+         gchar *tmpname = g_build_filename (curfile->directory, filename, NULL);
 
          if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
            {
@@ -3003,10 +3007,11 @@ gtk_rc_find_pixmap_in_path (GtkSettings  *settings,
        return filename;
     }
  
-  tmp_list = rc_dir_stack;
+  tmp_list = current_files_stack;
   while (tmp_list)
     {
-      filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
+      GtkRcFile *curfile = tmp_list->data;
+      filename = gtk_rc_check_pixmap_dir (curfile->directory, pixmap_file);
       if (filename)
        return filename;
        
@@ -3647,17 +3652,32 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
 
   token = g_scanner_get_next_token (scanner);
   
-  if (token != G_TOKEN_STRING)
+  if (token != G_TOKEN_STRING && token != '@')
     return G_TOKEN_STRING;
-
   
   source = gtk_icon_source_new ();
-  
-  full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
-  if (full_filename)
+
+  if (token == G_TOKEN_STRING)
+    {
+      /* Filename */
+      
+      full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
+      if (full_filename)
+       {
+         gtk_icon_source_set_filename (source, full_filename);
+         g_free (full_filename);
+       }
+    }
+  else
     {
-      gtk_icon_source_set_filename (source, full_filename);
-      g_free (full_filename);
+      /* Icon name */
+      
+      token = g_scanner_get_next_token (scanner);
+  
+      if (token != G_TOKEN_STRING)
+       return G_TOKEN_STRING;
+
+      gtk_icon_source_set_icon_name (source, scanner->value.v_string);
     }
 
   /* We continue parsing even if we didn't find the pixmap so that rest of the
@@ -3793,7 +3813,8 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
     }
 
  done:
-  if (gtk_icon_source_get_filename (source))
+  if (gtk_icon_source_get_filename (source) ||
+      gtk_icon_source_get_icon_name (source))
     {
       gtk_icon_set_add_source (icon_set, source);
       *icon_set_valid = TRUE;