Ran make update-po in gschem in prep for a new release (v1.5.4)
[geda-gaf/peter-b.git] / gattrib / src / s_attrib.c
blob615bde84c56560b95fddc604140cd25bd338e7a3
1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2008 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 /*!
21 * \file
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.
28 #include <config.h>
30 #include <stdio.h>
31 #include <math.h>
32 #ifdef HAVE_STRING_H
33 #include <string.h>
34 #endif
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
45 #include <dmalloc.h>
46 #endif
49 /*------------------------------------------------------------------*/
50 /*! \brief Detect "name" in STRING_LIST
52 * This function is passed a STRING_LIST of name=value pairs, and a
53 * name.
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;
62 char *local_name;
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)
69 continue;
71 local_name = u_basic_breakup_string(local_list_item->data, '=', 0);
72 if (strcmp(local_name, name) == 0) {
73 g_free (local_name);
74 return TRUE;
76 g_free (local_name);
78 return FALSE;
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)
94 char *temp_uref;
95 char *numslots_value;
96 char *slot_value;
97 OBJECT *slot_text_object;
99 /*------ Try to get the refdes -----*/
100 temp_uref = o_attrib_search_object_attribs_by_name (object, "refdes", 0);
101 if (!temp_uref) {
102 temp_uref = o_attrib_search_object_attribs_by_name (object, "uref", 0); // deprecated
103 if (temp_uref) {
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. */
106 #ifdef DEBUG
107 printf("In s_attrib_get_refdes, found non-graphical component with no refdes.\n");
108 printf(". . . . complex_basename = %s.\n", object->complex_basename);
109 #endif
110 return NULL;
114 #ifdef DEBUG
115 printf("In s_attrib_get_refdes, found component with refdes %s.\n", temp_uref);
116 #endif
118 /*------- Now append .slot to refdes if part is slotted -------- */
119 /* Find out if this is a multislotted component */
120 numslots_value =
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 = o_attrib_search_slot(object, &slot_text_object);
125 #if DEBUG
126 printf(". . . , found slotted component with slot = %s\n", slot_value);
127 #endif
128 temp_uref = g_strconcat(temp_uref, ".", slot_value, NULL);
131 #ifdef DEBUG
132 printf(". . . . returning refdes %s.\n", temp_uref);
133 #endif
135 return temp_uref;