rpms/libassetml/devel libassetml-gcompris.patch, NONE, 1.1 libassetml.spec, 1.1, 1.2

Hans de Goede (jwrdegoede) fedora-extras-commits at redhat.com
Fri Apr 21 08:11:43 UTC 2006


Author: jwrdegoede

Update of /cvs/extras/rpms/libassetml/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv25115

Modified Files:
	libassetml.spec 
Added Files:
	libassetml-gcompris.patch 
Log Message:
* Mon Apr 17 2006 Hans de Goede <j.w.r.degoede at hhs.nl> 1.2.1-2
- Add libassetml-gcompris.patch which adds a couple of fixes found in the
  version of libassetml as shipped with gcompris. Which is BTW currently our
  only user. Notice that this version is much less (annoyingly) verbose then
  the version bundled with gcompris.


libassetml-gcompris.patch:

--- NEW FILE libassetml-gcompris.patch ---
--- libassetml-1.2.1/src/assetml.c.gcompris	2003-10-07 13:22:37.000000000 +0200
+++ libassetml-1.2.1/src/assetml.c	2006-04-21 00:14:57.000000000 +0200
@@ -17,6 +17,7 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include "glib.h"
 #include "assetml.h"
 #include <config.h>
 
@@ -25,32 +26,37 @@
 #include <libxml/parser.h>
 
 #include <locale.h>
-#include <dirent.h>
 #include <string.h>
 
 #define FILE_EXT ".assetml"
 
-gchar	*assetml_get_locale(void);
-gchar	*reactivate_newline(gchar *str);
-void	 dump_asset(AssetML *assetml);
-int	 selectAssetML(const struct dirent *d);
-void	 assetml_read_xml_file(GList **gl_result, char *fname,
-			       gchar *dataset, gchar* categories, gchar* mimetype, gchar *locale, gchar* file);
-void	 assetml_load_xml(GList **gl_result, gchar *dataset, gchar* categories, gchar* mimetype, 
-			  gchar* locale, gchar* file);
-void	 free_asset(AssetML *assetml);
+const gchar	*assetml_get_locale(void);
+static gchar	*reactivate_newline(gchar *str);
+int		 selectAssetML(const gchar *dirent);
+void		 assetml_read_xml_file(GList **gl_result, char *fname,
+				       gchar *dataset, gchar* categories, gchar* mimetype, 
+				       const gchar *locale, gchar* file);
+void		 assetml_load_xml(GList **gl_result, gchar *dataset, gchar* categories, 
+				  gchar* mimetype, 
+				  const gchar* locale, gchar* file);
+void		 free_asset(AssetML *assetml);
+
+GHashTable *asset_cache = NULL;
 
 /*
  * This returns the locale for which text must be displayed
  *
  */
-gchar *assetml_get_locale()
+const gchar *assetml_get_locale()
 {
-  char *locale;
+  const char *locale;
 
-  locale = getenv("LC_ALL");
+  locale = g_getenv("LC_ALL");
+  if(locale == NULL)
+    locale = g_getenv("LC_MESSAGES");
   if(locale == NULL)
-    locale = getenv("LANG");
+    locale = g_getenv("LANG");
+
 
   if(locale!=NULL)
     return(locale);
@@ -65,7 +71,7 @@
  * \f \n \r \t \\ \" and the octal format.
  * 
  */
-gchar *reactivate_newline(gchar *str)
+static gchar *reactivate_newline(gchar *str)
 {
   gchar *newstr;
 
@@ -79,24 +85,6 @@
   return newstr;
 }
 
-void dump_asset(AssetML *assetml)
-{
-
-  printf("Dump Asset\n");
-
-  if(assetml==NULL)
-    return;
-
-  printf("  dataset     = %s\n",assetml->dataset);
-  printf("  file        = %s\n",assetml->file);
-  printf("  locale      = %s\n",assetml->locale);
-  printf("  description = %s\n",assetml->description);
-  printf("  categories  = %s\n",assetml->categories);
-  printf("  mimetype    = %s\n",assetml->mimetype);
-  printf("  credits     = %s\n",assetml->credits);
-
-}
-
 /*
  * Thanks for George Lebl <jirka at 5z.com> for his Genealogy example
  * for all the XML stuff there
@@ -131,6 +119,14 @@
     assetml->file		= NULL;
   xmlFree(tmpstr);
 
+  tmpstr = xmlGetProp(xmlnode,"name");
+  if(tmpstr && strlen(tmpstr)>0)
+  assetml->name		= g_strdup(tmpstr);
+  else
+    assetml->name		= g_path_get_basename(assetml->file);
+  xmlFree(tmpstr);
+
+
   tmpstr = xmlGetProp(xmlnode,"mimetype");
   if(tmpstr && strlen(tmpstr)>0)
   assetml->mimetype		= g_strdup(tmpstr);
@@ -138,6 +134,8 @@
     assetml->mimetype		= NULL;
   xmlFree(tmpstr);
 
+
+
   xmlnode = xmlnode->xmlChildrenNode;
   while (xmlnode != NULL) {
     gchar *lang = xmlGetProp(xmlnode,"lang");
@@ -185,22 +183,29 @@
  */
 static gboolean matching(AssetML *assetml, gchar *mydataset, 
 			 gchar *dataset, gchar* categories, gchar* mimetype, 
-			 gchar* mylocale, gchar* locale, gchar* file)
+			 const gchar* mylocale, const gchar* locale, gchar* name)
 {
   g_assert(assetml);
 
-  assetml->dataset = g_strdup(mydataset);
+  if (!assetml->locale)
+    assetml->locale = g_strdup(mylocale);
+  if (!assetml->dataset)
+    assetml->dataset = g_strdup(mydataset);
+
   if(assetml->dataset && dataset)
     if(g_ascii_strcasecmp(assetml->dataset, dataset))
       return FALSE;
 
+
   /* Check the leading locale definition matches the leading user request so that
    * File   Requested   Status
    * fr     fr_FR.UTF8  OK
    * pt     pt_BR       OK
    * pt_BR  pt          NO
    */
-  assetml->locale = g_strdup(mylocale);
+  if (!assetml->locale)
+    assetml->locale = g_strdup(mylocale);
+
   if(assetml->locale && locale)
     if(g_ascii_strncasecmp(assetml->locale, locale, strlen(assetml->locale)))
       return FALSE;
@@ -209,12 +214,16 @@
     if(g_ascii_strcasecmp(assetml->mimetype, mimetype))
       return FALSE;
 
-  if(assetml->file && file)
+  if(assetml->name && name)
+    if(g_ascii_strcasecmp(assetml->name, name))
+      return FALSE;
+
+/*  if(assetml->file && file)
     {
       gchar *str1;
       gchar *str2;
       gboolean nomatch;
-      /* We test only the basename of the file so that caller do not need to specify a full path */
+//      We test only the basename of the file so that caller do not need to specify a full path 
       str1 = g_path_get_basename(assetml->file);
       str2 = g_path_get_basename(file);
 
@@ -225,7 +234,7 @@
 
       if(nomatch)
 	return FALSE;
-    }
+    }*/
 
   if(assetml->categories && categories)
     {
@@ -247,8 +256,21 @@
 static void
 parse_doc(GList **gl_result, xmlDocPtr doc, 
 	  gchar *mydataset, gchar *rootdir, gchar* mylocale,
-	  gchar *dataset, gchar* categories, gchar* mimetype, gchar* locale, gchar* file)
+	  gchar *dataset, gchar* categories, gchar* mimetype, const gchar* locale, gchar* file, GList **cache)
 {
+  if (*cache){
+    GList *list;
+
+    for (list= *cache; list != NULL; list=list->next){
+      AssetML *assetml = (AssetML *) list->data;
+      
+      if (matching(assetml, mydataset, dataset, categories, 
+		   mimetype, mylocale, locale, file))
+	*gl_result = g_list_append (*gl_result, assetml);
+    }
+    return;
+  }
+
   xmlNodePtr node;
 
   /* find <Asset> nodes and add them to the list, this just
@@ -258,20 +280,28 @@
        we pass NULL as the node of the child */
     AssetML *assetml = assetml_add_xml_to_data(doc, node, rootdir, NULL);
 
-    if(assetml && matching(assetml, mydataset, dataset, categories, mimetype, mylocale, locale, file))
+    if(assetml && matching(assetml, mydataset, dataset, categories, 
+			   mimetype, mylocale, locale, file))
       *gl_result = g_list_append (*gl_result, assetml);
-				
+
+    if (assetml)
+      *cache = g_list_append( *cache,  assetml);
+
   }
 }
 
-
+void assetml_real_free_assetlist(GList *assetlist)
+{
+  g_list_foreach (assetlist, (GFunc) free_asset, NULL);
+  g_list_free(assetlist);
+}
 
 /* read an xml file into our memory structures and update our view,
    dump any old data we have in memory if we can load a new set
    Fill the gl_result list with all matching asseml items
 */
 void assetml_read_xml_file(GList **gl_result, char *assetmlfile,
-			   gchar *dataset, gchar* categories, gchar* mimetype, gchar *locale, gchar* file)
+			   gchar *dataset, gchar* categories, gchar* mimetype, const gchar *locale, gchar* file)
 {
   /* pointer to the new doc */
   xmlDocPtr doc;
@@ -279,82 +309,109 @@
   gchar *mylocale;
   gchar *mydataset;
 
+  GList *cache = NULL;
+
   g_return_if_fail(assetmlfile!=NULL);
 
+  /* cache asset for performance in non direct search */
+  if (!asset_cache){
+    asset_cache = g_hash_table_new_full( g_str_hash,
+					 g_str_equal,
+					 g_free,
+					 (GDestroyNotify) assetml_free_assetlist
+					 );
+  }
+
+  cache = g_hash_table_lookup (asset_cache, assetmlfile);
+
   /* parse the new file and put the result into newdoc */
-  doc = xmlParseFile(assetmlfile);
+  if (! cache){
+    doc = xmlParseFile(assetmlfile);
 
-  /* in case something went wrong */
-  if(!doc) {
-    g_warning("Oups, the parsing of %s failed", assetmlfile);
-    return;
-  }
-  
-  if(/* if there is no root element */
-     !doc->children ||
-     /* if it doesn't have a name */
-     !doc->children->name ||
-     /* if it isn't a Assetml node */
-     g_strcasecmp(doc->children->name,"AssetML")!=0) 
-    {
-      xmlFreeDoc(doc);
-      g_warning("Oups, the file %s is not of the assetml type", assetmlfile);
+    /* in case something went wrong */
+    if(!doc) {
+      g_warning("Oups, the parsing of %s failed", assetmlfile);
       return;
     }
+  
+    if(/* if there is no root element */
+       !doc->children ||
+       /* if it doesn't have a name */
+       !doc->children->name ||
+       /* if it isn't a Assetml node */
+       g_strcasecmp(doc->children->name,"AssetML")!=0) 
+      {
+	xmlFreeDoc(doc);
+	g_warning("Oups, the file %s is not of the assetml type", assetmlfile);
+	return;
+      }
+
+    rootdir   = xmlGetProp(doc->children,"rootdir");
+    mydataset = xmlGetProp(doc->children,"dataset");
+    mylocale  = xmlGetProp(doc->children,"locale");
+  }
+  else {
+    AssetML *myasset = (AssetML *) cache->data;
 
-  rootdir   = xmlGetProp(doc->children,"rootdir");
-  mydataset = xmlGetProp(doc->children,"dataset");
-  mylocale    = xmlGetProp(doc->children,"locale");
+    mylocale = myasset->locale;
+    mydataset = myasset->dataset;
+    rootdir = NULL;
+  }
 
   /* parse our document and replace old data */
-  parse_doc(gl_result, doc, mydataset, rootdir, mylocale, dataset, categories, mimetype, locale, file);
+  parse_doc(gl_result, doc, mydataset, rootdir, mylocale, dataset, categories, mimetype, locale, file, &cache);
 
-  xmlFree(rootdir);
-  xmlFree(mydataset);
+  if (rootdir)
+    g_hash_table_replace( asset_cache, g_strdup(assetmlfile), cache);
 
-  xmlFreeDoc(doc);
+  if (rootdir){
+    xmlFree(rootdir);
+    xmlFree(mydataset);
+    xmlFreeDoc(doc);
+  }
 }
 
 
 /*
  * Select only files with FILE_EXT
  */
-int selectAssetML(const struct dirent *d)
+int selectAssetML(const gchar *dirent)
 {
-  gchar *file = ((struct dirent *)d)->d_name;
   guint ext_length = strlen(FILE_EXT);
 
-  if(strlen(file)<ext_length)
+  if(strlen(dirent)<ext_length)
     return 0;
 
-  return (strncmp (&file[strlen(file)-ext_length], FILE_EXT, ext_length) == 0);
+  return (strncmp (&dirent[strlen(dirent)-ext_length], FILE_EXT, ext_length) == 0);
 }
 
 /* load all the xml files in the assetml path
  * into our memory structures.
  */
-void assetml_load_xml(GList **gl_result, gchar *dataset, gchar* categories, gchar* mimetype, gchar *locale, 
+void assetml_load_xml(GList **gl_result, gchar *dataset, gchar* categories, gchar* mimetype, const gchar *locale, 
 		      gchar* name)
 {
-  struct dirent **namelist;
-  int n;
+  const gchar  *one_dirent;
+  GDir    *dir;
 
-  n = scandir(ASSETML_DIR, &namelist, &selectAssetML, 0);
+  dir = g_dir_open(ASSETML_DIR, 0, NULL);
+  if(!dir) {
+    g_warning("opendir returns no files with extension %s in directory %s", FILE_EXT, ASSETML_DIR);
+    return;
+  }
 
-  if (n <= 0)
-    g_warning("scandir returns no files with extension %s in directory %s", FILE_EXT, ASSETML_DIR);
-  else {
-    while(n--) {
-      gchar *assetmlfile = g_strdup_printf("%s/%s", ASSETML_DIR, namelist[n]->d_name);
+  while((one_dirent = g_dir_read_name(dir)) != NULL) {
+
+    if(strstr(one_dirent, FILE_EXT)) {
+      gchar *assetmlfile = g_strdup_printf("%s/%s", ASSETML_DIR, one_dirent);
       
       assetml_read_xml_file(gl_result, assetmlfile,
-      			    dataset, categories, mimetype, locale, name);
+			    dataset, categories, mimetype, locale, name);
       
       g_free(assetmlfile);
-      free (namelist [n]);
     }
-    free (namelist);
   }
+  g_dir_close(dir);
 }
 
 
@@ -367,6 +424,7 @@
   xmlFree(assetml->description);
   xmlFree(assetml->categories);
   xmlFree(assetml->file);
+  xmlFree(assetml->name);
   xmlFree(assetml->mimetype);
   xmlFree(assetml->credits);
 
@@ -375,29 +433,25 @@
 
 void assetml_free_assetlist(GList *assetlist)
 {
-  g_list_foreach (assetlist, (GFunc) free_asset, NULL);
+  /* does not  free assets because cache */
+  //g_list_foreach (assetlist, (GFunc) free_asset, NULL);
   g_list_free(assetlist);
-
-
 }
 
-GList*	 assetml_get_asset(gchar *dataset, gchar* categories, gchar* mimetype, gchar *locale, gchar* file)
+GList*	 assetml_get_asset(gchar *dataset, gchar* categories, gchar* mimetype, const gchar *locale, gchar* file)
 {
   GList *gl_result = NULL;
 
   assetml_load_xml(&gl_result, dataset, categories, mimetype, locale, file);
 
-  if(g_list_length(gl_result)==0)
+  if(gl_result && g_list_length(gl_result)==0)
     {
       g_list_free(gl_result);
-      return NULL;
-    }
-  else
-    {
-#ifdef DEBUG
-      printf("Dumping return value of assetml_get_asset\n");
-      g_list_foreach (gl_result, (GFunc) dump_asset, NULL);
-#endif
-      return gl_result;
+      gl_result = NULL;
     }
+
+  if (!gl_result)
+    g_warning("assetml_get_asset file=%s: no match\n", file);
+
+  return gl_result;
 }
--- libassetml-1.2.1/src/assetml.h.gcompris	2003-10-07 13:22:37.000000000 +0200
+++ libassetml-1.2.1/src/assetml.h	2006-04-21 00:13:16.000000000 +0200
@@ -35,7 +35,7 @@
    \param locale is the locale to search for or NULL for the current locale
    \param file the asset file name to get or NULL for any file name
 */
-GList*	 assetml_get_asset(gchar *dataset, gchar* categories, gchar* mimetype, gchar* locale, gchar* name);
+GList*	 assetml_get_asset(gchar *dataset, gchar* categories, gchar* mimetype, const gchar* locale, gchar* name);
 
 
 void	 assetml_free_assetlist(GList *assetlist);
@@ -49,6 +49,7 @@
   gchar		*locale;
   gchar		*description;
   gchar		*file;
+  gchar		*name;
   gchar		*mimetype;
   gchar		*credits;
 };


Index: libassetml.spec
===================================================================
RCS file: /cvs/extras/rpms/libassetml/devel/libassetml.spec,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- libassetml.spec	15 Apr 2006 13:41:24 -0000	1.1
+++ libassetml.spec	21 Apr 2006 08:11:43 -0000	1.2
@@ -1,11 +1,12 @@
 Name:		libassetml
 Version: 	1.2.1
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        XML resource database library
 Group:          System Environment/Libraries
 License:	GPL  
 URL:		http://sourceforge.net/projects/ofset/
 Source0:        http://download.sourceforge.net/ofset/%{name}-%{version}.tar.gz
+Patch0:         libassetml-gcompris.patch
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildRequires:	glib2-devel libxml2-devel texinfo texi2html
 
@@ -31,6 +32,7 @@
 
 %prep
 %setup -q
+%patch -p1 -z .gcompris
 # make rpmlint happy
 chmod -x src/tools/assetml-query.c
 
@@ -84,5 +86,11 @@
 
 
 %changelog
+* Mon Apr 17 2006 Hans de Goede <j.w.r.degoede at hhs.nl> 1.2.1-2
+- Add libassetml-gcompris.patch which adds a couple of fixes found in the
+  version of libassetml as shipped with gcompris. Which is BTW currently our
+  only user. Notice that this version is much less (annoyingly) verbose then
+  the version bundled with gcompris.
+
 * Mon Apr 10 2006 Hans de Goede <j.w.r.degoede at hhs.nl> 1.2.1-1
 - Initial spec file




More information about the fedora-extras-commits mailing list