Updated all po files by running make update-po (in prep for a release)
[geda-gaf/whiteaudio.git] / gattrib / src / s_attrib.c
blob289305b0e786648936edbd0b949c706ed5fa8daf
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 local_list_item = name_value_list;
54 while (local_list_item != NULL) {
55 local_name = u_basic_breakup_string(local_list_item->data, '=', 0);
56 if (strcmp(local_name, name) == 0) {
57 return TRUE;
59 local_list_item = local_list_item->next;
61 return FALSE;
65 /*------------------------------------------------------------------*/
66 /*! \brief This fcn takes an object, finds its refdes and returns it.
68 * \return For normal components, it returns a (pointer to a)
69 * string containing the
70 * refdes If the component is slotted, it returns a refdes of the form
71 * refdes.slot. If no refdes is found, it returns NULL.
72 *------------------------------------------------------------------*/
73 char *s_attrib_get_refdes(OBJECT *object)
75 char *temp_uref;
76 char *numslots_value;
77 char *slot_value;
78 OBJECT *slot_text_object;
80 /*------ Try to get the refdes -----*/
81 temp_uref = o_attrib_search_name_single(object, "refdes", NULL);
82 if (!temp_uref) {
83 temp_uref = o_attrib_search_name_single(object, "uref", NULL); // deprecated
84 if (temp_uref) {
85 printf("WARNING: Found uref=%s, uref= is deprecated, please use refdes=\n", temp_uref);
86 } else { /* didn't find refdes. Report error to log. */
87 #ifdef DEBUG
88 printf("In s_attrib_get_refdes, found non-graphical component with no refdes.\n");
89 printf(". . . . complex_basename = %s.\n", object->complex_basename);
90 #endif
91 return NULL;
95 #ifdef DEBUG
96 printf("In s_attrib_get_refdes, found component with refdes %s.\n", temp_uref);
97 #endif
99 /*------- Now append .slot to refdes if part is slotted -------- */
100 /* Find out if this is a multislotted component */
101 numslots_value = o_attrib_search_numslots(object, NULL);
102 if (numslots_value != NULL) { /* this is a slotted component;
103 append slot number to refdes. */
104 slot_value = o_attrib_search_slot(object, &slot_text_object);
105 #if DEBUG
106 printf(". . . , found slotted component with slot = %s\n", slot_value);
107 #endif
108 temp_uref = g_strconcat(temp_uref, ".", slot_value, NULL);
111 #ifdef DEBUG
112 printf(". . . . returning refdes %s.\n", temp_uref);
113 #endif
115 return temp_uref;