[glib] Read the new glob2 format with case sensitive flags



commit ce239a010e29c91f683dae354060f6ec6213e148
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Oct 2 09:46:33 2009 +0200

    Read the new glob2 format with case sensitive flags

 gio/xdgmime/xdgmime.c     |    4 +-
 gio/xdgmime/xdgmimeglob.c |   83 ++++++++++++++++++++++++++++++++------------
 gio/xdgmime/xdgmimeglob.h |    6 ++-
 3 files changed, 66 insertions(+), 27 deletions(-)
---
diff --git a/gio/xdgmime/xdgmime.c b/gio/xdgmime/xdgmime.c
index c9bcfba..0888583 100644
--- a/gio/xdgmime/xdgmime.c
+++ b/gio/xdgmime/xdgmime.c
@@ -165,7 +165,7 @@ xdg_mime_init_from_directory (const char *directory)
   strcpy (file_name, directory); strcat (file_name, "/mime/globs2");
   if (stat (file_name, &st) == 0)
     {
-      _xdg_mime_glob_read_from_file (global_hash, file_name);
+      _xdg_mime_glob_read_from_file (global_hash, file_name, TRUE);
       xdg_dir_time_list_add (file_name, st.st_mtime);
     }
   else
@@ -175,7 +175,7 @@ xdg_mime_init_from_directory (const char *directory)
       strcpy (file_name, directory); strcat (file_name, "/mime/globs");
       if (stat (file_name, &st) == 0)
         {
-          _xdg_mime_glob_read_from_file (global_hash, file_name);
+          _xdg_mime_glob_read_from_file (global_hash, file_name, FALSE);
           xdg_dir_time_list_add (file_name, st.st_mtime);
         }
       else
diff --git a/gio/xdgmime/xdgmimeglob.c b/gio/xdgmime/xdgmimeglob.c
index d7c79b1..392eaab 100644
--- a/gio/xdgmime/xdgmimeglob.c
+++ b/gio/xdgmime/xdgmimeglob.c
@@ -493,7 +493,8 @@ void
 _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash,
 			    const char  *glob,
 			    const char  *mime_type,
-			    int          weight)
+			    int          weight,
+			    int          case_sensitive)
 {
   XdgGlobType type;
 
@@ -555,10 +556,12 @@ _xdg_glob_hash_dump (XdgGlobHash *glob_hash)
 
 void
 _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash,
-			       const char  *file_name)
+			       const char  *file_name,
+			       int          version_two)
 {
   FILE *glob_file;
   char line[255];
+  char *p;
 
   glob_file = fopen (file_name, "r");
 
@@ -569,33 +572,67 @@ _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash,
    * Blah */
   while (fgets (line, 255, glob_file) != NULL)
     {
-      char *colon, *colon2;
-      char *mimetype, *glob;
+      char *colon;
+      char *mimetype, *glob, *end;
       int weight;
+      int case_sensitive;
 
-      if (line[0] == '#')
+      if (line[0] == '#' || line[0] == 0)
 	continue;
 
-      colon = strchr (line, ':');
+      end = line + strlen(line) - 1;
+      if (*end == '\n')
+	*end = 0;
+
+      p = line;
+      if (version_two)
+	{
+	  colon = strchr (p, ':');
+	  if (colon == NULL)
+	    continue;
+	  *colon = 0;
+          weight = atoi (p);
+	  p = colon + 1;
+	}
+      else
+	weight = 50;
+
+      colon = strchr (p, ':');
       if (colon == NULL)
 	continue;
-      *(colon++) = '\0';
-      colon[strlen (colon) -1] = '\0';
-      colon2 = strchr (colon, ':');
-      if (colon2) 
-        {
-          *(colon2++) = '\000';
-          weight = atoi (line);
-          mimetype = colon;
-          glob = colon2;
-        }
-      else 
-        {
-          weight = 50;
-          mimetype = line;
-          glob = colon;
-        }
-      _xdg_glob_hash_append_glob (glob_hash, glob, mimetype, weight);
+      *colon = 0;
+
+      mimetype = p;
+      p = colon + 1;
+      glob = p;
+      case_sensitive = FALSE;
+
+      colon = strchr (p, ':');
+      if (version_two && colon != NULL)
+	{
+	  char *flag;
+
+	  /* We got flags */
+	  *colon = 0;
+	  p = colon + 1;
+
+	  /* Flags end at next colon */
+	  colon = strchr (p, ':');
+	  if (colon != NULL)
+	    *colon = 0;
+
+	  flag = strstr (p, "cs");
+	  if (flag != NULL &&
+	      /* Start or after comma */
+	      (flag == p ||
+	       flag[-1] == ',') &&
+	      /* ends with comma or end of string */
+	      (flag[2] == 0 ||
+	       flag[2] == ','))
+	    case_sensitive = TRUE;
+	}
+
+      _xdg_glob_hash_append_glob (glob_hash, glob, mimetype, weight, case_sensitive);
     }
 
   fclose (glob_file);
diff --git a/gio/xdgmime/xdgmimeglob.h b/gio/xdgmime/xdgmimeglob.h
index df8dc79..0018292 100644
--- a/gio/xdgmime/xdgmimeglob.h
+++ b/gio/xdgmime/xdgmimeglob.h
@@ -51,7 +51,8 @@ typedef enum
 #endif
 
 void         _xdg_mime_glob_read_from_file   (XdgGlobHash *glob_hash,
-					      const char  *file_name);
+					      const char  *file_name,
+					      int          version_two);
 XdgGlobHash *_xdg_glob_hash_new              (void);
 void         _xdg_glob_hash_free             (XdgGlobHash *glob_hash);
 int          _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
@@ -61,7 +62,8 @@ int          _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
 void         _xdg_glob_hash_append_glob      (XdgGlobHash *glob_hash,
 					      const char  *glob,
 					      const char  *mime_type,
-					      int          weight);
+					      int          weight,
+					      int          case_sensitive);
 XdgGlobType  _xdg_glob_determine_type        (const char  *glob);
 void         _xdg_glob_hash_dump             (XdgGlobHash *glob_hash);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]