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

gEDA-cvs: CVS update: s_table.c



  User: sdb     
  Date: 06/08/22 14:20:00

  Modified:    .        s_table.c s_toplevel.c
  Log:
  Fixed bug in which adding a new attrib column would munge the 
  
  visibility of existing attributes.
  
  
  
  
  Revision  Changes    Path
  1.13      +36 -29    eda/geda/gaf/gattrib/src/s_table.c
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: s_table.c
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gattrib/src/s_table.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- s_table.c	13 Aug 2006 12:31:56 -0000	1.12
  +++ s_table.c	22 Aug 2006 18:20:00 -0000	1.13
  @@ -85,43 +85,40 @@
   
   }
   
  -#if 0
  +
   /*------------------------------------------------------------------
  - * This fcn recreates the table with a new size
  + * This fcn recreates the table with a new size.  It can only increase
  + * the number of cols.  You can't increase the number of rows since
  + * gattrib doesn't allow you to input new components.  Decreasing the 
  + * number of cols is also TBD.
    *------------------------------------------------------------------*/
   TABLE **s_table_resize(TABLE **table, 
  -		       int old_rows, int old_cols, int new_rows, int new_cols)
  +		       int rows, int old_cols, int new_cols)
   {
     int i, j;
   
  -  s_table_destroy(**table, old_rows, old_cols);
  -
  -  /* Here I am trying to create a 2 dimensional array of structs */
  -  new_table = (TABLE **) g_malloc(new_rows*sizeof(TABLE *));
  -  for (i = 0; i < new_rows; i++) {
  -    new_table[i] = (TABLE *) g_malloc(new_cols * sizeof(TABLE));
  -    /* Note that I should put some checks in here to verify that 
  -     * malloc worked correctly. */
  -  }
  -
  -  /* Now pre-load the table with NULLs */
  -  for (i = 0; i < new_rows; i++) {
  -    for (j = 0; j < new_cols; j++) {
  -      (new_table[i][j]).attrib_value = NULL;
  -      (new_table[i][j]).row_name = NULL;
  -      (new_table[i][j]).col_name = NULL;
  -      (new_table[i][j]).row = i;
  -      (new_table[i][j]).col = j;
  -      (new_table[i][j]).visibility = VISIBLE;
  -      (new_table[i][j]).show_name_value = SHOW_VALUE;
  -      
  +  /* Here I am trying to resize the 2 dimensional array of structs */
  +  for (i = 0; i < rows; i++) {
  +    table[i] = (TABLE *) realloc(table[i], new_cols*sizeof(TABLE) );
  +    if (table[i] == NULL) exit(-1);  /* die if failed to realloc new memory */
  +  }
  +
  +  /* Now pre-load new cols with NULLs */
  +  for (i = 0; i < rows; i++) {
  +    for (j = old_cols; j < new_cols; j++) {
  +      (table[i][j]).attrib_value = NULL;
  +      (table[i][j]).row_name = NULL;
  +      (table[i][j]).col_name = NULL;
  +      (table[i][j]).row = i;
  +      (table[i][j]).col = j;
  +      (table[i][j]).visibility = VISIBLE;
  +      (table[i][j]).show_name_value = SHOW_VALUE;
       }
     }
   
  -  return (new_table);
  -
  +  return table;
   }
  -#endif
  +
   
   /*------------------------------------------------------------------
    * This fcn destroys the old table.  Use it after reading in a new
  @@ -179,7 +176,7 @@
       count++;
       list_element = list_element->next;
     }
  -  exit(-1);  /* return code when string is not in master_list  */
  +  return(-1);  /* return code when string is not in master_list  */
   }
   
   
  @@ -568,7 +565,8 @@
     local_gtk_sheet = sheets[2];
     master_row_list = sheet_head->master_pin_list_head;
     master_col_list = sheet_head->master_pin_attrib_list_head;
  -  local_table = s_table_new(num_rows, num_cols);
  +  /*  local_table = s_table_new(num_rows, num_cols);  */
  +  local_table = sheet_head->pin_table;
   
     s_table_gtksheet_to_table(local_gtk_sheet, master_row_list, 
   		       master_col_list, local_table,
  @@ -600,7 +598,7 @@
     gchar *attrib_value;
   
   #ifdef DEBUG
  -      printf("**********    Entering s_table_update_table     ******************\n");
  +      printf("**********    Entering s_table_gtksheet_to_table     ******************\n");
   #endif
   
   
  @@ -624,11 +622,14 @@
   
   
   #ifdef DEBUG
  -      printf("In s_table_update_table, found attrib_value = %s in cell row=%d, col=%d\n", 
  +      printf("In s_table_gtksheet_to_table, found attrib_value = %s in cell row=%d, col=%d\n", 
   	     attrib_value, row, col);
   #endif
   
         /* first handle attrib value in cell */
  +#ifdef DEBUG
  +      printf("     Updating attrib_value %s\n", attrib_value);
  +#endif
         if ( local_table[row][col].attrib_value != NULL) {
   	g_free( local_table[row][col].attrib_value );
         }
  @@ -639,6 +640,9 @@
         }
   
         /* next handle name of row (also held in TABLE cell) */
  +#ifdef DEBUG
  +      printf("     Updating row_name %s\n", row_title);
  +#endif
         if ( local_table[row][col].row_name != NULL) {
   	g_free( local_table[row][col].row_name );
         }
  @@ -649,6 +653,9 @@
         }
   
         /* finally handle name of col */
  +#ifdef DEBUG
  +      printf("     Updating col_name %s\n", col_title);
  +#endif
         if ( local_table[row][col].col_name != NULL) {
   	g_free( local_table[row][col].col_name );
         }
  
  
  
  1.20      +36 -12    eda/geda/gaf/gattrib/src/s_toplevel.c
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: s_toplevel.c
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gattrib/src/s_toplevel.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- s_toplevel.c	13 Aug 2006 18:24:45 -0000	1.19
  +++ s_toplevel.c	22 Aug 2006 18:20:00 -0000	1.20
  @@ -1,4 +1,4 @@
  -/* $Id: s_toplevel.c,v 1.19 2006/08/13 18:24:45 sdb Exp $ */
  +/* $Id: s_toplevel.c,v 1.20 2006/08/22 18:20:00 sdb Exp $ */
   
   /* gEDA - GPL Electronic Design Automation
    * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
  @@ -271,6 +271,7 @@
    *------------------------------------------------------------------*/
   void s_toplevel_add_new_attrib(gchar *new_attrib_name) {
     gint cur_page;  /* current page in notbook  */
  +  gint old_comp_attrib_count;
   
     if (strcmp(new_attrib_name, "_cancel") == 0) {
       return;  /* user pressed cancel or closed window with no value in entry */
  @@ -290,12 +291,14 @@
        *  new attrib.  However, that is difficult.  Therefore, I will just
        *  destroy the old table and recreate it for now. */
   
  +    /* 
       s_table_destroy(sheet_head->component_table, 
   		    sheet_head->comp_count, sheet_head->comp_attrib_count);
  -
  +    */
  +    old_comp_attrib_count = sheet_head->comp_attrib_count;
   #ifdef DEBUG 
  -    printf("In s_toplevel_menubar_edit_newattrib, before adding new comp attrib.\n");
  -    printf("                           comp_attrib_count = %d\n", sheet_head->comp_attrib_count);
  +    printf("In s_toplevel_add_new_attrib, before adding new comp attrib.\n");
  +    printf("                           comp_attrib_count = %d\n", old_comp_attrib_count);
   #endif
   
       s_string_list_add_item(sheet_head->master_comp_attrib_list_head, 
  @@ -304,13 +307,24 @@
       s_string_list_sort_master_comp_attrib_list();
   
   #ifdef DEBUG
  -    printf("In s_toplevel_menubar_edit_newattrib, just updated comp_attrib string list.\n");
  +    printf("In s_toplevel_add_new_attrib, just updated comp_attrib string list.\n");
       printf("                             new comp_attrib_count = %d\n", sheet_head->comp_attrib_count);
   #endif
   
       /* Now create new table */
  -    sheet_head->component_table = s_table_new(sheet_head->comp_count, 
  +    /*     sheet_head->component_table = s_table_new(sheet_head->comp_count, 
   					      sheet_head->comp_attrib_count);
  +    */
  +
  +    /* resize table to accomodate new attrib col */
  +    sheet_head->component_table = 
  +      s_table_resize(sheet_head->component_table, 
  +		     sheet_head->comp_count, 
  +		     old_comp_attrib_count, sheet_head->comp_attrib_count);
  +
  +#ifdef DEBUG
  +    printf("In s_toplevel_add_new_attrib, just resized component table.\n");
  +#endif
   
       /* Fill out new sheet with new stuff from gtksheet */
       gtk_sheet_insert_columns(GTK_SHEET(sheets[0]), sheet_head->comp_attrib_count, 1);
  @@ -319,7 +333,7 @@
   			      sheet_head->master_comp_attrib_list_head);
   
   #ifdef DEBUG
  -    printf("In s_toplevel_menubar_edit_newattrib, just updated gtksheet.\n");
  +    printf("In s_toplevel_add_new_attrib, just updated gtksheet.\n");
   #endif
   
       break;
  @@ -707,7 +721,8 @@
     ATTRIB *a_current;
     int count = 0;  /* This is to fake out a fcn called later */
     gint row, col;
  -  gint visibility, show_name_value;
  +  gint visibility;
  +  gint show_name_value;
   
   #if DEBUG
     printf("-----  Entering s_toplevel_update_component_attribs_in_toplevel.\n");
  @@ -761,6 +776,7 @@
     while (local_list != NULL) {
   
   #if DEBUG
  +    printf("\n\n");
     printf("        In s_toplevel_update_component_attribs_in_toplevel, handling entry in complete list %s .\n", 
   	 local_list->data);
   #endif
  @@ -797,8 +813,13 @@
     refdes = g_strdup(s_attrib_get_refdes(o_current));
     row = s_table_get_index(sheet_head->master_comp_list_head, refdes);
     col = s_table_get_index(sheet_head->master_comp_attrib_list_head, new_attrib_name);
  +  /* if attribute has been deleted from the sheet, here is where we detect that */
  +  if ( (row == -1) || (col == -1) ) {
  +    new_attrib_value = NULL;  /* attrib will be deleted below */
  +  } else { /* we need a better place to get this info since the TABLE can be out of date */
     visibility = sheet_head->component_table[row][col].visibility;
     show_name_value = sheet_head->component_table[row][col].show_name_value;
  +  }
     g_free(refdes);
   
   
  @@ -806,8 +827,11 @@
       if ( (old_attrib_value != NULL) && (new_attrib_value != NULL) && (strlen(new_attrib_value) != 0) ) {
         /* simply write new attrib into place of old one. */
   #if DEBUG
  -      printf("     -- In s_toplevel_update_component_attribs_in_toplevel, about to replace old attrib with name= %s, value= %s\n",
  +      printf("     -- In s_toplevel_update_component_attribs_in_toplevel,\n");
  +      printf("               about to replace old attrib with name= %s, value= %s\n", 
   	     new_attrib_name, new_attrib_value);
  +      printf("               visibility = %d, show_name_value = %d.\n",
  +	     visibility, show_name_value);
   #endif
         s_object_replace_attrib_in_object(o_current, 
   					new_attrib_name, 
  
  
  


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