libgeda: Remove some exit() calls and assertions.
[geda-gaf/peter-b.git] / libgeda / src / s_attrib.c
blobb281bfa5da1b9516154a0626472aeee27ac21664
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
22 #include <stdio.h>
23 #include <sys/types.h>
24 #ifdef HAVE_STDLIB_H
25 #include <stdlib.h>
26 #endif
27 #ifdef HAVE_STRING_H
28 #include <string.h>
29 #endif
31 #include "libgeda_priv.h"
33 #ifdef HAVE_LIBDMALLOC
34 #include <dmalloc.h>
35 #endif
37 #define MAX_ATTRIBS 128
39 /*! \brief */
40 struct st_attrib_names {
41 char *attrib_name;
44 /*! \brief */
45 static int attrib_index=0;
47 /*! \brief */
48 /* and eventually make this unlimited */
49 /* hack hack */
50 static struct st_attrib_names attrib[MAX_ATTRIBS];
52 /*! \todo Finish function documentation!!!
53 * \brief
54 * \par Function Description
57 int s_attrib_add_entry(char *new_attrib)
59 if (new_attrib == NULL) {
60 return(-1);
63 if (attrib_index >= MAX_ATTRIBS) {
64 return(-1);
67 attrib[attrib_index].attrib_name = g_strdup (new_attrib);
69 attrib_index++;
70 return(attrib_index);
73 /*! \todo Finish function documentation!!!
74 * \brief
75 * \par Function Description
78 void s_attrib_print()
80 int i;
82 for (i = 0; i < attrib_index; i++) {
83 printf("%s\n", attrib[i].attrib_name);
87 /*! \todo Finish function documentation!!!
88 * \brief
89 * \par Function Description
92 /* true for uniqueness, zero for duplication */
93 int s_attrib_uniq(char *name)
95 int i;
97 for (i = 0; i < attrib_index; i++) {
98 if (strcmp(attrib[i].attrib_name, name) == 0) {
99 return(0);
103 return(1);
106 /*! \todo Finish function documentation!!!
107 * \brief
108 * \par Function Description
111 void s_attrib_free()
113 int i;
115 for (i = 0; i < attrib_index; i++) {
116 g_free(attrib[i].attrib_name);
119 attrib_index=0;
122 /*! \todo Finish function documentation!!!
123 * \brief
124 * \par Function Description
127 void s_attrib_init()
129 int i;
130 for (i = 0; i < MAX_ATTRIBS; i++) {
131 attrib[i].attrib_name = NULL;
135 /*! \todo Finish function documentation!!!
136 * \brief
137 * \par Function Description
140 char *s_attrib_get(int counter)
142 if (counter < attrib_index) {
143 return(attrib[counter].attrib_name);
146 return(NULL);