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

gEDA-cvs: pcb.git: branch: master updated (8e622b2c0aa88e2fe131c45438429d3524dc4da6)



The branch, master has been updated
       via  8e622b2c0aa88e2fe131c45438429d3524dc4da6 (commit)
       via  542c19ff457755ce9d26ec1883650c125fcfe576 (commit)
      from  480e81559af88dacbfb6bd94cd5fb705ec4f7cb4 (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
=========

 src/action.c |   54 +++++++++++-
 src/buffer.c |   32 ++++++--
 src/change.c |    4 +
 src/copy.c   |   25 +++++-
 src/create.c |   12 +++
 src/file.c   |  280 ++++++++++++++++++++++++++++++++++++++--------------------
 src/file.h   |    1 +
 src/global.h |   17 ++--
 src/main.c   |    9 ++-
 9 files changed, 321 insertions(+), 113 deletions(-)


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

commit 8e622b2c0aa88e2fe131c45438429d3524dc4da6
Author: Stuart Brorson <sdb@xxxxxxxxxx>
Commit: Stuart Brorson <sdb@xxxxxxxxxx>

    Place components in middle of board instead of at 0,0.

:100644 100644 94bf07e... c15c7c0... M	src/action.c

commit 542c19ff457755ce9d26ec1883650c125fcfe576
Author: Stuart Brorson <sdb@xxxxxxxxxx>
Commit: Stuart Brorson <sdb@xxxxxxxxxx>

    Support for footprints not in subdirectories
    
    Added tons of debug spew to various files to aid in program tracing
    Also, modify library loading stuff in file.c to allow footprints to live
    directly in library directory (rather than only one level down).

:100644 100644 d7c754b... 94bf07e... M	src/action.c
:100644 100644 7daecf5... fbd1735... M	src/buffer.c
:100644 100644 db13d5e... 8cbd384... M	src/change.c
:100644 100644 5a030c9... 583feb8... M	src/copy.c
:100644 100644 518a35b... eced68d... M	src/create.c
:100644 100644 fd18340... 639c971... M	src/file.c
:100644 100644 64eba23... 2822525... M	src/file.h
:100644 100644 80bea72... 1082dd1... M	src/global.h
:100644 100644 e5d93eb... 3026f8d... M	src/main.c

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

commit 8e622b2c0aa88e2fe131c45438429d3524dc4da6
Author: Stuart Brorson <sdb@xxxxxxxxxx>
Commit: Stuart Brorson <sdb@xxxxxxxxxx>

    Place components in middle of board instead of at 0,0.

diff --git a/src/action.c b/src/action.c
index 94bf07e..c15c7c0 100644
--- a/src/action.c
+++ b/src/action.c
@@ -6968,7 +6968,8 @@ ActionElementList (int argc, char **argv, int x, int y)
       /* Not on board, need to add it. */
       if (LoadFootprint(argc, args, x, y))
 	return 1;
-      if (CopyPastebufferToLayout (0, 0))
+      /* Place components onto center of board. */
+      if (CopyPastebufferToLayout (PCB->MaxWidth/2, PCB->MaxHeight/2))
 	SetChangedFlag (True);
     }
 

commit 542c19ff457755ce9d26ec1883650c125fcfe576
Author: Stuart Brorson <sdb@xxxxxxxxxx>
Commit: Stuart Brorson <sdb@xxxxxxxxxx>

    Support for footprints not in subdirectories
    
    Added tons of debug spew to various files to aid in program tracing
    Also, modify library loading stuff in file.c to allow footprints to live
    directly in library directory (rather than only one level down).

diff --git a/src/action.c b/src/action.c
index d7c754b..94bf07e 100644
--- a/src/action.c
+++ b/src/action.c
@@ -6864,6 +6864,7 @@ delete_attr (AttributeListTypePtr list, AttributeType *attr)
   list->Number --;
 }
 
+/* ---------------------------------------------------------------- */
 static const char elementlist_syntax[] = "ElementList(Start|Done|Need,<refdes>,<footprint>,<value>)";
 
 static const char elementlist_help[] = "Adds the given element if it doesn't already exist.";
@@ -6901,6 +6902,10 @@ ActionElementList (int argc, char **argv, int x, int y)
   char *args[3];
   char *function = argv[0];
 
+#ifdef DEBUG
+  printf("Entered ActionElementList, executing function %s\n", function);
+#endif
+
   if (strcasecmp (function, "start") == 0)
     {
       ELEMENT_LOOP (PCB->Data);
@@ -6947,10 +6952,19 @@ ActionElementList (int argc, char **argv, int x, int y)
   args[1] = refdes;
   args[2] = value;
 
+#ifdef DEBUG
+  printf("  ... footprint = %s\n", footprint);
+  printf("  ... refdes = %s\n", refdes);
+  printf("  ... value = %s\n", value);
+#endif
+
   e = find_element_by_refdes (refdes);
 
   if (!e)
     {
+#ifdef DEBUG
+      printf("  ... Footprint not on board, need to add it.\n");
+#endif
       /* Not on board, need to add it. */
       if (LoadFootprint(argc, args, x, y))
 	return 1;
@@ -6960,6 +6974,9 @@ ActionElementList (int argc, char **argv, int x, int y)
 
   else if (e && strcmp (DESCRIPTION_NAME(e), footprint) != 0)
     {
+#ifdef DEBUG
+      printf("  ... Footprint on board, but different from footprint loaded.\n");
+#endif
       int er, pr, i;
       LocationType mx, my;
       ElementType *pe;
@@ -6992,6 +7009,7 @@ ActionElementList (int argc, char **argv, int x, int y)
 	SetChangedFlag (True);
     }
 
+  /* Now reload footprint */
   e = find_element_by_refdes (refdes);
 
   old = ChangeElementText (PCB, PCB->Data, e, NAMEONPCB_INDEX, strdup (refdes));
@@ -7003,9 +7021,14 @@ ActionElementList (int argc, char **argv, int x, int y)
 
   SET_FLAG (FOUNDFLAG, e);
 
+#ifdef DEBUG
+  printf(" ... Leaving ActionElementList.\n");
+#endif
+
   return 0;
 }
 
+/* ---------------------------------------------------------------- */
 static const char elementsetattr_syntax[] = "ElementSetAttr(refdes,name[,value])";
 
 static const char elementsetattr_help[] = "Sets or clears an element-specific attribute";
@@ -7069,6 +7092,7 @@ ActionElementSetAttr (int argc, char **argv, int x, int y)
   return 0;
 }
 
+/* ---------------------------------------------------------------- */
 static const char execcommand_syntax[] = "ExecCommand(command)";
 
 static const char execcommand_help[] = "Runs a command";
@@ -7096,6 +7120,7 @@ ActionExecCommand (int argc, char **argv, int x, int y)
   return 0;
 }
 
+/* ---------------------------------------------------------------- */
 static const char import_syntax[] =
   "Import()\n"
   "Import([gnetlist|make[,source,source,...]])\n";
@@ -7192,6 +7217,7 @@ pcb_spawnvp (char **argv)
   return 0;
 }
 
+/* ---------------------------------------------------------------- */
 /* 
  * Creates a new temporary file name.  Hopefully the operating system
  * provides a mkdtemp() function to securily create a temporary
@@ -7278,6 +7304,7 @@ tempfile_name_new (char * name)
   return tmpfile;
 }
 
+/* ---------------------------------------------------------------- */
 /*
  * Unlink a temporary file.  If we have mkdtemp() then our temp file
  * lives in a temporary directory and we need to remove that directory
@@ -7288,6 +7315,11 @@ tempfile_unlink (char * name)
 {
   int rc;
 
+#ifdef DEBUG
+    /* SDB says:  Want to keep old temp files for examiniation when debugging */
+  return 0;
+#endif
+
 #ifdef HAVE_MKDTEMP
   int e, rc2 = 0;
   char *dname;
@@ -7348,6 +7380,7 @@ tempfile_unlink (char * name)
   return 0;
 }
 
+/* ---------------------------------------------------------------- */
 static int
 ActionImport (int argc, char **argv, int x, int y)
 {
@@ -7355,6 +7388,10 @@ ActionImport (int argc, char **argv, int x, int y)
   char **sources = NULL;
   int nsources = 0;
 
+#ifdef DEBUG
+      printf("ActionImport:  ===========  Entering ActionImport  ============\n");
+#endif
+
   mode = ARG (0);
   if (! mode)
     mode = AttributeGet (PCB, "import::mode");
@@ -7447,12 +7484,22 @@ ActionImport (int argc, char **argv, int x, int y)
 	cmd[5+i] = sources[i];
       cmd[5+nsources] = NULL;
 
+#ifdef DEBUG
+      printf("ActionImport:  ===========  About to run gnetlist  ============\n");
+      printf("%s %s %s %s %s %s ...\n", 
+	     cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5]);
+#endif
+
       if (pcb_spawnvp (cmd))
 	{
 	  unlink (tmpfile);
 	  return 1;
 	}
 
+#ifdef DEBUG
+      printf("ActionImport:  ===========  About to run ActionExecuteFile, file = %s  ============\n", tmpfile);
+#endif
+
       cmd[0] = tmpfile;
       cmd[1] = NULL;
       ActionExecuteFile (1, cmd, 0, 0);
@@ -7546,6 +7593,10 @@ ActionImport (int argc, char **argv, int x, int y)
   DeleteRats (False);
   AddAllRats (False, NULL);
 
+#ifdef DEBUG
+      printf("ActionImport:  ===========  Leaving ActionImport  ============\n");
+#endif
+
   return 0;
 }
 
diff --git a/src/buffer.c b/src/buffer.c
index 7daecf5..fbd1735 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -683,23 +683,40 @@ make_footprint_hash ()
      in brackets in the description.  */
   for (i=0; i<Library.MenuN; i++)
     {
-      for (j=0; j<Library.Menu[i].EntryN; j++)
+#ifdef DEBUG
+  printf("In make_footprint_hash, looking for footprints in %s\n", 
+	 Library.Menu[i].directory);
+#endif
+
+    for (j=0; j<Library.Menu[i].EntryN; j++)
 	{
 	  footprint_hash[num_entries].menu_idx = i;
 	  footprint_hash[num_entries].entry_idx = j;
-	  if (Library.Menu[i].Entry[j].Template == (char *) -1)
+	  if (Library.Menu[i].Entry[j].Template == (char *) -1) 
+          /* file */
 	    {
+#ifdef DEBUG
+/*	      printf(" ... Examining file %s\n", Library.Menu[i].Entry[j].AllocatedMemory); */
+#endif
 	      fp = strrchr (Library.Menu[i].Entry[j].AllocatedMemory, '/');
+
 	      if (!fp)
 		fp = strrchr (Library.Menu[i].Entry[j].AllocatedMemory, '\\');
+
 	      if (fp)
 		fp ++;
-	      else
+	      else 
 		fp = Library.Menu[i].Entry[j].AllocatedMemory;
+
+#ifdef DEBUG
+/* 	      printf(" ... found file footprint %s\n",  fp); */
+#endif
+	        
 	      footprint_hash[num_entries].footprint = fp;
 	      footprint_hash[num_entries].footprint_allocated = 0;
 	    }
-	  else
+	  else 
+          /* m4 */
 	    {
 	      fp = strrchr (Library.Menu[i].Entry[j].Description, '[');
 	      if (fp)
@@ -723,10 +740,13 @@ make_footprint_hash ()
 
   footprint_hash_size = num_entries;
   qsort (footprint_hash, num_entries, sizeof(footprint_hash[0]), footprint_hash_cmp);
-#if 0
+/*
+#ifdef DEBUG
+  printf("       found footprints:  \n");
   for (i=0; i<num_entries; i++)
     printf("[%s]\n", footprint_hash[i].footprint);
 #endif
+*/
 }
 
 FootprintHashEntry *
@@ -810,7 +830,7 @@ LoadFootprintByName (BufferTypePtr Buffer, char *Footprint)
       return i ? 0 : 1;
     }
 
-#if 1
+#ifdef DEBUG
   {
     int j;
     printf("Library path: %s\n", Settings.LibraryPath);
diff --git a/src/change.c b/src/change.c
index db13d5e..8cbd384 100644
--- a/src/change.c
+++ b/src/change.c
@@ -988,6 +988,10 @@ ChangeElementText (PCBType *pcb, DataType *data, ElementTypePtr Element, int whi
 {
   char *old = Element->Name[which].TextString;
 
+#ifdef DEBUG
+  printf("In ChangeElementText, updating old TextString %s to %s\n", old, new_name);
+#endif
+
   if (pcb && which == NAME_INDEX (pcb))
     EraseElementName (Element);
 
diff --git a/src/copy.c b/src/copy.c
index 5a030c9..583feb8 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -277,11 +277,17 @@ CopyPolygon (LayerTypePtr Layer, PolygonTypePtr Polygon)
 }
 
 /* ---------------------------------------------------------------------------
- * copies a element 
+ * copies an element onto the PCB.  Then does a draw. 
  */
 static void *
 CopyElement (ElementTypePtr Element)
 {
+
+#ifdef DEBUG
+  printf("Entered CopyElement, trying to copy element %s\n",
+	 Element->Name[1].TextString);
+#endif
+
   Boolean didDraw = False;
   ElementTypePtr element = CopyElementLowLevel (PCB->Data,
 						NULL, Element,
@@ -302,6 +308,9 @@ CopyElement (ElementTypePtr Element)
       DrawElementPinsAndPads (element, 0);
       didDraw = True;
     }
+#ifdef DEBUG
+  printf(" ... Leaving CopyElement.\n");
+#endif
   return (element);
 }
 
@@ -315,6 +324,10 @@ CopyPastebufferToLayout (LocationType X, LocationType Y)
   Cardinal i;
   Boolean changed = False;
 
+#ifdef DEBUG
+  printf("Entering CopyPastebufferToLayout.....\n");
+#endif
+
   /* set movement vector */
   DeltaX = X - PASTEBUFFER->X, DeltaY = Y - PASTEBUFFER->Y;
 
@@ -358,6 +371,10 @@ CopyPastebufferToLayout (LocationType X, LocationType Y)
     {
       ELEMENT_LOOP (PASTEBUFFER->Data);
       {
+#ifdef DEBUG
+	printf("In CopyPastebufferToLayout, pasting element %s\n",
+	      element->Name[1].TextString);
+#endif
 	if (FRONT (element) || PCB->InvisibleObjectsOn)
 	  {
 	    CopyElement (element);
@@ -377,11 +394,17 @@ CopyPastebufferToLayout (LocationType X, LocationType Y)
       }
       END_LOOP;
     }
+
   if (changed)
     {
       Draw ();
       IncrementUndoSerialNumber ();
     }
+
+#ifdef DEBUG
+  printf("  .... Leaving CopyPastebufferToLayout.\n");
+#endif
+
   return (changed);
 }
 
diff --git a/src/create.c b/src/create.c
index 518a35b..eced68d 100644
--- a/src/create.c
+++ b/src/create.c
@@ -199,6 +199,9 @@ CreateNewPCB (Boolean SetDefaultNames)
   return (ptr);
 }
 
+/* This post-processing step adds the top and bottom silk layers to a
+ * pre-existing PCB.
+ */
 int
 CreateNewPCBPost (PCBTypePtr pcb, int use_defaults)
 {
@@ -643,6 +646,10 @@ CreateNewElement (DataTypePtr Data, ElementTypePtr Element,
 		  LocationType TextX, LocationType TextY, BYTE Direction,
 		  int TextScale, FlagType TextFlags, Boolean uniqueName)
 {
+#ifdef DEBUG
+  printf("Entered CreateNewElement.....\n");
+#endif
+
   if (!Element)
     Element = GetElementMemory (Data);
 
@@ -661,6 +668,11 @@ CreateNewElement (DataTypePtr Data, ElementTypePtr Element,
   VALUE_TEXT (Element).Element = Element;
   Element->Flags = Flags;
   Element->ID = ID++;
+
+#ifdef DEBUG
+  printf("  .... Leaving CreateNewElement.\n");
+#endif
+
   return (Element);
 }
 
diff --git a/src/file.c b/src/file.c
index fd18340..639c971 100644
--- a/src/file.c
+++ b/src/file.c
@@ -124,6 +124,8 @@ static int WritePCB (FILE *);
 static int WritePCBFile (char *);
 static int WritePipe (char *, Boolean);
 static int ParseLibraryTree (void);
+static int LoadNewlibFootprintsFromDir(char *path, char *toppath);
+static char *pcb_basename (char *p);
 
 /* ---------------------------------------------------------------------------
  * Flag helper functions
@@ -1093,9 +1095,10 @@ RemoveTMPData (void)
 #endif
 
 /* ---------------------------------------------------------------------------
- * parse the directory tree where additional library elements are found
+ * Parse the directory tree where newlib footprints are found
  */
 
+/* Helper function for ParseLibraryTree */
 static char *
 pcb_basename (char *p)
 {
@@ -1105,132 +1108,205 @@ pcb_basename (char *p)
   return p;
 }
 
-int
-ParseLibraryTree (void)
+/* This is a helper function for ParseLibrary Tree.   Given a char *path,
+ * it finds all newlib footprints in that dir and sticks them into the
+ * library menu structure named entry.
+ */
+static int
+LoadNewlibFootprintsFromDir(char *libpath, char *toppath)
 {
-  char path[MAXPATHLEN + 1];
-  char working[MAXPATHLEN + 1];
-  char *libpaths, *p;
-  DIR *dir, *subdir;
-  struct stat buffer;
-  struct dirent *direntry, *e2;
-  LibraryMenuTypePtr menu = NULL;
-  LibraryEntryTypePtr entry;
+  char olddir[MAXPATHLEN + 1];    /* The directory we start out in (cwd) */
+  char subdir[MAXPATHLEN + 1];    /* The directory holding footprints to load */
+  DIR *subdirobj;                 /* Interable object holding all subdir entries */
+  struct dirent *subdirentry;     /* Individual subdir entry */
+  struct stat buffer;             /* Buffer used in stat */
+  LibraryMenuTypePtr menu = NULL; /* Pointer to PCB's library menu structure */
+  LibraryEntryTypePtr entry;      /* Pointer to individual menu entry */
   size_t l;
-  int n_footprints = 0;
+  size_t len;
+  int n_footprints = 0;           /* Running count of footprints found in this subdir */
+
+  /* Cache old dir, then cd into subdir because stat is given relative file names. */
+  memset (subdir, 0, sizeof subdir);
+  memset (olddir, 0, sizeof olddir);
+  GetWorkingDirectory(olddir); 
+  strcpy (subdir, libpath);
+  chdir(subdir);
+  GetWorkingDirectory(subdir);  /* subdir is abs path */
+
+  /* First try opening the directory specified by path */
+  if ( (subdirobj = opendir (subdir)) == NULL )
+  {
+      OpendirErrorMessage (subdir);
+      return 0;
+  }
+
+  /* Get pointer to memory holding menu */
+  menu = GetLibraryMenuMemory (&Library);
+  /* Populate menuname and path vars */
+  menu->Name = MyStrdup (pcb_basename(subdir), "Newlib");
+  menu->directory = strdup (pcb_basename(toppath));
+
+  /* Now loop over files in this directory looking for files.
+   * We ignore certain files which are not footprints.
+   */
+  while ((subdirentry = readdir (subdirobj)) != NULL)
+  {
+#ifdef DEBUG
+/*    printf("...  Examining file %s ... \n", subdirentry->d_name); */
+#endif
+
+    /* Ignore non-footprint files found in this directory
+     * We're skipping .png and .html because those
+     * may exist in a library tree to provide an html browsable
+     * index of the library.
+     */
+    l = strlen (subdirentry->d_name);
+    if (!stat (subdirentry->d_name, &buffer) && S_ISREG (buffer.st_mode)
+      && subdirentry->d_name[0] != '.'
+      && NSTRCMP (subdirentry->d_name, "CVS") != 0
+      && NSTRCMP (subdirentry->d_name, "Makefile") != 0
+      && NSTRCMP (subdirentry->d_name, "Makefile.am") != 0
+      && NSTRCMP (subdirentry->d_name, "Makefile.in") != 0
+      && (l < 4 || NSTRCMP(subdirentry->d_name + (l - 4), ".png") != 0) 
+      && (l < 5 || NSTRCMP(subdirentry->d_name + (l - 5), ".html") != 0) )
+      {
+#ifdef DEBUG
+/*	printf("...  Found a footprint %s ... \n", subdirentry->d_name); */
+#endif
+	n_footprints++;
+	entry = GetLibraryEntryMemory (menu);
+
+	/* 
+	 * entry->AllocatedMemory points to abs path to the footprint.
+	 * entry->ListEntry points to fp name itself.
+	 */
+	len = strlen(subdir) + strlen("/") + strlen(subdirentry->d_name) + 1;
+	entry->AllocatedMemory = MyCalloc (1, len, "ParseLibraryTree()");
+	strcat (entry->AllocatedMemory, subdir);
+	strcat (entry->AllocatedMemory, PCB_DIR_SEPARATOR_S);
+
+	/* store pointer to start of footprint name */
+	entry->ListEntry = entry->AllocatedMemory
+	    + strlen (entry->AllocatedMemory);
+
+	/* Now place footprint name into AllocatedMemory */
+	strcat (entry->AllocatedMemory, subdirentry->d_name);
+
+	/* mark as directory tree (newlib) library */
+	entry->Template = (char *) -1;
+      }
+  }
+  /* Done.  Clean up, cd back into old dir, and return */
+  closedir (subdirobj);
+  chdir(olddir);
+  return n_footprints;
+}
 
-  memset (path, 0, sizeof path);
+
+/* This function loads the newlib footprints into the Library.
+ * It examines all directories pointed to by Settings.LibraryTree.
+ * In each directory specified there, it looks both in that directory,
+ * as well as *one* level down.  It calls the subfunction 
+ * LoadNewlibFootprintsFromDir to put the footprints into PCB's internal
+ * datastructures.
+ */
+static int
+ParseLibraryTree (void)
+{
+  char toppath[MAXPATHLEN + 1];    /* String holding abs path to top level library dir */
+  char working[MAXPATHLEN + 1];    /* String holding abs path to working dir */
+  char *libpaths;                  /* String holding list of library paths to search */
+  char *p;                         /* Helper string used in iteration */
+  DIR *dirobj;                     /* Iterable directory object */
+  struct dirent *direntry = NULL;  /* Object holding individual directory entries */
+  struct stat buffer;              /* buffer used in stat */
+  int n_footprints = 0;            /* Running count of footprints found */
+
+  /* Initialize path, working by writing 0 into every byte. */
+  memset (toppath, 0, sizeof toppath);
   memset (working, 0, sizeof working);
 
-  /* save the current working directory */
+  /* Save the current working directory as an absolute path.
+   * This fcn writes the abs path into the memory pointed to by the input arg.
+   */
   GetWorkingDirectory (working);
 
-  /* Additional loop to allow for multiple 'newlib' style library directories */
+  /* Additional loop to allow for multiple 'newlib' style library directories 
+   * called out in Settings.LibraryTree
+   */
   libpaths = MyStrdup (Settings.LibraryTree, "ParseLibraryTree");
   for (p = strtok (libpaths, PCB_PATH_DELIMETER); p && *p; p = strtok (NULL, PCB_PATH_DELIMETER))
     {
-      strncpy (path, p, sizeof (path) - 1);
+      /* remove trailing path delimeter */
+      strncpy (toppath, p, sizeof (toppath) - 1);
 
-      /* 
-       * start out in the working directory in case the path is a
+      /* start out in the working directory in case the path is a
        * relative path 
        */
       chdir (working);
 
-      if ((dir = opendir (path)) == NULL)
+      /*
+       * Next change to the directory which is the top of the library tree
+       * and extract its abs path.
+       */
+      chdir (toppath);
+      GetWorkingDirectory (toppath);
+
+#ifdef DEBUG
+      printf("In ParseLibraryTree, looking for newlib footprints inside top level directory %s ... \n", 
+	     toppath);
+#endif
+
+      /* Next read in any footprints in the top level dir */
+      n_footprints += LoadNewlibFootprintsFromDir("(local)", toppath);
+
+      /* Then open this dir so we can loop over its contents. */
+      if ((dirobj = opendir (toppath)) == NULL)
 	{
-	  OpendirErrorMessage (path);
+	  OpendirErrorMessage (toppath);
 	  continue;
 	}
 
-      /*
-       * change to the directory which is the top of the library tree
-       * and then extract that directory to ensure we have a full path
-       * name, not a relative path name.
+      /* Now loop over files in this directory looking for subdirs.
+       * For each direntry which is a valid subdirectory,
+       * try to load newlib footprints inside it.
        */
-      chdir (path);
-      GetWorkingDirectory (path);
-
-      /* read all entries */
-      while ((direntry = readdir (dir)) != NULL)
+      while ((direntry = readdir (dirobj)) != NULL)
 	{
-	  chdir (path);
-	  /* find directories
-	   * ignore entries beginning with "." and CVS
-	   * directories as well as a few other specific 
-	   * files.  We're skipping .png and .html because those
-	   * may exist in a library tree to provide an html browsable
-	   * index of the library.
+#ifdef DEBUG
+	  printf("In ParseLibraryTree loop examining 2nd level direntry %s ... \n", direntry->d_name);
+#endif
+	  /* Find subdirectories.  Ignore entries beginning with "." and CVS
+	   * directories.
 	   */
 	  if (!stat (direntry->d_name, &buffer)
-	      && S_ISDIR (buffer.st_mode) && direntry->d_name[0] != '.'
+	      && S_ISDIR (buffer.st_mode) 
+	      && direntry->d_name[0] != '.'
 	      && NSTRCMP (direntry->d_name, "CVS") != 0)
 	    {
-	      /* add directory name into menu */
-	      menu = GetLibraryMenuMemory (&Library);
-	      menu->Name = MyStrdup (direntry->d_name, "ParseLibraryTree()");
-	      /* FIXME ? */
-	      menu->directory = strdup (pcb_basename (path));
-	      subdir = opendir (direntry->d_name);
-	      chdir (direntry->d_name);
-	      while (subdir && (e2 = readdir (subdir)))
-		{
-		  l = strlen (e2->d_name);
-		  if (!stat (e2->d_name, &buffer) && S_ISREG (buffer.st_mode)
-		      && e2->d_name[0] != '.'
-		      && NSTRCMP (e2->d_name, "CVS") != 0
-		      && NSTRCMP (e2->d_name, "Makefile") != 0
-		      && NSTRCMP (e2->d_name, "Makefile.am") != 0
-		      && NSTRCMP (e2->d_name, "Makefile.in") != 0
-		      && (l < 4 || NSTRCMP(e2->d_name + (l - 4), ".png") != 0) 
-		      && (l < 5 || NSTRCMP(e2->d_name + (l - 5), ".html") != 0) )
-		    {
-
-		      /* 
-		       * Besides the length for the 3 strings listed, 
-		       * we have two "/" added in below, and also we 
-		       * have 2 '\0' characters since
-		       * entry->AllocatedMemory actually will contain
-		       * 2 null terminated strings.  Thats why we 
-		       * add 4
-		       */
-		      long len = strlen (path) + strlen (e2->d_name) +
-			strlen (direntry->d_name) + 4;
-#if 0
-		      if (NSTRCMP
-			  (e2->d_name + strlen (e2->d_name) - 4, ".lel") != 0)
-			break;
-#endif
-		      n_footprints++;
-		      entry = GetLibraryEntryMemory (menu);
-		      entry->AllocatedMemory = MyCalloc (1, len,
-							 "ParseLibraryTree()");
-		      strcat (entry->AllocatedMemory, path);
-		      strcat (entry->AllocatedMemory, PCB_DIR_SEPARATOR_S);
-		      strcat (entry->AllocatedMemory, direntry->d_name);
-		      strcat (entry->AllocatedMemory, PCB_DIR_SEPARATOR_S);
-		      entry->ListEntry = entry->AllocatedMemory
-			+ strlen (entry->AllocatedMemory);
-		      strcat (entry->AllocatedMemory, e2->d_name);
-		      /* mark as directory tree library */
-		      entry->Template = (char *) -1;
-		    }
-		}
-	      closedir (subdir);
+	      /* Found a valid subdirectory.  Try to load footprints from it.
+	       */
+	      n_footprints += LoadNewlibFootprintsFromDir(direntry->d_name, toppath);
 	    }
 	}
-      closedir (dir);
+      closedir (dirobj);
     }
-  free (libpaths);
 
   /* restore the original working directory */
   chdir (working);
+
+#ifdef DEBUG
+  printf("Leaving ParseLibraryTree, found %d footprints.\n", n_footprints);
+#endif
+
   return n_footprints;
 }
 
 /* ---------------------------------------------------------------------------
- * read contents of the library description file
- * also parse a special library directory tree
+ * Read contents of the library description file (for M4)
+ * and then read in M4 libs.  Then call a fcn to read the newlib
+ * footprints.
  */
 int
 ReadLibraryContents (void)
@@ -1241,18 +1317,28 @@ ReadLibraryContents (void)
   LibraryMenuTypePtr menu = NULL;
   LibraryEntryTypePtr entry;
 
+
+  /*  First load the M4 stuff.  The variable Settings.LibraryPath
+   *  points to it.
+   */
   MYFREE (command);
   command = EvaluateFilename (Settings.LibraryContentsCommand,
 			      Settings.LibraryPath, Settings.LibraryFilename,
 			      NULL);
 
-  /* open a pipe to the output of the command */
+#ifdef DEBUG
+  printf("In ReadLibraryContents, about to execute command %s\n", command);
+#endif
+
+  /* This uses a pipe to execute a shell script which provides the names of
+   * all M4 libs and footprints.  The results are placed in resultFP.
+   */
   if (command && *command && (resultFP = popen (command, "r")) == NULL)
     {
       PopenErrorMessage (command);
     }
 
-  /* the library contents are separated by colons;
+  /* the M4 library contents are separated by colons;
    * template : package : name : description
    */
   while (resultFP != NULL && fgets (inputline, MAX_LIBRARY_LINE_LENGTH, resultFP))
@@ -1312,7 +1398,11 @@ ReadLibraryContents (void)
     }
   if (resultFP != NULL)
     pclose (resultFP);
-  
+
+  /* Now after reading in the M4 libs, call a function to
+   * read the newlib footprint libraries.  Then sort the whole
+   * library.
+   */
   if (ParseLibraryTree () > 0 || resultFP != NULL)
     {
       sort_library (&Library);
diff --git a/src/file.h b/src/file.h
index 64eba23..2822525 100644
--- a/src/file.h
+++ b/src/file.h
@@ -48,6 +48,7 @@ int SaveBufferElements (char *);
 void PreLoadElementPCB (void);
 void PostLoadElementPCB (void);
 void sort_netlist (void);
+int ParseLibraryTree (void);
 
 /* 
  * Whenever the pcb file format is modified, this version number
diff --git a/src/global.h b/src/global.h
index 80bea72..1082dd1 100644
--- a/src/global.h
+++ b/src/global.h
@@ -178,8 +178,8 @@ typedef struct
 
 struct BoxType		/* a bounding box */
 {
-  LocationType X1, Y1,		/* upper left */
-    X2, Y2;			/* and lower right corner */
+  LocationType X1, Y1;		/* upper left */
+  LocationType X2, Y2;		/* and lower right corner */
 };
 
 typedef struct
@@ -231,8 +231,7 @@ typedef struct
 {
   ANYOBJECTFIELDS;
   BDimension Scale;		/* text scaling in percent */
-  LocationType X,		/* origin */
-    Y;
+  LocationType X, Y;    	/* origin */
   BYTE Direction;
   char *TextString;		/* string */
   void *Element;
@@ -809,11 +808,11 @@ struct drc_violation_st
  * Variables with absolute paths to various directories.  These are deduced
  * at runtime to allow pcb to be relocatable
  */
-extern char *bindir;
-extern char *pcblibdir;
-extern char *pcblibpath;
-extern char *pcbtreedir;
-extern char *pcbtreepath;
+extern char *bindir;       /* The dir in which PCB installation was found */
+extern char *pcblibdir;    /* The system M4 fp directory */
+extern char *pcblibpath;   /* The search path for M4 fps */
+extern char *pcbtreedir;   /* The system newlib fp directory */
+extern char *pcbtreepath;  /* The search path for newlib fps */
 extern char *exec_prefix;
 extern char *homedir;
 
diff --git a/src/main.c b/src/main.c
index e5d93eb..3026f8d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -896,11 +896,13 @@ main (int argc, char *argv[])
       program_basename = program_name;
     }
   Progname = program_basename;
-  
+
+  /* Print usage or version if requested.  Then exit.  */  
   if (argc > 1 && strcmp (argv[1], "-h") == 0)
     usage ();
   if (argc > 1 && strcmp (argv[1], "-V") == 0)
     print_version ();
+  /* Export pcb from command line if requested.  */
   if (argc > 1 && strcmp (argv[1], "-p") == 0)
     {
       exporter = gui = hid_find_printer ();
@@ -913,12 +915,15 @@ main (int argc, char *argv[])
       argc -= 2;
       argv += 2;
     }
+    /* Otherwise start GUI. */
   else
     gui = hid_find_gui ();
 
+  /* Exit with error if GUI failed to start. */
   if (!gui)
     exit (1);
 
+  /* Set up layers. */
   for (i = 0; i < MAX_LAYER; i++)
     {
       char buf[20];
@@ -960,9 +965,11 @@ main (int argc, char *argv[])
       exit (0);
     }
 
+  /* Create a new PCB object in memory */
   PCB = CreateNewPCB (True);
   PCB->Data->LayerN = DEF_LAYER;
   ParseGroupString (Settings.Groups, &PCB->LayerGroups, DEF_LAYER);
+  /* Add silk layers to newly created PCB */
   CreateNewPCBPost (PCB, 1);
   if (argc > 1)
     command_line_pcb = argv[1];




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