gschem

s_stretch.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * libgeda - gEDA's library
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 
00024 #include "gschem.h"
00025 
00026 #ifdef HAVE_LIBDMALLOC
00027 #include <dmalloc.h>
00028 #endif
00029 
00030 
00036 GList *s_stretch_add (GList *list, OBJECT *object, int whichone)
00037 {
00038   GList *s_iter;
00039   STRETCH *s_new;
00040 
00041   /* Check if the object is already in the stretch list */
00042   for (s_iter = list; s_iter != NULL; s_iter = g_list_next (s_iter)) {
00043     STRETCH *s_current = s_iter->data;
00044     if (s_current->object->sid == object->sid) {
00045       return list;
00046     }
00047   }
00048 
00049   s_new = g_malloc (sizeof (STRETCH));
00050   s_new->object = object;
00051   s_new->whichone = whichone;
00052 
00053   return g_list_append (list, s_new);
00054 }
00055 
00056 
00067 static gint find_object (gconstpointer a, gconstpointer b)
00068 {
00069   return (((STRETCH *)a)->object == (OBJECT *)b) ? 0 : 1;
00070 }
00071 
00072 
00078 GList *s_stretch_remove (GList *list, OBJECT *object)
00079 {
00080   GList *item;
00081 
00082   g_return_val_if_fail (object != NULL, list);
00083 
00084   item = g_list_find_custom (list, object, find_object);
00085   g_free (item->data);
00086 
00087   return g_list_delete_link (list, item);
00088 }
00089 
00090 
00096 void s_stretch_print_all (GList *list)
00097 {
00098   GList *iter;
00099 
00100   printf("START printing stretch ********************\n");
00101   for (iter = list; iter != NULL; iter = g_list_next (iter)) {
00102     STRETCH *s_current = iter->data;
00103 
00104     if (s_current->object) {
00105       printf("Object: %s\n", s_current->object->name);
00106     } else {
00107       printf("Object is NULL\n");
00108     }
00109 
00110     printf("which one: %d\n", s_current->whichone);
00111   }
00112   printf("DONE printing stretch ********************\n\n");
00113 }
00114 
00120 void s_stretch_destroy_all (GList *list)
00121 {
00122   g_list_foreach (list, (GFunc)g_free, NULL);
00123   g_list_free (list);
00124 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines