[asterisk-commits] branch group/autoconf_and_menuselect r8867 - in /team/group/autoconf_and_menu...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 31 14:20:28 MST 2006


Author: russell
Date: Sun Jan 29 16:28:56 2006
New Revision: 8867

URL: http://svn.digium.com/view/asterisk?rev=8867&view=rev
Log:
- allow F7 to deselect all, F8 to select all
- don't allow the asterisk build to continue without the existance of asterisk.makeopts
- add more comments and various code cleanup

Modified:
    team/group/autoconf_and_menuselect/Makefile
    team/group/autoconf_and_menuselect/build_tools/menuselect.c
    team/group/autoconf_and_menuselect/build_tools/menuselect.h

Modified: team/group/autoconf_and_menuselect/Makefile
URL: http://svn.digium.com/view/asterisk/team/group/autoconf_and_menuselect/Makefile?rev=8867&r1=8866&r2=8867&view=diff
==============================================================================
--- team/group/autoconf_and_menuselect/Makefile (original)
+++ team/group/autoconf_and_menuselect/Makefile Sun Jan 29 16:28:56 2006
@@ -434,7 +434,7 @@
 
 CFLAGS+=-DT38_SUPPORT
 
-_all: all
+_all: makeopts all
 	@echo " +--------- Asterisk Build Complete ---------+"  
 	@echo " + Asterisk has successfully been built, but +"  
 	@echo " + cannot be run before being installed by   +"  
@@ -444,6 +444,9 @@
 	@echo " +-------------------------------------------+"  
 
 all: cleantest depend asterisk subdirs 
+
+makeopts:
+	@test -f asterisk.makeopts || ( echo "You must run ./configure and make menuselect!" && exit 1 )
 
 #ifneq ($(wildcard tags),)
 ctags: tags

Modified: team/group/autoconf_and_menuselect/build_tools/menuselect.c
URL: http://svn.digium.com/view/asterisk/team/group/autoconf_and_menuselect/build_tools/menuselect.c?rev=8867&r1=8866&r2=8867&view=diff
==============================================================================
--- team/group/autoconf_and_menuselect/build_tools/menuselect.c (original)
+++ team/group/autoconf_and_menuselect/build_tools/menuselect.c Sun Jan 29 16:28:56 2006
@@ -21,6 +21,12 @@
  * \author Russell Bryant <russell at digium.com>
  * 
  * \brief a generic 'make menuselect' system
+ *
+ * \todo Allow the output makeopts filename to be optionally specified as a command line argument
+ * \todo Display the description of the category or member when the user hits a certain key
+ * \todo Deprecate the displayname in the member structure when the description display gets implemented
+ * \todo Allow nested categories for more organized menus - A single variable should be generated with values
+ *       from all of the members of child categories using the name of the top-level category.
  */
 
 #include <stdlib.h>
@@ -39,16 +45,9 @@
 #define MIN_X		80
 #define MIN_Y		20
 
-#define MENUSELECT_DEBUG
-
-#define my_calloc(num, len) \
-	({ \
-		void *__tmp; \
-		__tmp = calloc(num, len); \
-		if (!__tmp) \
-			fprintf(stderr, "Memory allocation error!\n"); \
-		__tmp; \
-	})
+#define PAGE_OFFSET	10
+
+/* #define MENUSELECT_DEBUG */
 
 /*!
    The member and category structures are used to maintain our own list of all
@@ -101,6 +100,7 @@
 
 /*! } */
 
+/*! The list of categories */
 AST_LIST_HEAD_NOLOCK_STATIC(categories, category);
 
 /*!
@@ -120,19 +120,33 @@
 /*! The list of trees from maketops.xml files */
 AST_LIST_HEAD_NOLOCK_STATIC(trees, tree);
 
-/*! The output build configuration file - TODO Make this optionally specified as a command line argument */
-const char *output_makeopts = OUTPUT_MAKEOPTS_DEFAULT;
-
 /*! Maximum number of characters horizontally */
 int max_x = 0;
 /*! Maximum number of characters vertically */
 int max_y = 0;
 
+char *output_makeopts = OUTPUT_MAKEOPTS_DEFAULT;
+
+/*! \brief a wrapper for calloc() that generates an error message if the allocation fails */
+static inline void *my_calloc(size_t num, size_t len)
+{
+	void *tmp;
+
+	tmp = calloc(num, len);
+	
+	if (!tmp)
+		fprintf(stderr, "Memory allocation error!\n");
+
+	return tmp;
+}
+
+/*! \brief returns non-zero if the string is not defined, or has zero length */
 static inline int strlen_zero(const char *s)
 {
 	return (!s || (*s == '\0'));
 }
 
+/*! \brief return a pointer to the first non-whitespace character */
 static inline char *skip_blanks(char *str)
 {
 	if (!str)
@@ -144,6 +158,7 @@
 	return str;
 }
 
+/*! \brief Add a category to the category list, ensuring that there are no duplicates */
 int add_category(struct category *cat)
 {
 	struct category *tmp;
@@ -154,18 +169,15 @@
 			return -1;
 		}
 	}
-
 	AST_LIST_INSERT_TAIL(&categories, cat, list);
 
 	return 0;
 }
 
+/*! \brief Add a member to the member list of a category, ensuring that there are no duplicates */
 int add_member(struct member *mem, struct category *cat)
 {
 	struct member *tmp;
-
-	if (!cat || !mem)
-		return -1;	
 
 	AST_LIST_TRAVERSE(&cat->members, tmp, list) {
 		if (!strcmp(tmp->name, mem->name)) {
@@ -173,12 +185,12 @@
 			return -1;
 		}
 	}
-
 	AST_LIST_INSERT_TAIL(&cat->members, mem, list);
 
 	return 0;
 }
 
+/*! \brief Parse an input makeopts file */
 int parse_makeopts_xml(const char *makeopts_xml)
 {
 	FILE *f;
@@ -289,6 +301,7 @@
 	return 0;
 }
 
+/*! \brief Process dependencies against the input dependencies file */
 int process_deps(void)
 {
 	struct category *cat;
@@ -321,11 +334,15 @@
 		}
 	}
 
+	/* We save all of the other trees because we use them later.  We don't need this tree anymore. */
 	mxmlDelete(root);
 
+	close(f);
+
 	return 0;
 }
 
+/*! \brief Iterate through all of the input makeopts files and call the parse function on them */
 int build_member_list(void)
 {
 	int i;
@@ -341,6 +358,7 @@
 	return res;
 }
 
+/*! \brief Given the string representation of a member and category, find it and mark it as enabled */
 void mark_as_enabled(const char *member, const char *category)
 {
 	struct category *cat;
@@ -365,6 +383,7 @@
 		fprintf(stderr, "category '%s' not found! Can't mark '%s' as enabled.\n", category, member);
 }
 
+/*! \brief Toggle a member of a category at the specified index to enabled/disabled */
 void toggle_enabled(struct category *cat, int index)
 {
 	struct member *mem;
@@ -379,10 +398,11 @@
 		mem->enabled = !mem->enabled;
 }
 
+/*! \brief Parse an existing output makeopts file and enable members previously selected */
 void parse_existing_config(void)
 {
 	FILE *f;
-	char buf[1024];
+	char buf[2048];
 	char *category, *parse, *member;
 	int lineno = 0;
 
@@ -425,6 +445,7 @@
 	close(f);
 }
 
+/*! \brief Create the output makeopts file that results from the user's selections */
 int generate_makeopts_file(void)
 {
 	FILE *f;
@@ -436,10 +457,9 @@
 		return -1;
 	}
 
-	/* Traverse all categories (Makefile variables) */
+	/* Traverse all categories and members and output them as var/val pairs */
 	AST_LIST_TRAVERSE(&categories, cat, list) {
 		fprintf(f, "%s=", cat->name);
-		/* Write out all enabled members (values) */
 		AST_LIST_TRAVERSE(&cat->members, mem, list) {
 			if (mem->enabled)
 				fprintf(f, "%s ", mem->name);
@@ -453,6 +473,7 @@
 }
 
 #ifdef MENUSELECT_DEBUG
+/*! \brief Print out all of the information contained in our tree */
 void dump_member_list(void)
 {
 	struct category *cat;
@@ -476,6 +497,7 @@
 }
 #endif
 
+/*! \brief Free all categories and their members */
 void free_member_list(void)
 {
 	struct category *cat;
@@ -491,6 +513,7 @@
 	AST_LIST_TRAVERSE_SAFE_END
 }
 
+/*! \brief Free all of the XML trees */
 void free_trees(void)
 {
 	struct tree *tree;
@@ -501,6 +524,7 @@
 	}
 }
 
+/*! \brief Handle a window resize in xterm */
 void winch_handler(int sig)
 {
 	getmaxyx(stdscr, max_y, max_x);
@@ -512,6 +536,7 @@
 	}
 }
 
+/*! \brief Display help information */
 void show_help(WINDOW *win)
 {
 	int i;
@@ -522,7 +547,18 @@
 		waddstr(win, help_info[i]);	
 	}
 	wrefresh(win);
-	getch(); /* block until the user hits a key */
+	getch(); /* display the help until the user hits a key */
+}
+
+/*! \brief Enable/Disable all members of a category as long as dependencies have been met */
+void set_all(struct category *cat, int val)
+{
+	struct member *mem;
+
+	AST_LIST_TRAVERSE(&cat->members, mem, list) {
+		if (!mem->depsfailed)
+			mem->enabled = val;
+	}
 }
 
 void draw_main_menu(WINDOW *menu, int curopt)
@@ -630,7 +666,6 @@
 					start--;
 					end--;
 				}
-				draw_category_menu(menu, cat, start, end, curopt);
 			}
 			break;
 		case KEY_DOWN:
@@ -640,8 +675,13 @@
 					start++;
 					end++;
 				}
-				draw_category_menu(menu, cat, start, end, curopt);
 			}
+			break;
+		case KEY_NPAGE:
+			/* XXX Move down the list by PAGE_OFFSET */
+			break;
+		case KEY_PPAGE:
+			/* XXX Move up the list by PAGE_OFFSET */
 			break;
 		case KEY_LEFT:
 			return 0;
@@ -650,17 +690,22 @@
 		case '\n':
 		case ' ':
 			toggle_enabled(cat, curopt);
-			draw_category_menu(menu, cat, start, end, curopt);
 			break;
 		case 'h':
 		case 'H':
 			show_help(menu);
-			draw_category_menu(menu, cat, start, end, curopt);
+			break;
+		case KEY_F(7):
+			set_all(cat, 0);
+			break;
+		case KEY_F(8):
+			set_all(cat, 1);
 		default:
 			break;	
 		}
 		if (c == 'x' || c == 'q')
 			break;	
+		draw_category_menu(menu, cat, start, end, curopt);
 	}
 
 	wrefresh(menu);
@@ -690,55 +735,48 @@
 	int res = 0;
 
 	initscr();
-	
 	getmaxyx(stdscr, max_y, max_x);
-
-	signal(SIGWINCH, winch_handler);
+	signal(SIGWINCH, winch_handler); /* handle window resizing in xterm */
 
 	if (max_x < MIN_X - 1 || max_y < MIN_Y - 1) {
-		fprintf(stderr, "Terminal must be at least 80 x 25.\n");
+		fprintf(stderr, "Terminal must be at least %d x %d.\n", MIN_X, MIN_Y);
 		endwin();
 		return -1;
 	}
 
-	cbreak();
-	noecho();
-	keypad(stdscr, TRUE);
+	cbreak(); /* don't buffer input until the enter key is pressed */
+	noecho(); /* don't echo user input to the screen */
+	keypad(stdscr, TRUE); /* allow the use of arrow keys */
 	clear();
 	refresh();
 
+	maxopt = count_categories() - 1;
+	
+	/* We have two windows - the title window at the top, and the menu window gets the rest */
 	title = newwin(TITLE_HEIGHT, max_x, 0, 0);
+	menu = newwin(max_y - TITLE_HEIGHT, max_x, TITLE_HEIGHT, 0);
 	draw_title_window(title);	
-
-	menu = newwin(max_y - TITLE_HEIGHT, max_x, TITLE_HEIGHT, 0);
+	draw_main_menu(menu, curopt);
 	
-	draw_main_menu(menu, curopt);
-	maxopt = count_categories() - 1;
 	while ((c = getch())) {
 		switch (c) {
 		case KEY_UP:
-			if (curopt > 0) {
+			if (curopt > 0)
 				curopt--;
-				draw_main_menu(menu, curopt);
-			}
 			break;
 		case KEY_DOWN:
-			if (curopt < maxopt) {
+			if (curopt < maxopt)
 				curopt++;
-				draw_main_menu(menu, curopt);
-			}
 			break;
 		case KEY_RIGHT:
 		case KEY_ENTER:
 		case '\n':
 		case ' ':
 			c = run_category_menu(menu, curopt);
-			draw_main_menu(menu, curopt);
 			break;
 		case 'h':
 		case 'H':
 			show_help(menu);
-			draw_main_menu(menu, curopt);
 		default:
 			break;	
 		}
@@ -748,6 +786,7 @@
 		}
 		if (c == 'x')
 			break;	
+		draw_main_menu(menu, curopt);
 	}
 
 	endwin();
@@ -771,8 +810,7 @@
 	parse_existing_config();
 
 #ifdef MENUSELECT_DEBUG
-	/* Dump the list produced by parsing the input XML and show which ones
-	   are already enabled by reading in the existing config */
+	/* Dump the list produced by parsing the various input files */
 	dump_member_list();
 #endif
 
@@ -780,9 +818,9 @@
 	if (!(res = run_menu()))
 		res = generate_makeopts_file(); /* If all is good, save the new config */
 
-	/* free everything we allocated */	
+	/* free everything we allocated */
 	free_trees();
-	free_member_list();	
+	free_member_list();
 
 	exit(res);
 }

Modified: team/group/autoconf_and_menuselect/build_tools/menuselect.h
URL: http://svn.digium.com/view/asterisk/team/group/autoconf_and_menuselect/build_tools/menuselect.h?rev=8867&r1=8866&r2=8867&view=diff
==============================================================================
--- team/group/autoconf_and_menuselect/build_tools/menuselect.h (original)
+++ team/group/autoconf_and_menuselect/build_tools/menuselect.h Sun Jan 29 16:28:56 2006
@@ -35,6 +35,8 @@
 const char * const help_info[] = {
 	"scroll        => up/down arrows",
 	"(de)select    => Enter",
+	"select all    => F8",
+	"deselect all  => F7",
 	"back          => left arrow",
 	"quit          => q",
 	"save and quit => x",



More information about the asterisk-commits mailing list