Expose permanent debugging code to the C compiler.
[geda-gaf/berndj.git] / gattrib / src / s_attrib.c
blobf7dd7935afa76975812c04fd076dfcf5285db34b
1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2007 Stuart D. Brorson.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
22 #include <stdio.h>
23 #include <math.h>
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
28 /*------------------------------------------------------------------
29 * Gattrib specific includes
30 *------------------------------------------------------------------*/
31 #include <libgeda/libgeda.h> /* geda library fcns */
32 #include "../include/struct.h" /* typdef and struct declarations */
33 #include "../include/prototype.h" /* function prototypes */
34 #include "../include/globals.h"
36 #ifdef HAVE_LIBDMALLOC
37 #include <dmalloc.h>
38 #endif
41 /*------------------------------------------------------------------*/
42 /*! \brief This fcn is passed a STRING_LIST of name=value pairs, and a
43 * name.
45 * \return It returns 1 (TRUE) if the name is in the STRING_LIST, otherwise
46 * it returns 0 (FALSE).
47 *------------------------------------------------------------------*/
48 int s_attrib_name_in_list(STRING_LIST *name_value_list, char *name)
50 STRING_LIST *local_list_item;
51 char *local_name;
53 for (local_list_item = name_value_list;
54 local_list_item != NULL;
55 local_list_item = local_list_item->next) {
57 if (local_list_item->data == NULL)
58 continue;
60 local_name = u_basic_breakup_string(local_list_item->data, '=', 0);
61 if (strcmp(local_name, name) == 0) {
62 g_free (local_name);
63 return TRUE;
65 g_free (local_name);
67 return FALSE;
71 /*------------------------------------------------------------------*/
72 /*! \brief This fcn takes an object, finds its refdes and returns it.
74 * \return For normal components, it returns a (pointer to a)
75 * string containing the
76 * refdes If the component is slotted, it returns a refdes of the form
77 * refdes.slot. If no refdes is found, it returns NULL.
78 *------------------------------------------------------------------*/
79 char *s_attrib_get_refdes(OBJECT *object)
81 char *temp_uref;
82 char *numslots_value;
83 char *slot_value;
84 OBJECT *slot_text_object;
86 /*------ Try to get the refdes -----*/
87 temp_uref = o_complex_get_refdes(object, NULL);
88 if (!temp_uref) {
89 if (GEDA_DEBUG) {
90 printf("In s_attrib_get_refdes, found non-graphical component with no refdes.\n");
91 printf(". . . . complex_basename = %s.\n", object->complex_basename);
93 return NULL;
96 if (GEDA_DEBUG) {
97 printf("In s_attrib_get_refdes, found component with refdes %s.\n", temp_uref);
100 /*------- Now append .slot to refdes if part is slotted -------- */
101 /* Find out if this is a multislotted component */
102 numslots_value = o_attrib_search_numslots(object, NULL);
103 if (numslots_value != NULL) { /* this is a slotted component;
104 append slot number to refdes. */
105 slot_value = o_attrib_search_slot(object, &slot_text_object);
106 if (GEDA_DEBUG) {
107 printf(". . . , found slotted component with slot = %s\n", slot_value);
109 temp_uref = g_strconcat(temp_uref, ".", slot_value, NULL);
112 if (GEDA_DEBUG) {
113 printf(". . . . returning refdes %s.\n", temp_uref);
116 return temp_uref;