[svn-commits] russell: trunk r725 - in /trunk: README menuselect.c
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Mar 12 09:38:15 CST 2010
Author: russell
Date: Fri Mar 12 09:38:10 2010
New Revision: 725
URL: http://svnview.digium.com/svn/menuselect?view=rev&rev=725
Log:
Add ability to enable/disable options from the command line.
For example, in a script I can now do:
$ make menuselect.makeopts
$ menuselect/menuselect --enable TEST_FRAMEWORK menuselect.makeopts
$ menuselect/menuselect --enable-category MENUSELECT_TEST menuselect.makeopts
Review: https://reviewboard.asterisk.org/r/550/
Modified:
trunk/README
trunk/menuselect.c
Modified: trunk/README
URL: http://svnview.digium.com/svn/menuselect/trunk/README?view=diff&rev=725&r1=724&r2=725
==============================================================================
--- trunk/README (original)
+++ trunk/README Fri Mar 12 09:38:10 2010
@@ -73,6 +73,24 @@
The format of the input files must be of the same format menuselect uses to
create the OUPUT_MAKEOPTS_DEFAULT.
+
+
+ENABLING AND DISABLING OPTIONS FROM THE COMMAND LINE
+
+If you would like menuselect to update choices via the command line, it can be
+done with the following syntax:
+
+Enable an option:
+ $ menuselect/menuselect --enable TEST_FRAMEWORK menuselect.makeopts
+
+Enable all options in a category:
+ $ menuselect/menuselect --enable-category MENUSELECT_TEST menuselect.makeopts
+
+Disable an option:
+ $ menuselect/menuselect --disable TEST_FRAMEWORK menuselect.makeopts
+
+Disable all options in a category:
+ $ menuselect/menuselect --disable-category MENUSELECT_TEST menuselect.makeopts
SETTING UP AVAILABLE OPTIONS
Modified: trunk/menuselect.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect.c?view=diff&rev=725&r1=724&r2=725
==============================================================================
--- trunk/menuselect.c (original)
+++ trunk/menuselect.c Fri Mar 12 09:38:10 2010
@@ -1,7 +1,7 @@
/*
* Asterisk -- An open source telephony toolkit.
*
- * Copyright (C) 2005 - 2006, Russell Bryant
+ * Copyright (C) 2005 - 2010, Digium, Inc.
*
* Russell Bryant <russell at digium.com>
*
@@ -29,6 +29,7 @@
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
+#include <getopt.h>
#include "mxml/mxml.h"
#include "linkedlists.h"
@@ -859,6 +860,21 @@
toggle_enabled(mem);
}
+static void set_member_enabled(struct member *mem)
+{
+ if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE))
+ return;
+
+ if (mem->enabled)
+ return;
+
+ enable_member(mem);
+ mem->was_defaulted = 0;
+ changes_made++;
+
+ while (calc_dep_failures(1, 0) || calc_conflict_failures(1, 0));
+}
+
void set_enabled(struct category *cat, int index)
{
struct member *mem;
@@ -872,13 +888,15 @@
if (!mem)
return;
- if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE))
+ set_member_enabled(mem);
+}
+
+static void clear_member_enabled(struct member *mem)
+{
+ if (!mem->enabled)
return;
- if (mem->enabled)
- return;
-
- enable_member(mem);
+ mem->enabled = 0;
mem->was_defaulted = 0;
changes_made++;
@@ -898,14 +916,7 @@
if (!mem)
return;
- if (!mem->enabled)
- return;
-
- mem->enabled = 0;
- mem->was_defaulted = 0;
- changes_made++;
-
- while (calc_dep_failures(1, 0) || calc_conflict_failures(1, 0));
+ clear_member_enabled(mem);
}
/*! \brief Process a previously failed dependency
@@ -1485,10 +1496,60 @@
}
+struct member *find_member(const char *name)
+{
+ struct category *cat;
+ struct member *mem;
+
+ AST_LIST_TRAVERSE(&categories, cat, list) {
+ AST_LIST_TRAVERSE(&cat->members, mem, list) {
+ if (!strcasecmp(name, mem->name)) {
+ return mem;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+struct category *find_category(const char *name)
+{
+ struct category *cat;
+
+ AST_LIST_TRAVERSE(&categories, cat, list) {
+ if (!strcasecmp(name, cat->name)) {
+ return cat;
+ }
+ }
+
+ return NULL;
+}
+
int main(int argc, char *argv[])
{
int res = 0;
unsigned int x;
+ static struct option long_options[] = {
+ /*
+ * The --check-deps option is used to ask this application to check to
+ * see if that an existing menuselect.makeopts file contains all of the
+ * modules that have dependencies that have not been met. If this
+ * is not the case, an informative message will be printed to the
+ * user and the build will fail.
+ */
+ { "check-deps", no_argument, &check_deps, 1 },
+ { "enable", required_argument, 0, 'e' },
+ { "enable-category", required_argument, 0, 'E' },
+ { "disable", required_argument, 0, 'd' },
+ { "disable-category", required_argument, 0, 'D' },
+ { 0, 0, 0, 0 },
+ };
+ int do_menu = 1;
+ int c, option_index = 0;
+ const char *enable = NULL;
+ const char *enable_cat = NULL;
+ const char *disable = NULL;
+ const char *disable_cat = NULL;
if (open_debug()) {
exit(1);
@@ -1504,15 +1565,35 @@
while (calc_dep_failures(0, 1) || calc_conflict_failures(0, 1));
- /* The --check-deps option is used to ask this application to check to
- * see if that an existing menuselect.makeopts file contains all of the
- * modules that have dependencies that have not been met. If this
- * is not the case, an informative message will be printed to the
- * user and the build will fail. */
- for (x = 1; x < argc; x++) {
- if (!strcmp(argv[x], "--check-deps"))
- check_deps = 1;
- else {
+ while ((c = getopt_long(argc, argv, "", long_options, &option_index)) != -1) {
+ switch (c) {
+ case 'e':
+ enable = optarg;
+ do_menu = 0;
+ break;
+ case 'E':
+ enable_cat = optarg;
+ do_menu = 0;
+ break;
+ case 'd':
+ disable = optarg;
+ do_menu = 0;
+ break;
+ case 'D':
+ disable_cat = optarg;
+ do_menu = 0;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (check_deps) {
+ do_menu = 0;
+ }
+
+ if (optind < argc) {
+ for (x = optind; x < argc; x++) {
res = parse_existing_config(argv[x]);
if (!res && !strcasecmp(argv[x], OUTPUT_MAKEOPTS_DEFAULT))
existing_config = 1;
@@ -1531,10 +1612,50 @@
res = sanity_check();
while (calc_dep_failures(0, 0) || calc_conflict_failures(0, 0));
-
- /* Run the menu to let the user enable/disable options */
- if (!check_deps && !res)
+
+ if (do_menu && !res) {
res = run_menu();
+ }
+
+ if (!strlen_zero(enable)) {
+ struct member *mem;
+
+ if ((mem = find_member(enable))) {
+ set_member_enabled(mem);
+ } else {
+ fprintf(stderr, "'%s' not found\n", enable);
+ }
+ }
+
+ if (!strlen_zero(enable_cat)) {
+ struct category *cat;
+
+ if ((cat = find_category(enable_cat))) {
+ set_all(cat, 1);
+ } else {
+ fprintf(stderr, "'%s' not found\n", enable_cat);
+ }
+ }
+
+ if (!strlen_zero(disable)) {
+ struct member *mem;
+
+ if ((mem = find_member(disable))) {
+ clear_member_enabled(mem);
+ } else {
+ fprintf(stderr, "'%s' not found\n", disable);
+ }
+ }
+
+ if (!strlen_zero(disable_cat)) {
+ struct category *cat;
+
+ if ((cat = find_category(disable_cat))) {
+ set_all(cat, 0);
+ } else {
+ fprintf(stderr, "'%s' not found\n", disable_cat);
+ }
+ }
if (!res)
res = generate_makeopts_file();
@@ -1542,7 +1663,7 @@
/* Always generate the dependencies file */
if (!res)
generate_makedeps_file();
-
+
/* free everything we allocated */
free_deps_file();
free_trees();
More information about the svn-commits
mailing list