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)
5  *
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.
10  *
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.
15  *
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
19  */
20 #include <config.h>
21 
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
30 
31 #include "libgeda_priv.h"
32 
33 #ifdef HAVE_LIBDMALLOC
34 #include <dmalloc.h>
35 #endif
36 
37 /*! \brief */
38 struct st_menu {
39   char *menu_name;
40   SCM menu_items;
41 };
42 
43 static int menu_index=0;
44 
45 #define MAX_MENUS	32
46 
47 /* and eventually make this unlimited */
48 /* hack hack */
49 static struct st_menu menu[MAX_MENUS];
50 
51 /*! \todo Finish function documentation!!!
52  *  \brief
53  *  \par Function Description
54  *
55  */
s_menu_return_num(void)56 int s_menu_return_num(void)
57 {
58   return(menu_index);
59 }
60 
61 /*! \todo Finish function documentation!!!
62  *  \brief
63  *  \par Function Description
64  *
65  */
s_menu_return_entry(int index,char ** menu_name)66 SCM s_menu_return_entry(int index, char **menu_name)
67 {
68   if (menu_name == NULL) {
69     return SCM_BOOL_F;
70   }
71 
72   if (index >= MAX_MENUS || index < 0) {
73     *menu_name = NULL;
74     return SCM_BOOL_F;
75   }
76 
77   *menu_name = menu[index].menu_name;
78   return(menu[index].menu_items);
79 }
80 
81 /*! \todo Finish function documentation!!!
82  *  \brief
83  *  \par Function Description
84  *
85  */
s_menu_add_entry(char * new_menu,SCM menu_items)86 int s_menu_add_entry(char *new_menu, SCM menu_items)
87 {
88   if (new_menu == NULL) {
89     return(-1);
90   }
91 
92   if (menu_index >= MAX_MENUS) {
93     return(-1);
94   }
95 
96   menu[menu_index].menu_name = g_strdup (new_menu);
97   scm_gc_protect_object (menu_items);
98   menu[menu_index].menu_items = menu_items;
99   menu_index++;
100 
101   return(menu_index);
102 }
103 
104 /*! \todo Finish function documentation!!!
105  *  \brief
106  *  \par Function Description
107  *
108  */
s_menu_print()109 void s_menu_print()
110 {
111   int i;
112 
113   for (i = 0; i < menu_index; i++) {
114     printf("Name; %s\n", menu[i].menu_name);
115     scm_display (menu[i].menu_items, scm_current_output_port ());
116     printf("\n");
117   }
118 }
119 
120 /*! \todo Finish function documentation!!!
121  *  \brief
122  *  \par Function Description
123  *
124  */
s_menu_free()125 void s_menu_free()
126 {
127   int i;
128 
129   for (i = 0; i < menu_index; i++) {
130     if (menu[i].menu_name) {
131       g_free(menu[i].menu_name);
132       menu[i].menu_name = NULL;
133       scm_gc_unprotect_object (menu[i].menu_items);
134     }
135   }
136 
137   menu_index=0;
138 }
139 
140 /*! \todo Finish function documentation!!!
141  *  \brief
142  *  \par Function Description
143  *
144  */
s_menu_init()145 void s_menu_init()
146 {
147   int i;
148   for (i = 0; i < MAX_MENUS; i++) {
149     menu[i].menu_name = NULL;
150   }
151 }
152