libgeda

s_attrib.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * libgeda - gEDA's library
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <sys/types.h>
00024 #ifdef HAVE_STDLIB_H
00025 #include <stdlib.h>
00026 #endif
00027 #ifdef HAVE_STRING_H
00028 #include <string.h>
00029 #endif
00030 
00031 #include "libgeda_priv.h"
00032 
00033 #ifdef HAVE_LIBDMALLOC
00034 #include <dmalloc.h>
00035 #endif
00036 
00037 #define MAX_ATTRIBS 128
00038 
00040 struct st_attrib_names {
00041   char *attrib_name;
00042 };
00043 
00045 static int attrib_index=0;
00046 
00048 /* and eventually make this unlimited */
00049 /* hack hack */
00050 static struct st_attrib_names attrib[MAX_ATTRIBS];
00051 
00057 int s_attrib_add_entry(char *new_attrib) 
00058 {
00059   if (new_attrib == NULL) {
00060     return(-1); 
00061   }
00062 
00063   if (attrib_index >= MAX_ATTRIBS) {
00064     return(-1); 
00065   }
00066     
00067   attrib[attrib_index].attrib_name = g_strdup (new_attrib);
00068 
00069   attrib_index++;
00070   return(attrib_index);
00071 }
00072 
00078 void s_attrib_print()
00079 {
00080   int i;
00081 
00082   for (i = 0; i < attrib_index; i++) {
00083     printf("%s\n", attrib[i].attrib_name);
00084   }
00085 }
00086 
00092 /* true for uniqueness, zero for duplication */
00093 int s_attrib_uniq(char *name)
00094 {
00095   int i;
00096 
00097   for (i = 0; i < attrib_index; i++) {
00098     if (strcmp(attrib[i].attrib_name, name) == 0) {
00099       return(0);
00100     }
00101   }
00102 
00103   return(1);
00104 }
00105 
00111 void s_attrib_free()
00112 {
00113   int i;
00114 
00115   for (i = 0; i < attrib_index; i++) {
00116      g_free(attrib[i].attrib_name);
00117   }
00118 
00119   attrib_index=0;
00120 }
00121 
00127 void s_attrib_init()
00128 {
00129   int i;
00130   for (i = 0; i < MAX_ATTRIBS; i++) {
00131     attrib[i].attrib_name = NULL;   
00132   } 
00133 }
00134 
00140 char *s_attrib_get(int counter)
00141 {
00142   if (counter < attrib_index) {
00143     return(attrib[counter].attrib_name);
00144   }
00145 
00146   return(NULL);
00147 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines