[svn-commits] kpfleming: trunk r949 - /trunk/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Oct 14 18:26:58 CDT 2011
Author: kpfleming
Date: Fri Oct 14 18:26:54 2011
New Revision: 949
URL: http://svnview.digium.com/svn/menuselect?view=rev&rev=949
Log:
Code cleanup:
* Properly use 'enum support_level_values' type in code that uses these values,
rather than 'int'.
* Ensure that all member items in categories have a non-empty support_level,
"unspecified" unless it is overridden by the input files.
* Don't show a support level of 'core' in the user interface code if a member
does not have a support level (see above... they will always have one now).
Modified:
trunk/menuselect.c
trunk/menuselect_curses.c
trunk/menuselect_newt.c
Modified: trunk/menuselect.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect.c?view=diff&rev=949&r1=948&r2=949
==============================================================================
--- trunk/menuselect.c (original)
+++ trunk/menuselect.c Fri Oct 14 18:26:54 2011
@@ -238,21 +238,21 @@
}
/*! \assigns values to support level strings */
-static int support_level_assign_value(const char *support_level)
+static enum support_level_values string_to_support_level(const char *support_level)
{
if (!support_level) {
return SUPPORT_UNSPECIFIED;
}
- if (!strncasecmp(support_level, "core", 4)) {
+ if (!strcasecmp(support_level, "core")) {
return SUPPORT_CORE;
}
- if (!strncasecmp(support_level, "extended", 8)) {
+ if (!strcasecmp(support_level, "extended")) {
return SUPPORT_EXTENDED;
}
- if (!strncasecmp(support_level, "deprecated", 10)) {
+ if (!strcasecmp(support_level, "deprecated")) {
return SUPPORT_DEPRECATED;
}
@@ -260,7 +260,7 @@
}
/*! \gets const separator strings from support level values */
-static char *separator_name_from_value(int support_level)
+static const char *support_level_to_string(enum support_level_values support_level)
{
switch (support_level) {
case SUPPORT_CORE:
@@ -269,50 +269,47 @@
return "extended";
case SUPPORT_DEPRECATED:
return "deprecated";
- }
-
- return "unspecified";
+ default:
+ return "unspecified";
+ }
}
/*! \sets default values for a given separator */
-static int initialize_separator(struct member *separators[], int iter)
-{
- separators[iter] = calloc(1, sizeof(*(separators[iter])));
- separators[iter]->name = separator_name_from_value(iter);
- separators[iter]->displayname = "";
- separators[iter]->is_separator = 1;
+static int initialize_separator(struct member *separators[], enum support_level_values level)
+{
+ separators[level] = calloc(1, sizeof(*(separators[level])));
+ separators[level]->name = support_level_to_string(level);
+ separators[level]->displayname = "";
+ separators[level]->is_separator = 1;
return 0;
}
/*! \Iterates through an existing category's members. If separators are found, they are
added to the provided separator array. Any separators left unfound will then be
initialized with initialize_separator. */
-static int find_or_initialize_separators(struct member *separators[], struct category *cat, int used[])
-{
- int iter = 0;
+static void find_or_initialize_separators(struct member *separators[], struct category *cat, int used[])
+{
+ enum support_level_values level;
struct member *tmp;
AST_LIST_TRAVERSE(&cat->members, tmp, list) {
if (tmp->is_separator) {
- int found = support_level_assign_value(tmp->name);
- separators[found] = tmp;
- used[found] = 1;
- }
- }
-
- for (iter = 0; iter < SUPPORT_COUNT; iter++) {
- if (!used[iter]) {
- initialize_separator(separators, iter);
- }
- }
-
- return 0;
-
+ level = string_to_support_level(tmp->name);
+ separators[level] = tmp;
+ used[level] = 1;
+ }
+ }
+
+ for (level = 0; level < SUPPORT_COUNT; level++) {
+ if (!used[level]) {
+ initialize_separator(separators, level);
+ }
+ }
}
/*! \adds a member to a category and attaches it to the last element of a particular support level used */
static int add_member_list_order(struct member *mem, struct category *cat, struct member *tails[], int used[], struct member *separators[])
{
- int support_level = support_level_assign_value(mem->support_level);
+ enum support_level_values support_level = string_to_support_level(mem->support_level);
int tail_index;
/* Works backwards from support_level to find properly ordered linked list member to insert from */
@@ -447,9 +444,7 @@
mem->displayname = mxmlElementGetAttr(cur2, "displayname");
mem->touch_on_change = mxmlElementGetAttr(cur2, "touch_on_change");
mem->remove_on_change = mxmlElementGetAttr(cur2, "remove_on_change");
- mem->is_separator = 0;
-
-
+ mem->support_level = "unspecified";
if ((tmp = mxmlElementGetAttr(cur2, "explicitly_enabled_only"))) {
mem->explicitly_enabled_only = !strcasecmp(tmp, "yes");
@@ -462,12 +457,13 @@
if (!cat->positive_output && !(mem->defaultenabled && strcasecmp(mem->defaultenabled, "no"))) {
mem->was_enabled = mem->enabled = 1;
- print_debug("Enabling %s because the category does not have positive output\n", mem->name);
+ print_debug("Enabled %s because the category does not have positive output\n", mem->name);
}
cur3 = mxmlFindElement(cur2, cur2, "support_level", NULL, NULL, MXML_DESCEND);
if (cur3 && cur3->child) {
mem->support_level = cur3->child->value.opaque;
+ print_debug("Set support_level for %s to %s\n", mem->name, mem->support_level);
}
cur3 = mxmlFindElement(cur2, cur2, "replacement", NULL, NULL, MXML_DESCEND);
@@ -541,8 +537,6 @@
}
AST_LIST_INSERT_TAIL(&mem->uses, use, list);
-
-
} else {
free(use);
}
Modified: trunk/menuselect_curses.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect_curses.c?view=diff&rev=949&r1=948&r2=949
==============================================================================
--- trunk/menuselect_curses.c (original)
+++ trunk/menuselect_curses.c Fri Oct 14 18:26:54 2011
@@ -238,8 +238,7 @@
if (!mem->is_separator) { /* Separators lack support levels */
{ /* support level */
wmove(menu, end - start + 6, max_x / 2 - 16);
- snprintf(buf, sizeof(buf), "Support Level: %s",
- (mem->support_level && *mem->support_level) ? mem->support_level : "core");
+ snprintf(buf, sizeof(buf), "Support Level: %s", mem->support_level);
if (mem->replacement && *mem->replacement) {
char buf2[64];
snprintf(buf2, sizeof(buf2), ", Replaced by: %s", mem->replacement);
Modified: trunk/menuselect_newt.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect_newt.c?view=diff&rev=949&r1=948&r2=949
==============================================================================
--- trunk/menuselect_newt.c (original)
+++ trunk/menuselect_newt.c Fri Oct 14 18:26:54 2011
@@ -173,8 +173,7 @@
}
{ /* Support Level */
- snprintf(buffer, sizeof(buffer), "%s",
- (mem->support_level && *mem->support_level) ? mem->support_level : "core");
+ snprintf(buffer, sizeof(buffer), "%s", mem->support_level);
if (mem->replacement && *mem->replacement) {
char buf2[64];
snprintf(buf2, sizeof(buf2), ", Replaced by: %s", mem->replacement);
More information about the svn-commits
mailing list