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

Re: gEDA-user: An opportunity to fix the symbol library



Kai-Martin:
> Stephen Trier wrote:
> > Kai, try (component-library-search"/home/..snip../symbols"
> Unfortunately, it works only for the first layer. Symbols in 
> ../symbols/analog/diode are still ignored. In other words: gschem 
> does not descend recursively into sub dirs. 

If you are brave, you can try the attached patch.

Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57

diff --git a/libgeda/src/g_rc.c b/libgeda/src/g_rc.c
index e287da7..588a582 100644
--- a/libgeda/src/g_rc.c
+++ b/libgeda/src/g_rc.c
@@ -541,13 +541,14 @@ SCM g_rc_component_library_funcs (SCM listfunc, SCM getfunc, SCM name)
  *  \param [in] path  
  *  \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
  */
-SCM g_rc_component_library_search(SCM path)
-{
+int C_g_rc_component_library_search(gchar *string, gchar *name, GRegex *regex);
+SCM g_rc_component_library_search(SCM path) {
   gchar *string;
   char *temp;
-  GDir *dir;
-  const gchar *entry;
-  
+  int ix;
+  const char pattern[] = "\\.sym$";
+  GRegex *regex;
+
   SCM_ASSERT (scm_is_string (path), path,
               SCM_ARG1, "component-library-search");
 
@@ -556,13 +557,29 @@ SCM g_rc_component_library_search(SCM path)
   string = s_expand_env_variables (temp);
   free (temp);
 
+  regex = g_regex_new (pattern, G_REGEX_CASELESS | G_REGEX_OPTIMIZE, 0, NULL);
+  ix = C_g_rc_component_library_search(string, NULL, regex);
+  g_regex_unref (regex);
+
+  g_free(string);
+
+  if (ix < 0) return SCM_BOOL_F;
+  else return SCM_BOOL_T;
+}
+
+int C_g_rc_component_library_search(gchar *string, gchar *name, GRegex *regex)
+{
+  GDir *dir;
+  const gchar *entry;
+  int have_sym = 0;
+
   /* invalid path? */
   if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
     fprintf (stderr,
              "Invalid path [%s] passed to component-library-search\n",
              string);
-    g_free(string);
-    return SCM_BOOL_F;
+    //g_free(string);
+    return -1;
   }
 
   dir = g_dir_open (string, 0, NULL);
@@ -570,37 +587,48 @@ SCM g_rc_component_library_search(SCM path)
     fprintf (stderr,
              "Invalid path [%s] passed to component-library-search\n",
              string);
-    g_free(string);
-    return SCM_BOOL_F;
+    //g_free(string);
+    return -1;
   }
 
   while ((entry = g_dir_read_name (dir))) {
     /* don't do . and .. and special case font */
-    if ((g_strcasecmp (entry, ".")    != 0) && 
-        (g_strcasecmp (entry, "..")   != 0) &&
-        (g_strcasecmp (entry, "font") != 0))
-    {
+    if ((g_strcasecmp (entry, ".")    == 0) && 
+        (g_strcasecmp (entry, "..")   == 0) &&
+        (g_strcasecmp (entry, "CVS")   == 0) &&
+        (g_strcasecmp (entry, "font") == 0)) continue;
+
+    if ( g_regex_match (regex, entry, 0, NULL) == TRUE ) {
+      have_sym++;
+    } else {
       gchar *fullpath = g_build_filename (string, entry, NULL);
+      gchar *entry_name;
+
+      if (name == NULL) entry_name = g_strconcat("cvs_", entry, NULL);
+      else entry_name = g_strconcat(name, "_", entry, NULL);
 
       if (g_file_test (fullpath, G_FILE_TEST_IS_DIR)) {
         if (g_path_is_absolute (fullpath)) {
-          s_clib_add_directory (fullpath, NULL);
+	  if (C_g_rc_component_library_search(fullpath, entry_name, regex) > 0)
+	    s_clib_add_directory (fullpath, entry_name);
         } else {
           gchar *cwd = g_get_current_dir ();
           gchar *temp;
           temp = g_build_filename (cwd, fullpath, NULL);
-          s_clib_add_directory (temp, NULL);
+	  if (C_g_rc_component_library_search(temp, entry_name, regex) > 0)
+	    s_clib_add_directory (temp, entry_name);
           g_free(temp);
           g_free(cwd);
         }
       }
       g_free(fullpath);
+      g_free(entry_name);
     }
   }
 
-  g_free(string);
+  //g_free(string);
 
-  return SCM_BOOL_T;
+  return have_sym;
 }
 
 /*! \todo Finish function description!!!

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