[svn-commits] branch russell/autoconf_and_menuselect - r8081
/team/russell/autoconf_and_men...
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Sun Jan 15 17:28:15 MST 2006
Author: russell
Date: Sun Jan 15 18:28:13 2006
New Revision: 8081
URL: http://svn.digium.com/view/asterisk?rev=8081&view=rev
Log:
finish list conversion
Modified:
team/russell/autoconf_and_menuselect/build_tools/menuselect.c
Modified: team/russell/autoconf_and_menuselect/build_tools/menuselect.c
URL: http://svn.digium.com/view/asterisk/team/russell/autoconf_and_menuselect/build_tools/menuselect.c?rev=8081&r1=8080&r2=8081&view=diff
==============================================================================
--- team/russell/autoconf_and_menuselect/build_tools/menuselect.c (original)
+++ team/russell/autoconf_and_menuselect/build_tools/menuselect.c Sun Jan 15 18:28:13 2006
@@ -69,14 +69,14 @@
const char *displayname;
const char *desc;
int enabled;
- struct member *next;
+ AST_LIST_ENTRY(member) list;
};
-static struct category {
+struct category {
const char *name;
const char *displayname;
const char *desc;
- struct member *members;
+ AST_LIST_HEAD_NOLOCK(, member) members;
AST_LIST_ENTRY(category) list;
};
@@ -89,13 +89,15 @@
convenient mapping to the information contained in these lists with one
additional piece of information - whether the build option is enabled or not.
*/
-static struct tree {
+struct tree {
mxml_node_t *root;
- struct tree *next;
-} *trees = NULL;
+ AST_LIST_ENTRY(tree) list;
+};
+
+AST_LIST_HEAD_NOLOCK_STATIC(trees, tree);
/*! The output build configuration file - TODO Make this optionally specified as a command line argument */
-static const char *output_makeopts = OUTPUT_MAKEOPTS_DEFAULT;
+const char *output_makeopts = OUTPUT_MAKEOPTS_DEFAULT;
/*! Maximum number of characters horizontally */
int max_x = 0;
@@ -144,32 +146,25 @@
struct member *add_member(const char *name, const char *displayname, const char *desc, struct category *cat)
{
struct member *mem;
- struct member *mem_prev = NULL;
if (!cat)
return NULL;
- for (mem = cat->members; mem; mem = mem->next) {
- if (!strcmp(name, mem->name))
- break;
- mem_prev = mem;
- }
- if (mem) {
- fprintf(stderr, "Member '%s' already exists in category '%s', ignoring.\n", name, cat->name);
+ AST_LIST_TRAVERSE(&cat->members, mem, list) {
+ if (!strcmp(name, mem->name)) {
+ fprintf(stderr, "Member '%s' already exists in category '%s', ignoring.\n", name, cat->name);
+ return NULL;
+ }
+ }
+
+ if (!(mem = my_calloc(1, sizeof(*mem))))
return NULL;
- }
-
- mem = my_calloc(1, sizeof(struct member));
- if (!mem)
- return NULL;
-
- if (!cat->members)
- cat->members = mem;
- if (mem_prev)
- mem_prev->next = mem;
+
mem->name = name;
mem->displayname = displayname;
mem->desc = desc;
+
+ AST_LIST_INSERT_TAIL(&cat->members, mem, list);
return mem;
}
@@ -198,8 +193,7 @@
close(f);
return -1;
}
- tree->next = trees;
- trees = tree;
+ AST_LIST_INSERT_HEAD(&trees, tree, list);
if (!(tree->root = mxmlLoadFile(NULL, f, MXML_OPAQUE_CALLBACK))) {
close(f);
@@ -299,15 +293,13 @@
AST_LIST_TRAVERSE(&categories, cat, list) {
if (strcmp(category, cat->name))
continue;
-
- for (mem = cat->members; mem; mem = mem->next) {
- if (!strcmp(member, mem->name))
+ AST_LIST_TRAVERSE(&cat->members, mem, list) {
+ if (!strcmp(member, mem->name)) {
+ mem->enabled = 1;
break;
- }
-
- if (mem)
- mem->enabled = 1;
- else
+ }
+ }
+ if (!mem)
fprintf(stderr, "member '%s' in category '%s' not found, ignoring.\n", member, category);
break;
}
@@ -321,14 +313,13 @@
struct member *mem;
int i = 0;
- for (mem = cat->members; mem; mem = mem->next) {
+ AST_LIST_TRAVERSE(&cat->members, mem, list) {
if (i++ == index)
break;
}
- if (!mem)
- return;
-
- mem->enabled = !mem->enabled;
+
+ if (mem)
+ mem->enabled = !mem->enabled;
}
void parse_existing_config(void)
@@ -388,24 +379,17 @@
return -1;
}
+ /* Traverse all categories (Makefile variables) */
AST_LIST_TRAVERSE(&categories, cat, list) {
- if (!cat->members)
- continue;
-
- print_cat = 1;
-
- for (mem = cat->members; mem; mem = mem->next) {
- if (mem->enabled) {
- if (print_cat) {
- fprintf(f, "%s=", cat->name);
- print_cat = 0;
- }
+ if (AST_LIST_EMPTY(&cat->members))
+ continue;
+ 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);
- }
- }
-
- if (!print_cat)
- fprintf(f, "\n");
+ }
+ fprintf(f, "\n");
}
close(f);
@@ -423,7 +407,7 @@
fprintf(stderr, "Category: '%s'\n", cat->name);
if (!strlen_zero(cat->desc))
fprintf(stderr, " --> Description: '%s'\n", cat->desc);
- for (mem = cat->members; mem; mem = mem->next) {
+ AST_LIST_TRAVERSE(&cat->members, mem, list) {
fprintf(stderr, " ==>> Member: '%s' (%s)\n", mem->name, mem->enabled ? "Enabled" : "Disabled");
if (!strlen_zero(mem->desc))
fprintf(stderr, " --> Description: '%s'\n", mem->desc);
@@ -436,13 +420,12 @@
{
struct category *cat;
struct member *mem;
- struct member *mem_next;
AST_LIST_TRAVERSE_SAFE_BEGIN(&categories, cat, list) {
- for (mem = cat->members; mem; mem = mem_next) {
- mem_next = mem->next;
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&cat->members, mem, list) {
free(mem);
}
+ AST_LIST_TRAVERSE_SAFE_END
free(cat);
}
AST_LIST_TRAVERSE_SAFE_END
@@ -450,13 +433,11 @@
void free_trees(void)
{
- struct tree *cur;
- struct tree *next;
-
- for (cur = trees; cur; cur = next) {
- next = cur->next;
- mxmlDelete(cur->root);
- free(cur);
+ struct tree *tree;
+
+ AST_LIST_TRAVERSE(&trees, tree, list) {
+ mxmlDelete(tree->root);
+ free(tree);
}
}
@@ -511,7 +492,7 @@
struct member *mem;
int count = 0;
- for (mem = cat->members; mem; mem = mem->next)
+ AST_LIST_TRAVERSE(&cat->members, mem, list)
count++;
return count;
@@ -525,7 +506,7 @@
char buf[64];
wclear(menu);
- for (mem = cat->members; mem; mem = mem->next) {
+ AST_LIST_TRAVERSE(&cat->members, mem, list) {
if (i < start) {
i++;
continue;
More information about the svn-commits
mailing list