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

gEDA-cvs: gaf.git: branch: master updated (1.7.0-20110116-36-g6c4b8a7)



The branch, master has been updated
       via  6c4b8a72cd917872709bfb7918f9a1141d9c8548 (commit)
       via  1ac00b2ab05de162319119c389f63e3841303f8e (commit)
       via  a7a0bd24515bef8bcad69ae9321b4a8e5cbba738 (commit)
       via  b3e10e97a110e6976aa3b8d12ea8037bf45f4d2e (commit)
       via  5b1ad217680aeddc4388b513fe2e41f0d9acee21 (commit)
       via  6f705051d3b5b7ae380d0e13ad6fb8f4568066d2 (commit)
      from  eee6b8c11a3bb73c5ea3dd21645c236205da0749 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 utils/src/gsch2pcb.c |  279 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 167 insertions(+), 112 deletions(-)


=================
 Commit Messages
=================

commit 6c4b8a72cd917872709bfb7918f9a1141d9c8548
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: replace g_spawn_* with build_and_run_command
    
    Affects-bug: lp-726828

:100644 100644 cafab3d... 85b7cb3... M	utils/src/gsch2pcb.c

commit 1ac00b2ab05de162319119c389f63e3841303f8e
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: run_gnetlist now uses build_and_run_command
    
    Affects-bug: lp-726828

:100644 100644 3e00b27... cafab3d... M	utils/src/gsch2pcb.c

commit a7a0bd24515bef8bcad69ae9321b4a8e5cbba738
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: helper function build_and_run_command
    
    Add a helper function to build and execute commands without
    relying on shell to split and parse command line.
    
    Affects-bug: lp-726828

:100644 100644 ed8580c... 3e00b27... M	utils/src/gsch2pcb.c

commit b3e10e97a110e6976aa3b8d12ea8037bf45f4d2e
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: keep multiple schematic files in a list
    
    Affects-bug: lp-726828

:100644 100644 5ceb27b... ed8580c... M	utils/src/gsch2pcb.c

commit 5b1ad217680aeddc4388b513fe2e41f0d9acee21
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: support quoting in schematics option
    
    Use g_shell_parse_argv to support spaces in filenames.
    
    Affects-bug: lp-726828

:100644 100644 24b9e06... 5ceb27b... M	utils/src/gsch2pcb.c

commit 6f705051d3b5b7ae380d0e13ad6fb8f4568066d2
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: fix check for filename ending with .sch

:100644 100644 095d400... 24b9e06... M	utils/src/gsch2pcb.c

=========
 Changes
=========

commit 6c4b8a72cd917872709bfb7918f9a1141d9c8548
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: replace g_spawn_* with build_and_run_command
    
    Affects-bug: lp-726828

diff --git a/utils/src/gsch2pcb.c b/utils/src/gsch2pcb.c
index cafab3d..85b7cb3 100644
--- a/utils/src/gsch2pcb.c
+++ b/utils/src/gsch2pcb.c
@@ -889,11 +889,9 @@ add_elements (gchar * pcb_file)
 
   total = n_added_ef + n_added_m4 + n_not_found;
   if (total == 0)
-    command = g_strconcat ("rm ", tmp_file, NULL);
+    build_and_run_command ("rm %s", tmp_file);
   else
-    command = g_strconcat ("mv ", tmp_file, " ", pcb_file, NULL);
-  g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
-  g_free (command);
+    build_and_run_command ("mv %s %s", tmp_file, pcb_file);
   g_free (tmp_file);
   return total;
 }
@@ -945,15 +943,11 @@ update_element_descriptions (gchar * pcb_file, gchar * bak)
   fclose (f_out);
 
   if (!bak_done) {
-    command = g_strconcat ("mv ", pcb_file, " ", bak, NULL);
-    g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
-    g_free (command);
+    build_and_run_command ("mv %s %s", pcb_file, bak);
     bak_done = TRUE;
   }
 
-  command = g_strconcat ("mv ", tmp, " ", pcb_file, NULL);
-  g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
-  g_free (command);
+  build_and_run_command ("mv %s %s", tmp, pcb_file);
   g_free (tmp);
 }
 
@@ -1032,15 +1026,11 @@ prune_elements (gchar * pcb_file, gchar * bak)
   fclose (f_out);
 
   if (!bak_done) {
-    command = g_strconcat ("mv ", pcb_file, " ", bak, NULL);
-    g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
-    g_free (command);
+    build_and_run_command ("mv %s %s", pcb_file, bak);
     bak_done = TRUE;
   }
 
-  command = g_strconcat ("mv ", tmp, " ", pcb_file, NULL);
-  g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
-  g_free (command);
+  build_and_run_command ("mv %s %s", tmp, pcb_file);
   g_free (tmp);
 }
 
@@ -1447,9 +1437,7 @@ main (gint argc, gchar ** argv)
                 sch_basename, schematics);
 
   if (add_elements (pcb_new_file_name) == 0) {
-    tmp = g_strconcat ("rm ", pcb_new_file_name, NULL);
-    g_spawn_command_line_sync (tmp, NULL, NULL, NULL, NULL);
-    g_free (tmp);
+    build_and_run_command ("rm %s", pcb_new_file_name);
     if (initial_pcb) {
       printf ("No elements found, so nothing to do.\n");
       exit (0);

commit 1ac00b2ab05de162319119c389f63e3841303f8e
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: run_gnetlist now uses build_and_run_command
    
    Affects-bug: lp-726828

diff --git a/utils/src/gsch2pcb.c b/utils/src/gsch2pcb.c
index 3e00b27..cafab3d 100644
--- a/utils/src/gsch2pcb.c
+++ b/utils/src/gsch2pcb.c
@@ -200,120 +200,95 @@ static void
 run_gnetlist (gchar * pins_file, gchar * net_file, gchar * pcb_file,
               gchar * basename, GList * largs)
 {
-  gchar *command, *out_file, *args1, *s;
-  GList *list;
   struct stat st;
   time_t mtime;
   static const gchar *gnetlist = NULL;
-  gchar *args = NULL;
-
-  /* Prepend the gnetlist arguments (including the list of schematics)
-   * with those the user has specified with gnetlist-arg directives */
-  if (extra_gnetlist_arg_list || largs) {
-    int count = 0;
-    gchar **str_array =
-      g_new0 (char *,
-              1
-              + g_list_length (extra_gnetlist_arg_list)
-              + g_list_length (largs));
-    for (list = extra_gnetlist_arg_list; list; list = g_list_next (list)) {
-      str_array[count++] = list->data;
-    }
-    for (list = largs; list; list = g_list_next (list)) {
-      str_array[count++] = list->data;
-    }
-    args = g_strjoinv (" ", str_array);
-    g_free (str_array);
-  }
+  GList *list = NULL;
+  GList *verboseList = NULL;
+  GList *args1 = NULL;
 
   /* Allow the user to specify a full path or a different name for
    * the gnetlist command.  Especially useful if multiple copies
    * are installed at once.
    */
-
   if (gnetlist == NULL)
     gnetlist = g_getenv ("GNETLIST");
   if (gnetlist == NULL)
     gnetlist = "gnetlist";
 
-  if (verbose) {
-    command =
-      g_strconcat (gnetlist, " -g pcbpins -o ", pins_file, " ", args, NULL);
-    printf ("Running command:\n\t%s\n", command);
-    printf (SEP_STRING);
-  } else
-    command =
-      g_strconcat (gnetlist, " -q -g pcbpins -o ", pins_file, " ", args, NULL);
-  g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
-  g_free (command);
-
-  if (verbose) {
-    command = g_strconcat (gnetlist, " -g PCB -o ", net_file, " ", args, NULL);
-    printf ("Running command:\n\t%s\n", command);
-    printf (SEP_STRING);
-  } else
-    command =
-      g_strconcat (gnetlist, " -q -g PCB -o ", net_file, " ", args, NULL);
-  g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
-  g_free (command);
-
+  if (!verbose)
+    verboseList = g_list_append (verboseList, "-q");
+
+  build_and_run_command ("%s %l -g pcbpins -o %s %l %l",
+                         gnetlist,
+                         verboseList,
+                         pins_file,
+                         extra_gnetlist_arg_list,
+                         largs);
+
+  build_and_run_command ("%s %l -g PCB -o %s %l %l",
+                         gnetlist,
+                         verboseList,
+                         net_file,
+                         extra_gnetlist_arg_list,
+                         largs);
   create_m4_override_file ();
-  if (m4_override_file)
-    args1 = g_strconcat ("-m ", m4_override_file, " ", args, NULL);
-  else
-    args1 = g_strdup (args);
-
-  mtime = (stat (pcb_file, &st) == 0) ? st.st_mtime : 0;
 
-  if (verbose) {
-    printf (SEP_STRING);
-    command = g_strconcat (gnetlist, " -g gsch2pcb -o ", pcb_file,
-                           " ", args1, NULL);
-    printf ("Running command:\n\t%s\n", command);
-    printf (SEP_STRING);
-  } else
-    command = g_strconcat (gnetlist, " -q -g gsch2pcb -o ", pcb_file,
-                           " ", args1, NULL);
+  if (m4_override_file) {
+    args1 = g_list_append (args1, "-m");
+    args1 = g_list_append (args1, m4_override_file);
+  }
 
-  g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
+  mtime = (stat (pcb_file, &st) == 0) ? st.st_mtime : 0;
 
-  if (verbose)
-    printf (SEP_STRING);
+  build_and_run_command ("%s %l -g gsch2pcb -o %s %l %l %l",
+                         gnetlist,
+                         verboseList,
+                         pcb_file,
+                         args1,
+                         extra_gnetlist_arg_list,
+                         largs);
 
   if (stat (pcb_file, &st) != 0 || mtime == st.st_mtime) {
-    fprintf (stderr, "gsch2pcb: gnetlist command (%s) failed.\n", command);
+    fprintf (stderr,
+             "gsch2pcb: gnetlist command failed, `%s' not updated\n",
+             pcb_file
+            );
     if (m4_override_file)
       fprintf (stderr,
                "    At least gnetlist 20030901 is required for m4-xxx options.\n");
     exit (1);
   }
-  g_free (command);
-  g_free (args1);
+
   if (m4_override_file)
     unlink (m4_override_file);
 
   for (list = extra_gnetlist_list; list; list = g_list_next (list)) {
-    s = (gchar *) list->data;
-    if (!strstr (s, " -o "))
-      out_file = g_strconcat (" -o ", basename, ".", s, NULL);
-    else
-      out_file = g_strdup (" ");
-
-    if (verbose) {
-      printf (SEP_STRING);
-      command = g_strconcat (gnetlist, " -g ", s, out_file, " ", args, NULL);
-      printf ("Running command:\n\t%s\n", command);
-      printf (SEP_STRING);
-    } else
-      command = g_strconcat (gnetlist, " -q -g ", s, out_file, " ", args, NULL);
+    const gchar *s = (gchar *) list->data;
+    const gchar *s2 = strstr (s, " -o ");
+    gchar *out_file;
+    gchar *backend;
+    if (!s2) {
+      out_file = g_strconcat (basename, ".", s, NULL);
+      backend = g_strdup (s);
+    } else {
+      out_file = g_strdup (s2 + 4);
+      backend = g_strndup (s, s2 - s);
+    }
 
-    g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
-    g_free (command);
+    build_and_run_command ("%s %l -g %s -o %s %l %l",
+                           gnetlist,
+                           verboseList,
+                           backend,
+                           out_file,
+                           extra_gnetlist_arg_list,
+                           largs);
     g_free (out_file);
-    if (verbose)
-      printf (SEP_STRING);
+    g_free (backend);
   }
-  g_free (args);
+
+  g_list_free (args1);
+  g_list_free (verboseList);
 }
 
 static gchar *

commit a7a0bd24515bef8bcad69ae9321b4a8e5cbba738
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: helper function build_and_run_command
    
    Add a helper function to build and execute commands without
    relying on shell to split and parse command line.
    
    Affects-bug: lp-726828

diff --git a/utils/src/gsch2pcb.c b/utils/src/gsch2pcb.c
index ed8580c..3e00b27 100644
--- a/utils/src/gsch2pcb.c
+++ b/utils/src/gsch2pcb.c
@@ -121,6 +121,76 @@ create_m4_override_file ()
   }
 }
 
+/**
+ * Build and run a command. No redirection or error handling is
+ * done.  Format string is split on whitespace. Specifiers %l and %s
+ * are replaced with contents of positional args. To be recognized,
+ * specifiers must be separated from other arguments in the format by
+ * whitespace.
+ *  - %l expects a GList, contents used as separate arguments
+ *  - %s expects a gchar*, contents used as a single argument
+ * @param[in] format  used to specify command to be executed
+ * @param[in] ...     positional parameters
+ */
+static void
+build_and_run_command (const gchar *format, ...)
+{
+  va_list vargs;
+  gchar ** split;
+  GList *tmp = NULL;
+  gint num_split;
+  gint i;
+
+  va_start (vargs, format);
+  split = g_strsplit_set (format, " \t\n\v", 0);
+  num_split = g_strv_length (split);
+  for (i = 0; i < num_split; ++i) {
+    gchar *chunk = split[i];
+    if (strcmp (chunk, "%l") == 0) {
+      /* append contents of list into command args - shared data */
+      tmp = g_list_concat (tmp, g_list_copy (va_arg (vargs, GList*)));
+    } else if (strcmp (chunk, "%s") == 0) {
+      /* insert contents of string into output */
+      tmp = g_list_append (tmp, va_arg (vargs, gchar*));
+    } else {
+      /* bare string, use as is */
+      tmp = g_list_append (tmp, chunk);
+    }
+  }
+  va_end (vargs);
+
+  if (tmp) {
+    /* we have something in the list, build & call command */
+    GList *p;
+    gint i = 0;
+    gchar ** args = g_new0 (gchar*, g_list_length (tmp));
+
+    if (verbose)
+      printf ("Running command:\n\t");
+
+    for (p = tmp; p; p = g_list_next (p)) {
+      args[i++] = (gchar*) p->data;
+      if (verbose)
+        printf ("%s ", p->data);
+    }
+
+    if (verbose)
+      printf ("\n%s", SEP_STRING);
+
+    g_spawn_sync (".", args, NULL, G_SPAWN_SEARCH_PATH,
+                  NULL, NULL, NULL, NULL, NULL, NULL);
+
+    if (verbose)
+      printf ("\n%s", SEP_STRING);
+
+    g_free (args);
+    /* free the list, but leave data untouched */
+    g_list_free (tmp);
+  }
+
+  g_strfreev (split);
+}
+
 /* Run gnetlist to generate a netlist and a PCB board file.  gnetlist
  * has exit status of 0 even if it's given an invalid arg, so do some
  * stat() hoops to decide if gnetlist successfully generated the PCB

commit b3e10e97a110e6976aa3b8d12ea8037bf45f4d2e
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: keep multiple schematic files in a list
    
    Affects-bug: lp-726828

diff --git a/utils/src/gsch2pcb.c b/utils/src/gsch2pcb.c
index 5ceb27b..ed8580c 100644
--- a/utils/src/gsch2pcb.c
+++ b/utils/src/gsch2pcb.c
@@ -63,7 +63,9 @@ ElementMap;
 static GList *pcb_element_list,
   *element_directory_list, *extra_gnetlist_list, *extra_gnetlist_arg_list;
 
-static gchar *schematics, *sch_basename;
+static gchar *sch_basename;
+
+static GList *schematics;
 
 static gchar *m4_command,
   *m4_pcbdir, *default_m4_pcbdir, *m4_files, *m4_override_file;
@@ -126,29 +128,32 @@ create_m4_override_file ()
  */
 static void
 run_gnetlist (gchar * pins_file, gchar * net_file, gchar * pcb_file,
-              gchar * basename, gchar * args)
+              gchar * basename, GList * largs)
 {
   gchar *command, *out_file, *args1, *s;
   GList *list;
   struct stat st;
   time_t mtime;
   static const gchar *gnetlist = NULL;
+  gchar *args = NULL;
 
   /* Prepend the gnetlist arguments (including the list of schematics)
    * with those the user has specified with gnetlist-arg directives */
-  if (extra_gnetlist_arg_list != NULL) {
+  if (extra_gnetlist_arg_list || largs) {
     int count = 0;
     gchar **str_array =
-      g_new0 (char *, 2 + g_list_length (extra_gnetlist_arg_list));
-    for (list = extra_gnetlist_arg_list;
-         list != NULL; list = g_list_next (list)) {
+      g_new0 (char *,
+              1
+              + g_list_length (extra_gnetlist_arg_list)
+              + g_list_length (largs));
+    for (list = extra_gnetlist_arg_list; list; list = g_list_next (list)) {
+      str_array[count++] = list->data;
+    }
+    for (list = largs; list; list = g_list_next (list)) {
       str_array[count++] = list->data;
     }
-    str_array[count++] = args;
     args = g_strjoinv (" ", str_array);
     g_free (str_array);
-  } else {
-    args = g_strdup (args);
   }
 
   /* Allow the user to specify a full path or a different name for
@@ -1039,14 +1044,8 @@ add_default_m4_files (void)
 static void
 add_schematic (gchar * sch)
 {
-  gchar *s;
-
-  s = schematics;
-  if (s)
-    schematics = g_strconcat (s, " ", sch, NULL);
-  else
-    schematics = g_strdup (sch);
-  g_free (s);
+  const gchar* s;
+  schematics = g_list_append (schematics, g_strdup (sch));
   if (!sch_basename && (s = g_strrstr (sch, ".sch")) != NULL && strlen(s) == 4)
     sch_basename = g_strndup (sch, s - sch);
 }

commit 5b1ad217680aeddc4388b513fe2e41f0d9acee21
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: support quoting in schematics option
    
    Use g_shell_parse_argv to support spaces in filenames.
    
    Affects-bug: lp-726828

diff --git a/utils/src/gsch2pcb.c b/utils/src/gsch2pcb.c
index 24b9e06..5ceb27b 100644
--- a/utils/src/gsch2pcb.c
+++ b/utils/src/gsch2pcb.c
@@ -1051,6 +1051,29 @@ add_schematic (gchar * sch)
     sch_basename = g_strndup (sch, s - sch);
 }
 
+static void
+add_multiple_schematics (gchar * sch)
+{
+  /* parse the string using shell semantics */
+  gint count;
+  gchar** args = NULL;
+  GError* error = NULL;
+
+  if (g_shell_parse_argv (sch, &count, &args, &error)) {
+    int i;
+    for (i = 0; i < count; ++i)
+    {
+      add_schematic (args[i]);
+    }
+    g_strfreev (args);
+  } else {
+    fprintf (stderr,
+             "invalid `schematics' option: %s\n",
+             error->message);
+    g_error_free (error);
+  }
+}
+
 static gint
 parse_config (gchar * config, gchar * arg)
 {
@@ -1101,7 +1124,7 @@ parse_config (gchar * config, gchar * arg)
   } else if (!strcmp (config, "output-name") || !strcmp (config, "o"))
     sch_basename = g_strdup (arg);
   else if (!strcmp (config, "schematics"))
-    add_schematic (arg);
+    add_multiple_schematics (arg);
   else if (!strcmp (config, "m4-command"))
     m4_command = g_strdup (arg);
   else if (!strcmp (config, "m4-pcbdir"))

commit 6f705051d3b5b7ae380d0e13ad6fb8f4568066d2
Author: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Commit: Krzysztof KoÅ?ciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>

    gsch2pcb: fix check for filename ending with .sch

diff --git a/utils/src/gsch2pcb.c b/utils/src/gsch2pcb.c
index 095d400..24b9e06 100644
--- a/utils/src/gsch2pcb.c
+++ b/utils/src/gsch2pcb.c
@@ -1047,7 +1047,7 @@ add_schematic (gchar * sch)
   else
     schematics = g_strdup (sch);
   g_free (s);
-  if (!sch_basename && (s = strstr (sch, ".sch")) != NULL)
+  if (!sch_basename && (s = g_strrstr (sch, ".sch")) != NULL && strlen(s) == 4)
     sch_basename = g_strndup (sch, s - sch);
 }
 
@@ -1291,7 +1291,7 @@ get_args (gint argc, gchar ** argv)
       printf ("gsch2pcb: bad or incomplete arg: %s\n", argv[i]);
       usage ();
     } else {
-      if ((s = strstr (argv[i], ".sch")) == NULL) {
+      if (!g_str_has_suffix (argv[i], ".sch")) {
         load_extra_project_files ();
         load_project (argv[i]);
       } else



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