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

gEDA-user: cvs.gedasymbols.org and gschem



There are a lot of symbols available at cvs.gedasymbols.org.

To make them all available to gschem I have added:

(component-library-search "${HOME}/Net/cvs/cvs.gedasymbols.org/www/user")

to my ~/.gEDA/gafrc, and changed component-library-search to descend
into subdirectories (see diff).

The result is as seen in attachment (dump.jpg).

///

The code that executes the ...-search command is in libgeda/src/g_rc.c
(relative the top of the git repo.), in the function:

 SCM g_rc_component_library_search(SCM path);

I have changed that function to a wrapper around

 int C_g_rc_component_library_search(gchar *string, gchar *name, GRegex *regex);

which can be more easily called recursively within c. That function
contains the main body of the former function. Its added parameters
are "name" and "regex". regex is simply a precompiled regular
expression matching file names ending in ".sym" (since we don't want to
have entries that doesn't contain any symbol files). Name's function
is described below under the code snippet.

The function that does the acutual "adding" to the library list is:

 s_clib_add_directory (fullpath, entry_name);

It takes as first parameter the name of the file. The second parameter,
which was NULL previuosly, is the actual text that will be visible
in the library browser (defults to basename of "fullpath".

I have added code so it will look like
"cvs/kai_martin_knaak/symbols/analog/diode" when given the above
command in gafrc. The prefix "cvs/", is not suitable for other such
commands (maybe the ...-search could take a second parameter to set
the prefix).

The actual proposed code is:

  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, "CVS")   == 0) &&
        (g_strcasecmp (entry, "font") == 0)) continue;

    if ( g_regex_match (regex, entry, 0, NULL) == TRUE ) {
A:     have_sym++;
    } else {
      gchar *fullpath = g_build_filename (string, entry, NULL);
      gchar *entry_name;

B:     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)) {
C:	  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);
	  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);
    }
  }

The loop goes through all files in "dir".

If the file (named "entry" above) is a directory, it check that directory
(at C, with the call C_g_rc_component_li...) to see if it contains any
symbol files (the test is done at A). If the directory contains one or
more symbol files, a line i added for the library browser.
As a bonus, it will go through that subdirectory and add any dir's there
to the browsers list, etc...

Since many directories with symbols in them happen to be named
"symbols", a mean to differentiate between them is needed. For that
I have added the parameter "name" to the function call, so I can use
it as a prefix for what enters into the browser list. That is happening
at B.

///

As for the test case of gedasymbols, it seems to do its job, though
there are a few points that is not resolved:

. should we change component-library-search, or create a new call
  for this

. the prefix added (at B, "cvs/") is not suitable for general use
  how should one tell the program which prefix to use

Regards,
/Karl Hammar

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



Attachment: dump.jpg
Description: dump.jpg

diff --git a/libgeda/src/g_rc.c b/libgeda/src/g_rc.c
index e287da7..bc48270 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,28 @@ 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;
+    return -1;
   }
 
   dir = g_dir_open (string, 0, NULL);
@@ -570,37 +586,45 @@ 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;
+    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);
-
-  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