gEDA-dev: [PATCH] gschem: clean up i_basic.c

Ivan Stankovic ivan.stankovic at fer.hr
Tue May 29 13:39:00 EDT 2007


On Tue, May 29, 2007 at 05:59:13PM +0100, Peter TB Brett wrote:
> Firstly, while you're working on this code could you please take the 
> opportunity to flesh out the Doxygen comments with \param and \returns tags?  
> It does make a lot of difference when tracing what code is supposed to do.

Here is a new version with some doxygen comments added. There are still
2 or 3 functions that need better documentation, but I suppose this is
good enough.

-- 
Ivan Stankovic, ivan.stankovic at fer.hr

"Protect your digital freedom and privacy, eliminate DRM, 
learn more at http://www.defectivebydesign.org/what_is_drm"
-------------- next part --------------

---
 gschem/include/prototype.h |    4 -
 gschem/src/i_basic.c       |  330 ++++++++------------------------------------
 gschem/src/i_callbacks.c   |   19 ---
 gschem/src/o_picture.c     |    3 -
 4 files changed, 59 insertions(+), 297 deletions(-)

diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index 54cc8cc..617a53e 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -291,16 +291,12 @@ void gschem_quit(void);
 void main_prog(void *closure, int argc, char *argv[]);
 int main(int argc, char *argv[]);
 /* i_basic.c */
-void i_allow_expose(void);
 void i_show_state(TOPLEVEL *w_current, const char *message);
 void i_set_state(TOPLEVEL *w_current, enum x_states newstate);
 void i_set_state_msg(TOPLEVEL *w_current, enum x_states newstate, const char *message);
-void i_update_left_button(const char *string);
 void i_update_middle_button(TOPLEVEL *w_current, void (*func_ptr)(gpointer, guint, GtkWidget*), const char *string);
-void i_update_right_button(const char *string);
 void i_update_toolbar(TOPLEVEL *w_current);
 void i_update_menus(TOPLEVEL *w_current);
-void i_update_cursor(TOPLEVEL *w_current);
 void i_set_filename(TOPLEVEL *w_current, const gchar *string);
 void i_set_grid(TOPLEVEL *w_current, int visible_grid);
 /* i_callbacks.c */
diff --git a/gschem/src/i_basic.c b/gschem/src/i_basic.c
index 65dde59..8d86cf1 100644
--- a/gschem/src/i_basic.c
+++ b/gschem/src/i_basic.c
@@ -31,16 +31,15 @@
 #include <dmalloc.h>
 #endif
 
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
+/*! \brief Actually update the status bar widget with the
+ *         new string.
+ *  \param [in] w_current TOPLEVEL structure
+ *  \param [in] string The new string to be shown in the status bar
  */
 static void i_update_status(TOPLEVEL *w_current, const char *string)
 {
-  if (!w_current->status_label) {
+  if (!w_current->status_label)
     return;
-  }
 
   if (string) {
     /* NOTE: consider optimizing this if same label */
@@ -50,33 +49,11 @@ static void i_update_status(TOPLEVEL *w_current, const char *string)
   }
 }
 
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-/* Prefix to i_show_state(), i_set_state() and i_set_state_msg()
- , Allows expose events to happen
- * *EK* Egil Kvaleberg
- */
-void i_allow_expose(void)
-{
-  /* This function is probably not needed and should be deleted eventually */
-#if 0
-   /* HACK: This one allows the expose events to happen? */
-    w_current->DONT_EXPOSE = 1;
-#endif
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-/* Get string corresponding to the currently selected mode
- * The returned string will only last until the next time
- * the function is called (which is probably just fine, really)
- * *EK* Egil Kvaleberg
+/*! \brief Get string corresponding to the currently selected mode
+ *  \param [in] w_current TOPLEVEL structure
+ *  \returns a string that will only last until the next time
+ *   the function is called (which is probably just fine, really)
+ *   *EK* Egil Kvaleberg
  */
 static const char *i_status_string(TOPLEVEL *w_current)
 {
@@ -164,85 +141,55 @@ static const char *i_status_string(TOPLEVEL *w_current)
   return ""; /* should not happen */
 }
 
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-/* Show state field on screen,
- * possibly with the addition of an extra message
- * *EK* Egil Kvaleberg
+/*! \brief Show state field on screen, possibly with the 
+ *         addition of an extra message
+ *  \param [in] w_current TOPLEVEL structure
+ *  \param [in] message The string to be displayed 
  */
 void i_show_state(TOPLEVEL *w_current, const char *message)
 {
-  static char *buf = 0;
-  char *aux = 0;
-  const char *state_string = i_status_string(w_current);
-  const char *what_to_say;
-
-  /* This may be a memory leak... either way it's weird and -Wall is */
-  /* complaining... */
-  buf = g_strdup("");
-  aux = buf;
-
-  if ( message != NULL) {
-    if ( message && message[0] ) {
-      buf = g_strdup_printf("%s - ", message);
-      if (aux) g_free(aux);
-      aux = buf;
-    }
-  }
-
-  if ( !w_current->snap ) {
-    buf = g_strdup_printf("%s%s - ", buf, _("Snap Off"));
-    if (aux) g_free(aux);
-    aux = buf;
-  }
+  gchar *what_to_say;
+  const gchar *array[5] = { NULL };
+  int i = 3; /* array[4] must be NULL */
 
-  if ( w_current->show_hidden_text ) {
-    buf = g_strdup_printf("%s%s - ", buf, _("Show Hidden"));
-    if (aux) g_free(aux);
-    aux = buf;
-  }
+  /* Fill in the string array */
+  array[i--] = i_status_string(w_current);
+  
+  if(w_current->show_hidden_text)
+    array[i--] = _("Show Hidden");
+  
+  if(!w_current->snap)
+    array[i--] = _("Snap Off");
+  
+  if(message && message[0])
+    array[i] = message;
+  
+  /* Skip over NULLs */
+  while(array[i] == NULL)
+    i++;
 
-  if (buf != NULL) {
-    if (strlen(buf) > 0) {
-      buf = g_strdup_printf("%s%s", buf, state_string);
-      if (aux) g_free(aux);
-      aux = buf;
-      what_to_say = buf;
-    } else {
-      what_to_say = state_string;
-    }
-  }
-  else {
-    what_to_say = state_string;
-  }
+  what_to_say = g_strjoinv(" - ", (gchar **) array + i);
 
   i_update_status(w_current, what_to_say);
-  if (buf != NULL) g_free(buf);
+  g_free(what_to_say);
 }
 
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-/* Set new state, then show state field
- * *EK* Egil Kvaleberg
+/*! \brief Set new state, then show state field
+ *  \param [in] w_current TOPLEVEL structure
+ *  \param [in] newstate The new state
+ *   *EK* Egil Kvaleberg
  */
 void i_set_state(TOPLEVEL *w_current, enum x_states newstate)
 {
   i_set_state_msg(w_current, newstate, NULL);
 }
 
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-/* Set new state, then show state field including some message
- * *EK* Egil Kvaleberg
+/*! \brief Set new state, then show state field including some
+ *         message
+ *  \param [in] w_current TOPLEVEL structure
+ *  \param [in] newstate The new state
+ *  \param [in] message Message to be shown
+ *   *EK* Egil Kvaleberg
  */
 void i_set_state_msg(TOPLEVEL *w_current, enum x_states newstate,
 		     const char *message)
@@ -256,31 +203,20 @@ void i_set_state_msg(TOPLEVEL *w_current, enum x_states newstate,
  *  \par Function Description
  *
  */
-void i_update_left_button(const char *string)
-{
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
 void i_update_middle_button(TOPLEVEL *w_current,
-			    void (*func_ptr)(gpointer, guint, GtkWidget*), const char *string)
+			    void (*func_ptr)(gpointer, guint, GtkWidget*),
+			    const char *string)
 {
   char *temp_string;
 
-  if (func_ptr == NULL) {
+  if (func_ptr == NULL)
     return;
-  }
 
-  if (string == NULL) {
+  if (string == NULL)
     return;
-  }	
 
-  if (!w_current->middle_label) {
+  if (!w_current->middle_label)
     return;
-  }
 
   switch(w_current->middle_button) {
 
@@ -319,21 +255,11 @@ void i_update_middle_button(TOPLEVEL *w_current,
     break;
 
   }
-
 }
 
 /*! \todo Finish function documentation!!!
  *  \brief
- *  \par Function Description
- *
- */
-void i_update_right_button(const char *string)
-{
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
+ *  \param [in] w_current TOPLEVEL structure
  *
  */
 void i_update_toolbar(TOPLEVEL *w_current)
@@ -411,10 +337,8 @@ void i_update_toolbar(TOPLEVEL *w_current)
   }
 }
 
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
+/*! \brief Update sensitivity of relevant menu items
+ *  \param [in] w_current TOPLEVEL structure
  */
 void i_update_menus(TOPLEVEL *w_current)
 {
@@ -476,7 +400,7 @@ void i_update_menus(TOPLEVEL *w_current)
     /* x_menus_popup_sensitivity(w_current, "/Up", TRUE); */
 
   } else {
-    /* Nothing is slected.  grey these out */
+    /* Nothing is selected, grey these out */
     /* These strings should NOT be internationalized */
     x_menus_sensitivity(w_current, "Edit/Cut Buffer", FALSE);
     x_menus_sensitivity(w_current, "Edit/Copy Buffer", FALSE);
@@ -554,136 +478,11 @@ void i_update_menus(TOPLEVEL *w_current)
   } else {
     x_menus_sensitivity(w_current, "Buffer/Paste from 5", FALSE);
   }
- 
-
 }
  
-#if 0
-/* This data is in X bitmap format, and can be created with the 'bitmap'
-     utility. */
-  #define cursor1_width 16
-  #define cursor1_height 16
-  static unsigned char cursor1_bits[] = {
-   0x00, 0x00, 0x08, 0x38, 0x18, 0x08, 0x38, 0x18, 0x78, 0x08, 0xf8, 0x38,
-   0xf8, 0x01, 0xf8, 0x03, 0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01,
-   0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00};
-
-  static unsigned char cursor1mask_bits[] = {
-   0x0c, 0x7c, 0x1c, 0x7c, 0x3c, 0x7c, 0x7c, 0x3c, 0xfc, 0x7c, 0xfc, 0x7d,
-   0xfc, 0x7f, 0xfc, 0x07, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x01, 0xdc, 0x03,
-   0xcc, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03};
-#endif
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-void i_update_cursor(TOPLEVEL *w_current)
-{
-#if 0
-  if (!w_current->cursors) 
-	return;
-#endif
-
-#if 0
-  GdkCursor *cursor;
-
-  GdkPixmap *source, *mask;
-  GdkColor fg = { 0, 0, 0, 0 }; /* Red. */
-  GdkColor bg = { 0, 65535, 65535, 65535 }; /* Blue. */
-    
-  source = gdk_bitmap_create_from_data (NULL, cursor1_bits,
-					cursor1_width, cursor1_height);
-  mask = gdk_bitmap_create_from_data (NULL, cursor1mask_bits,
-				      cursor1_width, cursor1_height);
-  cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 3, 1);
-  gdk_pixmap_unref (source);
-  gdk_pixmap_unref (mask);
-  
-  gdk_window_set_cursor (w_current->window, cursor);
-#endif
-
-
-  GdkCursor* cursor;
-  cursor = gdk_cursor_new(GDK_ARROW);
-  gdk_window_set_cursor(w_current->window, cursor);
-  gdk_cursor_destroy(cursor);
-  
-#if 0
-  switch(w_current->event_state) {
-    case(NONE):
-    case(SELECT):
-    case(STARTSELECT): 
-    case(TEXTENTRY): 
-      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
-				   w_current->toolbar_select), TRUE);
-      break;
-
-    case(DRAWNET): 
-    case(STARTDRAWNET): 
-    case(NETCONT): 
-      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
-				   w_current->toolbar_net), TRUE);
-      break;
-
-    case(DRAWBUS): 
-    case(STARTDRAWBUS): 
-    case(BUSCONT): 
-      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
-				   w_current->toolbar_bus), TRUE);
-      break;
-
-    case(DRAWCOMP): /*! \todo */
-    case(DRAWLINE): /*! \todo */
-    case(DRAWBOX): /*! \todo */
-    case(DRAWPICTURE): /*! \todo */
-    case(DRAWPIN): /*! \todo */
-    case(DRAWCIRCLE): /*! \todo */
-    case(DRAWARC): /*! \todo */
-    case(MOVE): /*! \todo */
-    case(COPY): /*! \todo */
-    case(ZOOM): /*! \todo */
-    case(PAN): /*! \todo */
-    case(STARTPAN): /*! \todo */
-    case(STARTCOPY): /*! \todo */
-    case(STARTMOVE): /*! \todo */
-    case(ENDCOPY): /*! \todo */
-    case(ENDMOVE): /*! \todo */
-    case(ENDLINE): /*! \todo */
-    case(ENDBOX): /*! \todo */
-    case(ENDPICTURE): /*! \todo */
-    case(ENDCIRCLE): /*! \todo */
-    case(ENDARC): /*! \todo */
-    case(ENDPIN): /*! \todo */
-    case(ENDCOMP): /*! \todo */
-    case(DRAWATTRIB): /*! \todo */
-    case(ENDATTRIB): /*! \todo */
-    case(DRAWTEXT): /*! \todo */
-    case(ENDTEXT): /*! \todo */
-    case(ENDROTATEP): /*! \todo */
-    case(ENDMIRROR): /*! \todo */
-    case(ZOOMBOXSTART): /*! \todo */
-    case(ZOOMBOXEND): /*! \todo */
-    case(STARTROUTENET): /*! \todo */
-    case(ENDROUTENET): /*! \todo */
-    case(MOUSEPAN): /*! \todo */
-    case(STARTPASTE): /*! \todo */
-    case(ENDPASTE): /*! \todo */
-    case(GRIPS): /*! \todo */
-    case(MCOPY): /*! \todo */
-    case(MCOPYSTART): /*! \todo */
-    case(MCOPYEND): /*! \todo */
-    default:
-      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
-				   w_current->toolbar_select), TRUE);
-      break;
-  }
-#endif
-}
-
-/*! \brief Set filename as gschem  window title
- *  \par Function Description
+/*! \brief Set filename as gschem window title
+ *  \param [in] w_current TOPLEVEL structure
+ *  \param [in] string The filename
  *  Set the window title using the gnome HID format style.
  */
 void i_set_filename(TOPLEVEL *w_current, const gchar *string)
@@ -700,17 +499,6 @@ void i_set_filename(TOPLEVEL *w_current, const gchar *string)
   
   print_string = g_strdup_printf("%s - gschem", filename);
   
-  /* alternativ code with length limited pathname */
-/*  int max_len = 70;
-    if (strlen(string) > max_len) {
-    print_string = g_strdup_printf("gschem: ...%s",
-				   &(string[strlen(string)-max_len]));
-  }
-  else {
-    print_string = g_strdup_printf("gschem: %s",string);
-  }
-*/
-
   gtk_window_set_title(GTK_WINDOW(w_current->main_window),
 		       print_string);
   
@@ -719,7 +507,8 @@ void i_set_filename(TOPLEVEL *w_current, const gchar *string)
 }
 
 /*! \brief Write the grid settings to the gschem status bar
- *  \par Function Description
+ *  \param [in] w_current TOPLEVEL structure
+ *  \param [in] visible_grid Visible grid size
  *  The function takes the current grid paramters of gschem and
  *  prints it to the status bar.
  *  The format is "Grid([SnapGridSize],[CurrentGridSize])"
@@ -730,9 +519,8 @@ void i_set_grid(TOPLEVEL *w_current, int visible_grid)
   gchar *snap=NULL;
   gchar *grid=NULL;
 
-  if (!w_current->grid_label) {
+  if (!w_current->grid_label)
     return;
-  }
   
   if (!w_current->snap)
     snap = g_strdup(_("OFF"));
diff --git a/gschem/src/i_callbacks.c b/gschem/src/i_callbacks.c
index cfe3518..73c5fa0 100644
--- a/gschem/src/i_callbacks.c
+++ b/gschem/src/i_callbacks.c
@@ -1378,7 +1378,6 @@ DEFINE_I_CALLBACK(view_zoom_box)
 
   o_redraw_cleanstates(w_current);	
   w_current->inside_action = 0;
-  i_allow_expose();
   i_set_state(w_current, ZOOMBOXSTART);
 }
 
@@ -1397,7 +1396,6 @@ DEFINE_I_CALLBACK(view_zoom_box_hotkey)
   a_zoom_box_start(w_current, mouse_x, mouse_y);
 
   w_current->inside_action = 1;
-  i_allow_expose();
   i_set_state(w_current, ZOOMBOXEND);
 }
 
@@ -2233,7 +2231,6 @@ DEFINE_I_CALLBACK(add_component)
   i_update_middle_button(w_current,
                          i_callback_add_component, _("Component"));
 
-  i_allow_expose();
   i_set_state(w_current, SELECT);
   i_update_toolbar(w_current);
 }
@@ -2270,7 +2267,6 @@ DEFINE_I_CALLBACK(add_attribute)
   i_update_middle_button(w_current, i_callback_add_attribute,
                          _("Attribute"));
 
-  i_allow_expose();
   i_set_state(w_current, SELECT);
   i_update_toolbar(w_current);
 }
@@ -2290,7 +2286,6 @@ DEFINE_I_CALLBACK(add_attribute_hotkey)
   i_update_middle_button(w_current, i_callback_add_attribute_hotkey,
                          _("Attribute"));
 
-  i_allow_expose();
   i_set_state(w_current, SELECT);
   i_update_toolbar(w_current);
 }
@@ -2311,7 +2306,6 @@ DEFINE_I_CALLBACK(add_net)
 
   /* need to click */
   i_update_middle_button(w_current, i_callback_add_net, _("Net"));
-  i_allow_expose();
   i_set_state(w_current, STARTDRAWNET);
   i_update_toolbar(w_current);
   /* somewhere you need to nearest point locking... */
@@ -2334,7 +2328,6 @@ DEFINE_I_CALLBACK(add_net_hotkey)
 
   /* need to click */
   i_update_middle_button(w_current, i_callback_add_net_hotkey, _("Net"));
-  i_allow_expose();
   i_set_state(w_current, STARTDRAWNET);
   i_update_toolbar(w_current);
 
@@ -2379,7 +2372,6 @@ DEFINE_I_CALLBACK(add_bus)
 
   /* need to click */
   i_update_middle_button(w_current, i_callback_add_bus, _("Bus"));
-  i_allow_expose();
   i_set_state(w_current, STARTDRAWBUS);
   i_update_toolbar(w_current);
 
@@ -2403,7 +2395,6 @@ DEFINE_I_CALLBACK(add_bus_hotkey)
 
   /* need to click */
   i_update_middle_button(w_current, i_callback_add_bus_hotkey, _("Bus"));
-  i_allow_expose();
   i_set_state(w_current, STARTDRAWBUS);
   i_update_toolbar(w_current);
 
@@ -2485,7 +2476,6 @@ DEFINE_I_CALLBACK(add_line)
   o_erase_rubber(w_current);
 
   i_update_middle_button(w_current, i_callback_add_line, _("Line"));
-  i_allow_expose();
   i_set_state(w_current, DRAWLINE);
   w_current->inside_action = 0;
 }
@@ -2509,7 +2499,6 @@ DEFINE_I_CALLBACK(add_line_hotkey)
   o_line_start(w_current, mouse_x, mouse_y);
 
   w_current->inside_action = 1;
-  i_allow_expose();
   i_set_state(w_current, ENDLINE);
 }
 
@@ -2529,7 +2518,6 @@ DEFINE_I_CALLBACK(add_box)
 
   i_update_middle_button(w_current, i_callback_add_box, _("Box"));
   w_current->inside_action = 0;
-  i_allow_expose();
   i_set_state(w_current, DRAWBOX);
 }
 
@@ -2552,7 +2540,6 @@ DEFINE_I_CALLBACK(add_box_hotkey)
   o_box_start(w_current, mouse_x, mouse_y);
 
   w_current->inside_action = 1;
-  i_allow_expose();
   i_set_state(w_current, ENDBOX);
 }
 
@@ -2606,7 +2593,6 @@ DEFINE_I_CALLBACK(add_circle)
 
   i_update_middle_button(w_current, i_callback_add_circle, _("Circle"));
   w_current->inside_action = 0;
-  i_allow_expose();
   i_set_state(w_current, DRAWCIRCLE);
 }
 
@@ -2630,7 +2616,6 @@ DEFINE_I_CALLBACK(add_circle_hotkey)
   o_circle_start(w_current, mouse_x, mouse_y);
 
   w_current->inside_action = 1;
-  i_allow_expose();
   i_set_state(w_current, ENDCIRCLE);
 }
 
@@ -2650,7 +2635,6 @@ DEFINE_I_CALLBACK(add_arc)
 
   i_update_middle_button(w_current, i_callback_add_arc, _("Arc"));
   w_current->inside_action = 0;
-  i_allow_expose();
   i_set_state(w_current, DRAWARC);
 }
 
@@ -2673,7 +2657,6 @@ DEFINE_I_CALLBACK(add_arc_hotkey)
   o_arc_start(w_current, mouse_x, mouse_y);
 
   w_current->inside_action = 1;
-  i_allow_expose();
   i_set_state(w_current, ENDARC);
 }
 
@@ -2693,7 +2676,6 @@ DEFINE_I_CALLBACK(add_pin)
 
   i_update_middle_button(w_current, i_callback_add_pin, _("Pin"));
   w_current->inside_action = 0;
-  i_allow_expose();
   i_set_state(w_current, DRAWPIN);
 }
 
@@ -2716,7 +2698,6 @@ DEFINE_I_CALLBACK(add_pin_hotkey)
   o_pin_start(w_current, mouse_x, mouse_y);
 
   w_current->inside_action = 1;
-  i_allow_expose();
   i_set_state(w_current, ENDPIN);
 }
 
diff --git a/gschem/src/o_picture.c b/gschem/src/o_picture.c
index e9c9185..61a23e3 100644
--- a/gschem/src/o_picture.c
+++ b/gschem/src/o_picture.c
@@ -222,7 +222,6 @@ void picture_selection_dialog (TOPLEVEL *w_current)
       o_picture_set_pixbuf(w_current, pixbuf, filename);
     
       w_current->page_current->CHANGED=1;
-      i_allow_expose();
       i_set_state(w_current, DRAWPICTURE);
     }
     g_free (filename);
@@ -767,8 +766,6 @@ void picture_change_filename_dialog (TOPLEVEL *w_current)
 
       g_object_unref(pixbuf);
       w_current->page_current->CHANGED=1;
-  
-      i_allow_expose();
     }
     g_free (filename);
   }
-- 
1.5.1.3



More information about the geda-dev mailing list