[asterisk-commits] branch group/autoconf_and_menuselect r22160 -
/team/group/autoconf_and_menuse...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Apr 22 22:05:32 MST 2006
Author: russell
Date: Sun Apr 23 00:05:32 2006
New Revision: 22160
URL: http://svn.digium.com/view/asterisk?rev=22160&view=rev
Log:
move the curses frontend code into its own file so that it will be easier
to write a different frontend if anyone chooses to do so
Added:
team/group/autoconf_and_menuselect/build_tools/menuselect_curses.c (with props)
Modified:
team/group/autoconf_and_menuselect/build_tools/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/build_tools/Makefile
URL: http://svn.digium.com/view/asterisk/team/group/autoconf_and_menuselect/build_tools/Makefile?rev=22160&r1=22159&r2=22160&view=diff
==============================================================================
--- team/group/autoconf_and_menuselect/build_tools/Makefile (original)
+++ team/group/autoconf_and_menuselect/build_tools/Makefile Sun Apr 23 00:05:32 2006
@@ -1,11 +1,14 @@
-menuselect: menuselect.o
- $(CC) -g -o menuselect menuselect.o ../mxml/libmxml.a -lcurses
+menuselect: menuselect.o menuselect_curses.o
+ $(CC) -g -o $@ $< menuselect_curses.o ../mxml/libmxml.a -lcurses
menuselect.o: menuselect.c menuselect.h
- $(CC) -D_GNU_SOURCE -g -o menuselect.o -c -I../ -I../include/ menuselect.c
+ $(CC) -D_GNU_SOURCE -g -c -o $@ -I../ -I../include/ $<
+
+menuselect_curses.o: menuselect_curses.c menuselect.h
+ $(CC) -D_GNU_SOURCE -g -c -o $@ -I../ -I../include/ $<
clean:
- rm -f menuselect menuselect.o
+ rm -f menuselect *.o
dist-clean: clean
rm -f menuselect-deps
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=22160&r1=22159&r2=22160&view=diff
==============================================================================
--- team/group/autoconf_and_menuselect/build_tools/menuselect.c (original)
+++ team/group/autoconf_and_menuselect/build_tools/menuselect.c Sun Apr 23 00:05:32 2006
@@ -24,39 +24,22 @@
* \brief A console menu-driven system for Asterisk module selection
*/
+#include "autoconfig.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <signal.h>
-#include <curses.h>
#include "mxml/mxml.h"
#include "menuselect.h"
-#include "autoconfig.h"
+#include "asterisk.h"
#include "asterisk/linkedlists.h"
-#define MIN_X 80
-#define MIN_Y 20
-
-#define PAGE_OFFSET 10
-
#undef MENUSELECT_DEBUG
-/*!
- The member and category structures are used to maintain our own list of all
- of the categories and members in these categories that are specified in the
- build options file.
-
- The reason we need this is that we have to maintain information about which
- options are enabled and disabled. This information is read from any existing
- build configuration, and then changed as the user navigates the system. We
- will then use this information to output a new build configuration file.
-
- {
-*/
struct depend {
/*! the name of the dependency */
const char *name;
@@ -71,42 +54,8 @@
AST_LIST_ENTRY(conflict) list;
};
-struct member {
- /*! What will be sent to the makeopts file */
- const char *name;
- /*! This module is currently selected */
- int enabled;
- /*! This module has failed dependencies */
- int depsfailed;
- /*! This module has failed conflicts */
- int conflictsfailed;
- /*! dependencies of this module */
- AST_LIST_HEAD_NOLOCK(, depend) deps;
- /*! conflicts of this module */
- AST_LIST_HEAD_NOLOCK(, conflict) conflicts;
- /*! for making a list of modules */
- AST_LIST_ENTRY(member) list;
-};
-
-struct category {
- /*! the Makefile variable */
- const char *name;
- /*! the name displayed in the menu */
- const char *displayname;
- /*! Display what is selected, as opposed to not selected */
- int positive_output;
- /*! Force a clean of the source tree if anything in this category changes */
- int force_clean_on_change;
- /*! the list of possible values to be set in this variable */
- AST_LIST_HEAD_NOLOCK(, member) members;
- /*! for linking */
- AST_LIST_ENTRY(category) list;
-};
-
-/*! } */
-
/*! The list of categories */
-AST_LIST_HEAD_NOLOCK_STATIC(categories, category);
+struct categories categories = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
/*!
We have to maintain a pointer to the root of the trees generated from reading
@@ -125,10 +74,9 @@
/*! The list of trees from makeopts.xml files */
AST_LIST_HEAD_NOLOCK_STATIC(trees, tree);
-/*! Maximum number of characters horizontally */
-int max_x = 0;
-/*! Maximum number of characters vertically */
-int max_y = 0;
+const char * const makeopts_files[] = {
+ "makeopts.xml"
+};
char *output_makeopts = OUTPUT_MAKEOPTS_DEFAULT;
@@ -152,12 +100,6 @@
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 */
@@ -622,32 +564,6 @@
}
}
-/*! \brief Handle a window resize in xterm */
-void winch_handler(int sig)
-{
- getmaxyx(stdscr, max_y, max_x);
-
- if (max_x < MIN_X - 1 || max_y < MIN_Y - 1) {
- fprintf(stderr, "Terminal must be at least 80 x 25.\n");
- max_x = MIN_X - 1;
- max_y = MIN_Y - 1;
- }
-}
-
-/*! \brief Display help information */
-void show_help(WINDOW *win)
-{
- int i;
-
- wclear(win);
- for (i = 0; i < (sizeof(help_info) / sizeof(help_info[0])); i++) {
- wmove(win, i, max_x / 2 - 15);
- waddstr(win, help_info[i]);
- }
- wrefresh(win);
- 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 and no conflicts are found */
void set_all(struct category *cat, int val)
{
@@ -659,30 +575,6 @@
}
}
-void draw_main_menu(WINDOW *menu, int curopt)
-{
- struct category *cat;
- char buf[64];
- int i = 0;
-
- wclear(menu);
-
- AST_LIST_TRAVERSE(&categories, cat, list) {
- wmove(menu, i++, max_x / 2 - 10);
- if (!strlen_zero(cat->displayname))
- snprintf(buf, sizeof(buf), "%d.%s %s", i, i < 10 ? " " : "", cat->displayname);
- else
- snprintf(buf, sizeof(buf), "%d.%s %s", i, i < 10 ? " " : "", cat->name);
- waddstr(menu, buf);
- }
-
- wmove(menu, curopt, (max_x / 2) - 15);
- waddstr(menu, "--->");
- wmove(menu, 0, 0);
-
- wrefresh(menu);
-}
-
int count_categories(void)
{
struct category *cat;
@@ -703,194 +595,6 @@
count++;
return count;
-}
-
-void draw_category_menu(WINDOW *menu, struct category *cat, int start, int end, int curopt)
-{
- int i = 0;
- int j = 0;
- struct member *mem;
- char buf[64];
-
- wclear(menu);
-
- AST_LIST_TRAVERSE(&cat->members, mem, list) {
- if (i < start) {
- i++;
- continue;
- }
- wmove(menu, j++, max_x / 2 - 10);
- i++;
- if (mem->depsfailed)
- snprintf(buf, sizeof(buf), "XXX %d.%s %s", i, i < 10 ? " " : "", mem->name);
- else
- snprintf(buf, sizeof(buf), "[%s] %d.%s %s", mem->enabled ? "*" : " ", i, i < 10 ? " " : "", mem->name);
- waddstr(menu, buf);
- if (i == end)
- break;
- }
-
- wmove(menu, curopt - start, max_x / 2 - 9);
-
- wrefresh(menu);
-}
-
-int run_category_menu(WINDOW *menu, int cat_num)
-{
- struct category *cat;
- int i = 0;
- int start = 0;
- int end = max_y - TITLE_HEIGHT - 2;
- int c;
- int curopt = 0;
- int maxopt;
-
- AST_LIST_TRAVERSE(&categories, cat, list) {
- if (i++ == cat_num)
- break;
- }
- if (!cat)
- return -1;
-
- maxopt = count_members(cat) - 1;
-
- draw_category_menu(menu, cat, start, end, curopt);
-
- while ((c = getch())) {
- switch (c) {
- case KEY_UP:
- if (curopt > 0) {
- curopt--;
- if (curopt < start) {
- start--;
- end--;
- }
- }
- break;
- case KEY_DOWN:
- if (curopt < maxopt) {
- curopt++;
- if (curopt > end - 1) {
- start++;
- end++;
- }
- }
- 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;
- case KEY_RIGHT:
- case KEY_ENTER:
- case '\n':
- case ' ':
- toggle_enabled(cat, curopt);
- break;
- case 'h':
- case 'H':
- show_help(menu);
- 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);
-
- return c;
-}
-
-void draw_title_window(WINDOW *title)
-{
- wmove(title, 1, (max_x / 2) - (strlen(MENU_TITLE1) / 2));
- waddstr(title, MENU_TITLE1);
- wmove(title, 2, (max_x / 2) - (strlen(MENU_TITLE2) / 2));
- waddstr(title, MENU_TITLE2);
- wmove(title, 3, (max_x / 2) - (strlen(MENU_TITLE3) / 2));
- waddstr(title, MENU_TITLE3);
- wmove(title, 0, 0);
- wrefresh(title);
-}
-
-int run_menu(void)
-{
- WINDOW *title;
- WINDOW *menu;
- int maxopt;
- int curopt = 0;
- int c;
- int res = 0;
-
- initscr();
- getmaxyx(stdscr, max_y, max_x);
- 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 %d x %d.\n", MIN_X, MIN_Y);
- endwin();
- return -1;
- }
-
- 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);
- draw_main_menu(menu, curopt);
-
- while ((c = getch())) {
- switch (c) {
- case KEY_UP:
- if (curopt > 0)
- curopt--;
- break;
- case KEY_DOWN:
- if (curopt < maxopt)
- curopt++;
- break;
- case KEY_RIGHT:
- case KEY_ENTER:
- case '\n':
- case ' ':
- c = run_category_menu(menu, curopt);
- break;
- case 'h':
- case 'H':
- show_help(menu);
- default:
- break;
- }
- if (c == 'q') {
- res = -1;
- break;
- }
- if (c == 'x')
- break;
- draw_main_menu(menu, curopt);
- }
-
- endwin();
-
- return res;
}
int main(int argc, char *argv[])
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=22160&r1=22159&r2=22160&view=diff
==============================================================================
--- team/group/autoconf_and_menuselect/build_tools/menuselect.h (original)
+++ team/group/autoconf_and_menuselect/build_tools/menuselect.h Sun Apr 23 00:05:32 2006
@@ -23,27 +23,61 @@
*
*/
-#define MENU_TITLE1 "*************************************"
-#define MENU_TITLE2 "* Asterisk Module Selection *"
-#define MENU_TITLE3 "*************************************"
+#ifndef MENUSELECT_H
+#define MENUSELECT_H
-#define TITLE_HEIGHT 5
+#include "asterisk/linkedlists.h"
#define OUTPUT_MAKEOPTS_DEFAULT "menuselect.makeopts"
-#define MENUSELECT_DEPS "build_tools/menuselect-deps"
+#define MENUSELECT_DEPS "build_tools/menuselect-deps"
-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",
- "",
- "XXX means dependencies have not been met"
+struct depend;
+struct conflict;
+
+struct member {
+ /*! What will be sent to the makeopts file */
+ const char *name;
+ /*! This module is currently selected */
+ int enabled;
+ /*! This module has failed dependencies */
+ int depsfailed;
+ /*! This module has failed conflicts */
+ int conflictsfailed;
+ /*! dependencies of this module */
+ AST_LIST_HEAD_NOLOCK(, depend) deps;
+ /*! conflicts of this module */
+ AST_LIST_HEAD_NOLOCK(, conflict) conflicts;
+ /*! for making a list of modules */
+ AST_LIST_ENTRY(member) list;
};
-const char * const makeopts_files[] = {
- "makeopts.xml"
+struct category {
+ /*! the Makefile variable */
+ const char *name;
+ /*! the name displayed in the menu */
+ const char *displayname;
+ /*! Display what is selected, as opposed to not selected */
+ int positive_output;
+ /*! Force a clean of the source tree if anything in this category changes */
+ int force_clean_on_change;
+ /*! the list of possible values to be set in this variable */
+ AST_LIST_HEAD_NOLOCK(, member) members;
+ /*! for linking */
+ AST_LIST_ENTRY(category) list;
};
+
+extern AST_LIST_HEAD_NOLOCK(categories, category) categories;
+
+/*! This is implemented by the frontend */
+int run_menu(void);
+
+int count_categories(void);
+int count_members(struct category *cat);
+
+/*! \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'));
+}
+
+#endif /* MENUSELECT_H */
Added: team/group/autoconf_and_menuselect/build_tools/menuselect_curses.c
URL: http://svn.digium.com/view/asterisk/team/group/autoconf_and_menuselect/build_tools/menuselect_curses.c?rev=22160&view=auto
==============================================================================
--- team/group/autoconf_and_menuselect/build_tools/menuselect_curses.c (added)
+++ team/group/autoconf_and_menuselect/build_tools/menuselect_curses.c Sun Apr 23 00:05:32 2006
@@ -1,0 +1,278 @@
+#include "autoconfig.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <curses.h>
+
+#include "menuselect.h"
+
+#define MENU_TITLE1 "*************************************"
+#define MENU_TITLE2 "* Asterisk Module Selection *"
+#define MENU_TITLE3 "*************************************"
+
+#define TITLE_HEIGHT 5
+
+#define MIN_X 80
+#define MIN_Y 20
+
+#define PAGE_OFFSET 10
+
+
+/*! Maximum number of characters horizontally */
+int max_x = 0;
+/*! Maximum number of characters vertically */
+int max_y = 0;
+
+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",
+ "",
+ "XXX means dependencies have not been met"
+};
+
+/*! \brief Handle a window resize in xterm */
+void winch_handler(int sig)
+{
+ getmaxyx(stdscr, max_y, max_x);
+
+ if (max_x < MIN_X - 1 || max_y < MIN_Y - 1) {
+ fprintf(stderr, "Terminal must be at least 80 x 25.\n");
+ max_x = MIN_X - 1;
+ max_y = MIN_Y - 1;
+ }
+}
+
+/*! \brief Display help information */
+void show_help(WINDOW *win)
+{
+ int i;
+
+ wclear(win);
+ for (i = 0; i < (sizeof(help_info) / sizeof(help_info[0])); i++) {
+ wmove(win, i, max_x / 2 - 15);
+ waddstr(win, help_info[i]);
+ }
+ wrefresh(win);
+ getch(); /* display the help until the user hits a key */
+}
+
+void draw_main_menu(WINDOW *menu, int curopt)
+{
+ struct category *cat;
+ char buf[64];
+ int i = 0;
+
+ wclear(menu);
+
+ AST_LIST_TRAVERSE(&categories, cat, list) {
+ wmove(menu, i++, max_x / 2 - 10);
+ if (!strlen_zero(cat->displayname))
+ snprintf(buf, sizeof(buf), "%d.%s %s", i, i < 10 ? " " : "", cat->displayname);
+ else
+ snprintf(buf, sizeof(buf), "%d.%s %s", i, i < 10 ? " " : "", cat->name);
+ waddstr(menu, buf);
+ }
+
+ wmove(menu, curopt, (max_x / 2) - 15);
+ waddstr(menu, "--->");
+ wmove(menu, 0, 0);
+
+ wrefresh(menu);
+}
+
+void draw_category_menu(WINDOW *menu, struct category *cat, int start, int end, int curopt)
+{
+ int i = 0;
+ int j = 0;
+ struct member *mem;
+ char buf[64];
+
+ wclear(menu);
+
+ AST_LIST_TRAVERSE(&cat->members, mem, list) {
+ if (i < start) {
+ i++;
+ continue;
+ }
+ wmove(menu, j++, max_x / 2 - 10);
+ i++;
+ if (mem->depsfailed)
+ snprintf(buf, sizeof(buf), "XXX %d.%s %s", i, i < 10 ? " " : "", mem->name);
+ else
+ snprintf(buf, sizeof(buf), "[%s] %d.%s %s", mem->enabled ? "*" : " ", i, i < 10 ? " " : "", mem->name);
+ waddstr(menu, buf);
+ if (i == end)
+ break;
+ }
+
+ wmove(menu, curopt - start, max_x / 2 - 9);
+
+ wrefresh(menu);
+}
+
+int run_category_menu(WINDOW *menu, int cat_num)
+{
+ struct category *cat;
+ int i = 0;
+ int start = 0;
+ int end = max_y - TITLE_HEIGHT - 2;
+ int c;
+ int curopt = 0;
+ int maxopt;
+
+ AST_LIST_TRAVERSE(&categories, cat, list) {
+ if (i++ == cat_num)
+ break;
+ }
+ if (!cat)
+ return -1;
+
+ maxopt = count_members(cat) - 1;
+
+ draw_category_menu(menu, cat, start, end, curopt);
+
+ while ((c = getch())) {
+ switch (c) {
+ case KEY_UP:
+ if (curopt > 0) {
+ curopt--;
+ if (curopt < start) {
+ start--;
+ end--;
+ }
+ }
+ break;
+ case KEY_DOWN:
+ if (curopt < maxopt) {
+ curopt++;
+ if (curopt > end - 1) {
+ start++;
+ end++;
+ }
+ }
+ 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;
+ case KEY_RIGHT:
+ case KEY_ENTER:
+ case '\n':
+ case ' ':
+ toggle_enabled(cat, curopt);
+ break;
+ case 'h':
+ case 'H':
+ show_help(menu);
+ 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);
+
+ return c;
+}
+
+void draw_title_window(WINDOW *title)
+{
+ wmove(title, 1, (max_x / 2) - (strlen(MENU_TITLE1) / 2));
+ waddstr(title, MENU_TITLE1);
+ wmove(title, 2, (max_x / 2) - (strlen(MENU_TITLE2) / 2));
+ waddstr(title, MENU_TITLE2);
+ wmove(title, 3, (max_x / 2) - (strlen(MENU_TITLE3) / 2));
+ waddstr(title, MENU_TITLE3);
+ wmove(title, 0, 0);
+ wrefresh(title);
+}
+
+
+
+int run_menu(void)
+{
+ WINDOW *title;
+ WINDOW *menu;
+ int maxopt;
+ int curopt = 0;
+ int c;
+ int res = 0;
+
+ initscr();
+ getmaxyx(stdscr, max_y, max_x);
+ 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 %d x %d.\n", MIN_X, MIN_Y);
+ endwin();
+ return -1;
+ }
+
+ 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);
+ draw_main_menu(menu, curopt);
+
+ while ((c = getch())) {
+ switch (c) {
+ case KEY_UP:
+ if (curopt > 0)
+ curopt--;
+ break;
+ case KEY_DOWN:
+ if (curopt < maxopt)
+ curopt++;
+ break;
+ case KEY_RIGHT:
+ case KEY_ENTER:
+ case '\n':
+ case ' ':
+ c = run_category_menu(menu, curopt);
+ break;
+ case 'h':
+ case 'H':
+ show_help(menu);
+ default:
+ break;
+ }
+ if (c == 'q') {
+ res = -1;
+ break;
+ }
+ if (c == 'x')
+ break;
+ draw_main_menu(menu, curopt);
+ }
+
+ endwin();
+
+ return res;
+}
Propchange: team/group/autoconf_and_menuselect/build_tools/menuselect_curses.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/group/autoconf_and_menuselect/build_tools/menuselect_curses.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/group/autoconf_and_menuselect/build_tools/menuselect_curses.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list