Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / libgeda / src / s_menu.c
blob74599db599d94e142b9e19c4c492fd6f4634fc5d
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., 59 Temple Place, Suite 330, Boston, MA 02111 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 /*! \brief */
38 struct st_menu {
39 char *menu_name;
40 SCM menu_items;
43 static int menu_index=0;
45 #define MAX_MENUS 32
47 /* and eventually make this unlimited */
48 /* hack hack */
49 static struct st_menu menu[MAX_MENUS];
51 /*! \todo Finish function documentation!!!
52 * \brief
53 * \par Function Description
56 int s_menu_return_num(void)
58 return(menu_index);
61 /*! \todo Finish function documentation!!!
62 * \brief
63 * \par Function Description
66 SCM s_menu_return_entry(int index, char **menu_name)
68 if (menu_name == NULL) {
69 return SCM_BOOL_F;
72 if (index > MAX_MENUS || index < 0) {
73 *menu_name = NULL;
74 return SCM_BOOL_F;
77 *menu_name = menu[index].menu_name;
78 return(menu[index].menu_items);
81 /*! \todo Finish function documentation!!!
82 * \brief
83 * \par Function Description
86 int s_menu_add_entry(char *new_menu, SCM menu_items)
88 if (new_menu == NULL) {
89 return(-1);
92 if (menu_index >= MAX_MENUS) {
93 return(-1);
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++;
101 return(menu_index);
104 /*! \todo Finish function documentation!!!
105 * \brief
106 * \par Function Description
109 void s_menu_print()
111 int i;
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");
120 /*! \todo Finish function documentation!!!
121 * \brief
122 * \par Function Description
125 void s_menu_free()
127 int i;
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);
137 menu_index=0;
140 /*! \todo Finish function documentation!!!
141 * \brief
142 * \par Function Description
145 void s_menu_init()
147 int i;
148 for (i = 0; i < MAX_MENUS; i++) {
149 menu[i].menu_name = NULL;