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

gEDA-cvs: CVS update: listsort.c



  User: ahvezda 
  Date: 07/02/10 10:09:22

  Modified:    .        listsort.c s_string_list.c
  Log:
  Applied patch by DJ [ 1637387 ] Enhance sort functions.
  
  
  
  
  Revision  Changes    Path
  1.5       +32 -3     eda/geda/gaf/gattrib/src/listsort.c
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: listsort.c
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gattrib/src/listsort.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- listsort.c	21 Feb 2005 05:29:33 -0000	1.4
  +++ listsort.c	10 Feb 2007 15:09:21 -0000	1.5
  @@ -1,4 +1,4 @@
  -/* $Id: listsort.c,v 1.4 2005/02/21 05:29:33 danmc Exp $ */
  +/* $Id: listsort.c,v 1.5 2007/02/10 15:09:21 ahvezda Exp $ */
   
   
   /*----------------------------------------------------------------*
  @@ -56,6 +56,7 @@
   #endif
   
   #include <stdio.h>
  +#include <ctype.h>
   
   #ifdef HAVE_STRING_H
   #include <string.h>
  @@ -77,8 +78,36 @@
   /*----------------------------------------------------------------*
    * Comparison function -- compare values of string data.
    *----------------------------------------------------------------*/
  -int cmp(STRING_LIST *a, STRING_LIST *b) {
  -    return strcmp(a->data, b->data);
  +int cmp(STRING_LIST *al, STRING_LIST *bl) {
  +  char *a = al->data;
  +  char *b = bl->data;
  +
  +  if (al->pos != bl->pos)
  +    return al->pos - bl->pos;
  +
  +  while (*a && *b)
  +    {
  +      if (isdigit ((int) *a) && isdigit ((int) *b))
  +	{
  +	  int ia = atoi (a);
  +	  int ib = atoi (b);
  +	  if (ia != ib)
  +	    return ia - ib;
  +	  while (isdigit ((int) *a))
  +	    a++;
  +	  while (isdigit ((int) *b))
  +	    b++;
  +	}
  +      else if (tolower (*a) != tolower (*b))
  +	return tolower (*a) - tolower (*b);
  +      a++;
  +      b++;
  +    }
  +  if (*a)
  +    return 1;
  +  if (*b)
  +    return -1;
  +  return 0;
   }
   
   /*----------------------------------------------------------------*
  
  
  
  1.8       +37 -5     eda/geda/gaf/gattrib/src/s_string_list.c
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: s_string_list.c
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gattrib/src/s_string_list.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- s_string_list.c	26 Jul 2006 22:56:39 -0000	1.7
  +++ s_string_list.c	10 Feb 2007 15:09:22 -0000	1.8
  @@ -310,10 +310,12 @@
    *------------------------------------------------------------------*/
   void s_string_list_sort_master_comp_list() {
     int i = 0;
  -  STRING_LIST *local_list;
  +  STRING_LIST *local_list, *p;
   
     /* Here's where we do the sort.  The sort is done using a fcn found on the web. */
     local_list = sheet_head->master_comp_list_head;
  +  for (p=local_list; p; p=p->next)
  +    p->pos = 0;
     local_list = listsort(local_list, 0, 1);
   
     /* Do this after sorting is done.  This resets the order of the individual items
  @@ -345,21 +347,49 @@
    * Right now it does nothing other than fill in the "position"
    * and "length" variables.
    *------------------------------------------------------------------*/
  +
  +/* This list overrides the alphanumeric sort.  Attribs not found in
  +   this list are sorted as if they had a value of DEFAULT_ATTRIB_POS
  +   within this list, but alphanumerically relative to each other.  */
  +static struct {
  +  const char *attrib;
  +  int pos;
  +} certain_attribs[] = {
  +  {"device", 1},
  +  {"footprint", 2},
  +  {"value", 3},
  +  {"symversion", 200}
  +};
  +#define NUM_CERTAINS (sizeof(certain_attribs)/sizeof(certain_attribs[0]))
  +#define DEFAULT_ATTRIB_POS 100
  +
   void s_string_list_sort_master_comp_attrib_list() {
     int i = 0;
  -  STRING_LIST *local_list;
  +  STRING_LIST *local_list, *p;
   
     /* Here's where we do the sort */
  +  local_list = sheet_head->master_comp_attrib_list_head;
   
     /*
      * Note that this sort is TBD -- it is more than just an alphabetic sort 'cause we want 
      * certain attribs to go first. 
      */
  +  for (p=local_list; p; p=p->next) {
  +    int i;
  +    p->pos = DEFAULT_ATTRIB_POS;
  +    for (i=0; i<NUM_CERTAINS; i++)
  +      if (strcmp (certain_attribs[i].attrib, p->data) == 0)
  +	{
  +	  p->pos = certain_attribs[i].pos;
  +	  break;
  +	}
  +  }
     
  +  local_list = listsort(local_list, 0, 1);
  +  sheet_head->master_comp_attrib_list_head = local_list;
   
     /* Do this after sorting is done.  This resets the order of the individual items
      * in the list.  */
  -  local_list = sheet_head->master_comp_attrib_list_head;
     while (local_list != NULL) {
       local_list->pos = i;
       i++;
  @@ -423,10 +453,12 @@
    *------------------------------------------------------------------*/
   void s_string_list_sort_master_pin_list() {
     int i = 0;
  -  STRING_LIST *local_list;
  +  STRING_LIST *local_list, *p;
   
     /* Here's where we do the sort.  The sort is done using a fcn found on the web. */
     local_list = sheet_head->master_pin_list_head;
  +  for (p=local_list; p; p=p->next)
  +    p->pos = 0;
     local_list = listsort(local_list, 0, 1);
   
     /* Do this after sorting is done.  This resets the order of the individual items
  
  
  


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