gattrib

s_attrib.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
00003  * Copyright (C) 2003-2010 Stuart D. Brorson.
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 
00028 #include <config.h>
00029 
00030 #include <stdio.h>
00031 #include <math.h>
00032 #ifdef HAVE_STRING_H
00033 #include <string.h>
00034 #endif
00035 
00036 /*------------------------------------------------------------------
00037  * Gattrib specific includes
00038  *------------------------------------------------------------------*/
00039 #include <libgeda/libgeda.h>       /* geda library fcns  */
00040 #include "../include/struct.h"     /* typdef and struct declarations */
00041 #include "../include/prototype.h"  /* function prototypes */
00042 #include "../include/globals.h"
00043 
00044 #ifdef HAVE_LIBDMALLOC
00045 #include <dmalloc.h>
00046 #endif
00047 
00048 
00049 /*------------------------------------------------------------------*/
00059 int s_attrib_name_in_list(STRING_LIST *name_value_list, char *name)
00060 {
00061   STRING_LIST *local_list_item;
00062   char *local_name;
00063 
00064   for (local_list_item = name_value_list;
00065        local_list_item != NULL;
00066        local_list_item = local_list_item->next) {
00067 
00068     if (local_list_item->data == NULL)
00069       continue;
00070 
00071     local_name = u_basic_breakup_string(local_list_item->data, '=', 0);
00072     if (strcmp(local_name, name) == 0) {
00073       g_free (local_name);
00074       return TRUE;
00075     }
00076     g_free (local_name);
00077   }
00078   return FALSE;
00079 }
00080 
00081 
00082 /*------------------------------------------------------------------*/
00092 char *s_attrib_get_refdes(OBJECT *object)
00093 {
00094   char *temp_uref;
00095   char *numslots_value;
00096   char *slot_value;
00097   OBJECT *slot_text_object;
00098 
00099   /*------ Try to get the refdes -----*/
00100   temp_uref = o_attrib_search_object_attribs_by_name (object, "refdes", 0);
00101   if (!temp_uref) {
00102     temp_uref = o_attrib_search_object_attribs_by_name (object, "uref", 0); // deprecated
00103     if (temp_uref) {
00104       printf("WARNING: Found uref=%s, uref= is deprecated, please use refdes=\n", temp_uref);
00105     } else {        /* didn't find refdes.  Report error to log. */
00106 #ifdef DEBUG
00107       printf("In s_attrib_get_refdes, found non-graphical component with no refdes.\n");
00108       printf(". . . . complex_basename = %s.\n", object->complex_basename);
00109 #endif
00110       return NULL;
00111     } 
00112   }
00113 
00114 #ifdef DEBUG
00115   printf("In s_attrib_get_refdes, found component with refdes %s.\n", temp_uref);
00116 #endif   
00117   
00118   /*------- Now append .slot to refdes if part is slotted -------- */
00119   /* Find out if this is a multislotted component */
00120   numslots_value =
00121     o_attrib_search_object_attribs_by_name (object, "numslots", 0);
00122   if (numslots_value != NULL) {  /* this is a slotted component; 
00123                     append slot number to refdes. */
00124     slot_value = s_slot_search_slot (object, &slot_text_object);
00125 #if DEBUG
00126     printf(". . .  , found slotted component with slot = %s\n", slot_value);
00127 #endif
00128     temp_uref = g_strconcat(temp_uref, ".", slot_value, NULL);
00129   }
00130 
00131 #ifdef DEBUG
00132   printf(". . . .   returning refdes %s.\n", temp_uref);
00133 #endif   
00134   
00135   return temp_uref;
00136 
00137 }
00138 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines