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

gEDA-cvs: CVS update: s_clib.c



  User: peterb  
  Date: 07/05/28 03:50:39

  Modified:    .        s_clib.c
  Log:
  Sort lists of component sources and symbols.
  
  
  
  Adds functions to compare sources and symbols by name
  
  case-insensitively, and makes the both s_clib_source_get_symbols() and
  
  s_clib_get_sources() return lists sorted by name.
  
  
  
  
  Revision  Changes    Path
  1.22                 eda/geda/gaf/libgeda/src/s_clib.c
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: s_clib.c
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/libgeda/src/s_clib.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -b -r1.21 -r1.22
  --- s_clib.c	28 May 2007 07:46:11 -0000	1.21
  +++ s_clib.c	28 May 2007 07:50:39 -0000	1.22
  @@ -196,6 +196,8 @@
   
   static void free_symbol (gpointer data, gpointer user_data);
   static void free_source (gpointer data, gpointer user_data);
  +static gint compare_source_name (gconstpointer a, gconstpointer b);
  +static gint compare_symbol_name (gconstpointer a, gconstpointer b);
   static gchar *run_source_command (gchar **argv);
   static CLibSymbol *source_has_symbol (const CLibSource *source, 
   				      const gchar *name);
  @@ -275,6 +277,57 @@
     }
   }
   
  +/*! \brief Compare two component sources by name.
  + *  \par Function Description
  + *  Compare two component sources by name, case-insensitively.
  + *  Typically used when calling g_list_sort().  Private function used
  + *  only in s_clib.c.  Argument order is as strcasecmp().
  + *
  + *  \param a First source to compare
  + *  \param b Second source to compare
  + *
  + *  \return As strcasecmp().
  + */
  +static gint compare_source_name (gconstpointer a, gconstpointer b)
  +{
  +  const CLibSource *src1 = a;
  +  const CLibSource *src2 = b;
  +
  +  g_assert (src1 != NULL);
  +  g_assert (src2 != NULL);
  +
  +  g_assert (src1->name != NULL);
  +  g_assert (src2->name != NULL);
  +
  +  return strcasecmp(src1->name, src2->name);
  +}
  +
  +/*! \brief Compare two component symbols by name.
  + *  \par Function Description
  + *  Compare two component symbols by name, case-insensitively.
  + *  Typically used when calling g_list_sort().  Private function used
  + *  only in s_clib.c.  Argument order is as strcasecmp().
  + *
  + *  \param a First symbol to compare
  + *  \param b Second symbol to compare
  + *
  + *  \return As strcasecmp().
  + */
  +static gint compare_symbol_name (gconstpointer a, gconstpointer b)
  +{
  +  const CLibSymbol *sym1 = a;
  +  const CLibSymbol *sym2 = b;
  +
  +  g_assert (sym1 != NULL);
  +  g_assert (sym2 != NULL);
  +
  +  g_assert (sym1->name != NULL);
  +  g_assert (sym2->name != NULL);
  +
  +  return strcasecmp(sym1->name, sym2->name);
  +}
  +
  +
   /*! \brief Execute a library command.
    *  \par Function Description
    *  Execute a library command, returning the standard output, or \b
  @@ -346,7 +399,9 @@
    */
   GList *s_clib_get_sources ()
   {
  -  return g_list_copy(clib_sources);
  +  GList *l = g_list_copy(clib_sources);
  +  l = g_list_sort (l, (GCompareFunc) compare_source_name);
  +  return l;
   }
   
   /*! \brief Find any symbols within a source with a given name.
  @@ -435,16 +490,17 @@
       symbol->source = source;
       symbol->name = g_strdup(entry);
   
  -    /* Prepend because it's faster. */
  +    /* Prepend because it's faster and it doesn't matter what order we
  +     * add them. */
       source->symbols = g_list_prepend (source->symbols, symbol);
     }
   
     entry = NULL;
     g_dir_close (dir);
   
  -  /* We prepended each element, so now we have to reverse the whole
  -   * list. */
  -  source->symbols = g_list_reverse (source->symbols);
  +  /* Now sort the list of symbols by name. */
  +  source->symbols = g_list_sort (source->symbols, 
  +				 (GCompareFunc) compare_symbol_name);
   }
   
   /*! \brief Re-poll a library command for symbols.
  @@ -498,16 +554,17 @@
       symbol->source = source;
       symbol->name = name;
   
  -    /* Prepend because it's faster. */
  +    /* Prepend because it's faster and it doesn't matter what order we
  +     * add them. */
       source->symbols = g_list_prepend (source->symbols, symbol);    
     }
   
     s_textbuffer_free (tb);
     g_free (cmdout);
   
  -  /* We prepended each element, so now we have to reverse the whole
  -   * list. */
  -  source->symbols = g_list_reverse (source->symbols);  
  +  /* Sort all symbols by name. */
  +  source->symbols = g_list_sort (source->symbols, 
  +				 (GCompareFunc) compare_symbol_name);
   }
   
   /*! \brief Rescan all available component libraries.
  
  
  


_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs