1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2010 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
22 * \brief Functions to operate on attributes in STRING_LISTs
24 * Various functions to operate on attribute name=value pairs in supplied
25 * STRING_LIST structs.
36 /*------------------------------------------------------------------
37 * Gattrib specific includes
38 *------------------------------------------------------------------*/
39 #include <libgeda/libgeda.h> /* geda library fcns */
40 #include "../include/struct.h" /* typdef and struct declarations */
41 #include "../include/prototype.h" /* function prototypes */
42 #include "../include/globals.h"
44 #ifdef HAVE_LIBDMALLOC
49 /*------------------------------------------------------------------*/
50 /*! \brief Detect "name" in STRING_LIST
52 * This function is passed a STRING_LIST of name=value pairs, and a
54 * \param name_value_list pointer to STRING_LIST to search
55 * \param name name string to search for
56 * \returns 1 (TRUE) if the name is in the STRING_LIST, otherwise
57 * it returns 0 (FALSE).
59 int s_attrib_name_in_list(STRING_LIST
*name_value_list
, char *name
)
61 STRING_LIST
*local_list_item
;
64 for (local_list_item
= name_value_list
;
65 local_list_item
!= NULL
;
66 local_list_item
= local_list_item
->next
) {
68 if (local_list_item
->data
== NULL
)
71 local_name
= u_basic_breakup_string(local_list_item
->data
, '=', 0);
72 if (strcmp(local_name
, name
) == 0) {
82 /*------------------------------------------------------------------*/
83 /*! \brief Locate the refdes associated with an object.
85 * This fcn takes an object, finds its refdes and returns it.
86 * \param object Pointer to the object to search for.
87 * \return For normal components, it returns a pointer to a
88 * string containing the refdes. If the component is slotted,
89 * it returns a refdes of the form
90 * refdes.slot. If no refdes is found, it returns NULL.
92 char *s_attrib_get_refdes(OBJECT
*object
)
97 OBJECT
*slot_text_object
;
99 /*------ Try to get the refdes -----*/
100 temp_uref
= o_attrib_search_object_attribs_by_name (object
, "refdes", 0);
102 temp_uref
= o_attrib_search_object_attribs_by_name (object
, "uref", 0); // deprecated
104 printf("WARNING: Found uref=%s, uref= is deprecated, please use refdes=\n", temp_uref
);
105 } else { /* didn't find refdes. Report error to log. */
107 printf("In s_attrib_get_refdes, found non-graphical component with no refdes.\n");
108 printf(". . . . complex_basename = %s.\n", object
->complex_basename
);
115 printf("In s_attrib_get_refdes, found component with refdes %s.\n", temp_uref
);
118 /*------- Now append .slot to refdes if part is slotted -------- */
119 /* Find out if this is a multislotted component */
121 o_attrib_search_object_attribs_by_name (object
, "numslots", 0);
122 if (numslots_value
!= NULL
) { /* this is a slotted component;
123 append slot number to refdes. */
124 slot_value
= s_slot_search_slot (object
, &slot_text_object
);
126 printf(". . . , found slotted component with slot = %s\n", slot_value
);
128 temp_uref
= g_strconcat(temp_uref
, ".", slot_value
, NULL
);
132 printf(". . . . returning refdes %s.\n", temp_uref
);