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

gEDA-cvs: CVS update: g_funcs.nw



  User: pbernaud
  Date: 05/02/13 16:53:25

  Modified:    .        g_funcs.nw g_keys.nw
  Log:
  Refactored get_selected_component_attributes() and get_selected_filename(): simplified prototype and made it use more of GLib.
  
  
  
  
  Revision  Changes    Path
  1.8       +37 -54    eda/geda/devel/gschem/noweb/g_funcs.nw
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: g_funcs.nw
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/g_funcs.nw,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- g_funcs.nw	4 Feb 2005 04:39:29 -0000	1.7
  +++ g_funcs.nw	13 Feb 2005 21:53:24 -0000	1.8
  @@ -236,7 +236,8 @@
   
   @section Function @code{get_selected_component_attributes()}
   
  -@defun get_selected_component_attributes data callback_action widget
  +@defun get_selected_component_attributes toplevel
  +Gets names from all objects of current page which selected-flags are true.
   @end defun
   
   <<g_funcs.c : get_selected_component_attributes()>>=
  @@ -245,56 +246,41 @@
    * I don't really know, whether this all are necessary or not, but 
    * it works :-). */
   
  -/* get names from all objects of current_page, which */
  -/* selected-flags are true. */
  +static void
  +hash_table_2_list (gpointer key,
  +                   gpointer value,
  +                   gpointer user_data)
  +{
  +  SCM *plist = (SCM*)user_data;
  +  *plist = gh_cons(gh_str2scm((char*)value, strlen ((char*)value)),
  +                   *plist);
  +}
   
  -SCM get_selected_component_attributes(gpointer data,		
  -				      guint callback_action,	
  -				      GtkWidget *widget)
  +SCM get_selected_component_attributes(TOPLEVEL *toplevel)
   {
  +  SCM list = SCM_EOL;
     OBJECT *obj;
  -  PAGE *p;
  +  GHashTable *ht;
     
  -  TOPLEVEL *w_current = (TOPLEVEL *) data;
  -  SCM list = SCM_EOL;
  -  /*NETLIST *nl_current = NULL; */
  +  /* build a hash table */
  +  ht = g_hash_table_new (g_str_hash, g_str_equal);
  +  for (obj = toplevel->page_current->object_head; obj != NULL;
  +       obj = obj->next) {
  +    if (obj->selected &&
  +        obj->type == OBJ_TEXT &&
  +        obj->text->string != NULL) {
  +      /* add text string in the hash table */
  +      g_hash_table_insert (ht,
  +                           obj->text->string,
  +                           obj->text->string);
  +     }
  +   }
  +  /* now create a scheme list of the entries in the hash table */
  +  g_hash_table_foreach (ht, hash_table_2_list, &list);
  +  /* and get ride of the hast table */
  +  g_hash_table_destroy (ht);
   
  -  /*nl_current = netlist_head; */
  -  p = w_current->page_current;
  -  obj = p->object_head;
  -
  -  s_scratch_string_init();
  -  
  -  while (obj != NULL)
  -  {
  -    if (obj->selected) 
  -    {
  -	  
  -      /*if (obj->type == OBJ_COMPLEX)
  -        {
  -        if (s_scratch_string_fill(obj->complex_basename)) 
  -        {
  -        list = gh_cons( gh_str2scm (obj->complex_basename, 
  -        strlen(obj->complex_basename)), 
  -        list);	
  -        }
  -        }
  -        else*/
  -      {
  -        if (obj->text && obj->text->string)
  -        {
  -          if (s_scratch_string_fill(obj->text->string))
  -          {
  -            list = scm_cons (scm_makfrom0str (obj->text->string),
  -                             list);	
  -          } 
  -        }
  -      }
  -    }
  -    obj = obj->next;
  -  }
  -  s_scratch_string_free();
  -  return(list);
  +  return list;
   }
   
   
  @@ -303,19 +289,16 @@
   
   @section Function @code{get_selected_filename()}
   
  -@defun get_selected_filename data callback_action widget
  +@defun get_selected_filename w_current
  +This function returns the whole filename of the current schematic. 
  +Specially, the [[page_filename]] of the current page.
   @end defun
   
   <<g_funcs.c : get_selected_filename()>>=
  -/* this function returns the whole filename of the current schematic. */
  -/* specially, the page_filename of the current_page */
   
  -SCM get_selected_filename(gpointer data,		
  -			  guint callback_action,	
  -			  GtkWidget *widget)
  +SCM get_selected_filename(TOPLEVEL *w_current)
   {
     SCM return_value;
  -  TOPLEVEL *w_current = (TOPLEVEL *) data;
     
     exit_if_null(w_current);
     
  
  
  
  1.4       +3 -3      eda/geda/devel/gschem/noweb/g_keys.nw
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: g_keys.nw
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/g_keys.nw,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- g_keys.nw	4 Feb 2005 04:39:29 -0000	1.3
  +++ g_keys.nw	13 Feb 2005 21:53:24 -0000	1.4
  @@ -338,7 +338,7 @@
   /*help for generate-netlist hot key*/
   SCM g_get_selected_filename(void)                     
   {                                                     
  -	return (get_selected_filename(global_window_current, 0, NULL));
  +	return (get_selected_filename(global_window_current));
   }
   
   
  @@ -353,7 +353,7 @@
   <<g_keys.c : g_get_selected_component_attributes()>>=
   SCM g_get_selected_component_attributes(void)                 
   {                                                     
  -	return (get_selected_component_attributes(global_window_current, 0, NULL));
  +  return (get_selected_component_attributes(global_window_current));
   }