libgeda

s_menu.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 
00038 struct st_menu {
00039   char *menu_name;
00040   SCM menu_items;
00041 };
00042 
00043 static int menu_index=0;
00044 
00045 #define MAX_MENUS   32
00046 
00047 /* and eventually make this unlimited */
00048 /* hack hack */
00049 static struct st_menu menu[MAX_MENUS];
00050 
00056 int s_menu_return_num(void) 
00057 {
00058   return(menu_index);
00059 }
00060 
00066 SCM s_menu_return_entry(int index, char **menu_name) 
00067 {
00068   if (menu_name == NULL) {
00069     return SCM_BOOL_F;
00070   }
00071 
00072   if (index >= MAX_MENUS || index < 0) {
00073     *menu_name = NULL;
00074     return SCM_BOOL_F;
00075   }
00076 
00077   *menu_name = menu[index].menu_name;
00078   return(menu[index].menu_items);
00079 }
00080 
00086 int s_menu_add_entry(char *new_menu, SCM menu_items) 
00087 {
00088   if (new_menu == NULL) {
00089     return(-1); 
00090   }
00091 
00092   if (menu_index >= MAX_MENUS) {
00093     return(-1); 
00094   }
00095 
00096   menu[menu_index].menu_name = g_strdup (new_menu);
00097   scm_gc_protect_object (menu_items);
00098   menu[menu_index].menu_items = menu_items;
00099   menu_index++;
00100   
00101   return(menu_index);
00102 }
00103 
00109 void s_menu_print()
00110 {
00111   int i;
00112 
00113   for (i = 0; i < menu_index; i++) {
00114     printf("Name; %s\n", menu[i].menu_name);
00115     scm_display (menu[i].menu_items, scm_current_output_port ());
00116     printf("\n");
00117   }
00118 }
00119 
00125 void s_menu_free()
00126 {
00127   int i;
00128 
00129   for (i = 0; i < menu_index; i++) {
00130     if (menu[i].menu_name) {
00131       g_free(menu[i].menu_name);
00132       menu[i].menu_name = NULL;
00133       scm_gc_unprotect_object (menu[i].menu_items);
00134     }       
00135   }
00136 
00137   menu_index=0;
00138 }
00139 
00145 void s_menu_init()
00146 {
00147   int i;
00148   for (i = 0; i < MAX_MENUS; i++) {
00149     menu[i].menu_name = NULL;   
00150   } 
00151 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines