[svn-commits] jrose: trunk r944 - /trunk/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Oct 14 11:28:32 CDT 2011


Author: jrose
Date: Fri Oct 14 11:28:26 2011
New Revision: 944

URL: http://svnview.digium.com/svn/menuselect?view=rev&rev=944
Log:
Adds support level categorical separation to menuselect

As long as the support level tag ends up in the menuselect-tree, a given module should
now be separated on the menuselect category trees by support level.

(issue ASTERISK-18268)
Review: https://reviewboard.asterisk.org/r/1524/


Modified:
    trunk/menuselect.c
    trunk/menuselect.h
    trunk/menuselect_curses.c
    trunk/menuselect_gtk.c
    trunk/menuselect_newt.c

Modified: trunk/menuselect.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect.c?view=diff&rev=944&r1=943&r2=944
==============================================================================
--- trunk/menuselect.c (original)
+++ trunk/menuselect.c Fri Oct 14 11:28:26 2011
@@ -172,6 +172,7 @@
 	return cat;
 }
 
+#if 0
 /*! \brief Add a member to the member list of a category, ensuring that there are no duplicates */
 static int add_member(struct member *mem, struct category *cat)
 {
@@ -184,6 +185,38 @@
 		}
 	}
 	AST_LIST_INSERT_TAIL(&cat->members, mem, list);
+
+	return 0;
+}
+#endif
+
+static int add_member_after(struct member *mem, struct category *cat, struct member *place)
+{
+	struct member *tmp;
+
+	AST_LIST_TRAVERSE(&cat->members, tmp, list) {
+		if (!strcmp(tmp->name, mem->name)) {
+			fprintf(stderr, "Member '%s' already exists in category '%s', ignoring.\n", mem->name, cat->name);
+			return -1;
+		}
+	}
+	AST_LIST_INSERT_AFTER(&cat->members, place, mem, list);
+
+	return 0;
+
+}
+
+static int add_member_head(struct member *mem, struct category *cat)
+{
+	struct member *tmp;
+
+	AST_LIST_TRAVERSE(&cat->members, tmp, list) {
+		if (!strcmp(tmp->name, mem->name)) {
+			fprintf(stderr, "Member '%s' already exists in category '%s', ignoring.\n", mem->name, cat->name);
+			return -1;
+		}
+	}
+	AST_LIST_INSERT_HEAD(&cat->members, mem, list);
 
 	return 0;
 }
@@ -202,6 +235,130 @@
 	while ((use = AST_LIST_REMOVE_HEAD(&mem->uses, list)))
 		free(use);
 	free(mem);
+}
+
+/*! \assigns values to support level strings */
+static int support_level_assign_value(const char *support_level)
+{
+	if (!support_level) {
+		return SUPPORT_OTHER;
+	}
+
+	if (!strncasecmp(support_level, "core", 4)) {
+		return SUPPORT_CORE;
+	}
+
+	if (!strncasecmp(support_level, "extended", 8)) {
+		return SUPPORT_EXTENDED;
+	}
+
+	if (!strncasecmp(support_level, "deprecated", 10)) {
+		return SUPPORT_DEPRECATED;
+	}
+
+	return SUPPORT_OTHER;
+}
+
+/*! \gets const separator strings from support level values */
+static char* separator_name_from_value(int support_level)
+{
+	switch (support_level) {
+	case SUPPORT_CORE:
+		return "core";
+	case SUPPORT_EXTENDED:
+		return "extended";
+	case SUPPORT_DEPRECATED:
+		return "deprecated";
+	}
+
+	return "other";
+}
+
+/*! \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;
+	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;
+	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;
+
+}
+
+/*! \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);
+	int tail_index;
+
+	/* Works backwards from support_level to find properly ordered linked list member to insert from */
+	for (tail_index = support_level; ; tail_index--) {
+		if (tail_index == -1) {
+			break;
+		}
+		if (used[tail_index]) {
+			break;
+		}
+	}
+
+
+	if (tail_index == -1) { /* None of the nodes that should come before the list were in use, so use head. */
+		if (add_member_head(mem, cat)) { /* Failure to insert the node... */
+			return -1;
+		}
+
+		/* If we successfully added the member, we need to update its support level pointer info */
+		tails[support_level] = mem;
+		used[support_level] = 1;
+		if (add_member_head(separators[support_level], cat)) {
+			printf("Separator insertion failed.  This should be impossible, report an issue if this occurs.\n");
+			return -1;
+		}
+		return 0;
+
+	} else { /* We found an appropriate node to use to insert before we reached the head. */
+		if (add_member_after(mem, cat, tails[tail_index])) {
+			return -1;
+		}
+
+		tails[support_level] = mem;
+		used[support_level] = 1;
+		if (support_level != tail_index) {
+			if (add_member_after(separators[support_level], cat, tails[tail_index])) {
+				printf("Separator insertion failed.  This should be impossible, report an issue if this occurs.\n");
+				return -1;
+			}
+		}
+
+		return 0;
+
+	}
+
+	return -2; /* failed to place... for whatever reason.  This should be impossible to reach. */
 }
 
 /*! \brief Parse an input makeopts file */
@@ -247,6 +404,13 @@
 		struct category *cat;
 		struct category *newcat;
 
+		/* Member seperator definitions */
+		struct member *separators[SUPPORT_COUNT];
+
+		/* link list tails... used to put new elements in in order of support level */
+		struct member *support_tails[SUPPORT_COUNT];
+		int support_tails_placed[SUPPORT_COUNT] = { 0 };
+
 		if (!(cat = calloc(1, sizeof(*cat))))
 			return -1;
 
@@ -259,6 +423,8 @@
 			free(cat);
 			cat = newcat;
 		}
+
+		find_or_initialize_separators(separators, cat, support_tails_placed);
 
 		if ((tmp = mxmlElementGetAttr(cur, "displayname")))
 			cat->displayname = tmp;
@@ -277,11 +443,14 @@
 		{
 			if (!(mem = calloc(1, sizeof(*mem))))
 				return -1;
-			
+
 			mem->name = mxmlElementGetAttr(cur2, "name");
 			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;
+
+
 
 			if ((tmp = mxmlElementGetAttr(cur2, "explicitly_enabled_only"))) {
 				mem->explicitly_enabled_only = !strcasecmp(tmp, "yes");
@@ -319,7 +488,7 @@
 					if (!strlen_zero(tmp)) {
 						dep->name = tmp;
 					}
-				}				
+				}
 				if (!strlen_zero(cur3->child->value.opaque)) {
 					dep->displayname = cur3->child->value.opaque;
 					if (!dep->name) {
@@ -347,7 +516,7 @@
 					cnf->displayname = cur3->child->value.opaque;
 					if (!cnf->name) {
 						cnf->name = cnf->displayname;
-					}					
+					}
 					AST_LIST_INSERT_TAIL(&mem->conflicts, cnf, list);
 				} else
 					free(cnf);
@@ -371,14 +540,18 @@
 					if (!use->name) {
 						use->name = use->displayname;
 					}
+
 					AST_LIST_INSERT_TAIL(&mem->uses, use, list);
+
+
 				} else {
 					free(use);
 				}
 			}
 
-			if (add_member(mem, cat))
+			if (add_member_list_order(mem, cat, support_tails, support_tails_placed, separators)) {
 				free_member(mem);
+			}
 		}
 	}
 
@@ -873,7 +1046,7 @@
 
 void toggle_enabled(struct member *mem)
 {
-	if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE))
+	if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE) || (mem->is_separator))
 		return;
 
 	if (!mem->enabled)

Modified: trunk/menuselect.h
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect.h?view=diff&rev=944&r1=943&r2=944
==============================================================================
--- trunk/menuselect.h (original)
+++ trunk/menuselect.h Fri Oct 14 11:28:26 2011
@@ -83,6 +83,9 @@
 	/*! This module should never be enabled automatically, but only
 	 * when explicitly set. */
 	unsigned int explicitly_enabled_only:1;
+	/*! This isn't actually a module!  It's a separator, and it should
+	 * be passed over for many of the usual purposes associated with members. */
+	unsigned int is_separator:1;
 	/*! dependencies of this module */
 	AST_LIST_HEAD_NOLOCK(, reference) deps;
 	/*! conflicts of this module */
@@ -93,7 +96,16 @@
 	AST_LIST_ENTRY(member) list;
 };
 
+enum support_level_values {
+	SUPPORT_CORE = 0,
+	SUPPORT_EXTENDED = 1,
+	SUPPORT_DEPRECATED = 2,
+	SUPPORT_OTHER = 3,
+	SUPPORT_COUNT = 4, /* Keep this item at the end of the list. Tracks total number of support levels. */
+};
+
 struct category {
+	struct member *separators[SUPPORT_COUNT];
 	/*! the Makefile variable */
 	const char *name;
 	/*! the name displayed in the menu */

Modified: trunk/menuselect_curses.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect_curses.c?view=diff&rev=944&r1=943&r2=944
==============================================================================
--- trunk/menuselect_curses.c (original)
+++ trunk/menuselect_curses.c Fri Oct 14 11:28:26 2011
@@ -234,16 +234,19 @@
 		}
 		waddstr(menu, buf);
 	}
-	{ /* 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");
-		if (mem->replacement && *mem->replacement) {
-			char buf2[64];
-			snprintf(buf2, sizeof(buf2), ", Replaced by: %s", mem->replacement);
-			strncat(buf, buf2, sizeof(buf) - strlen(buf) - 1);
-		}
-		waddstr(menu, buf);
+
+	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");
+			if (mem->replacement && *mem->replacement) {
+				char buf2[64];
+				snprintf(buf2, sizeof(buf2), ", Replaced by: %s", mem->replacement);
+				strncat(buf, buf2, sizeof(buf) - strlen(buf) - 1);
+			}
+			waddstr(menu, buf);
+		}
 	}
 }
 
@@ -281,6 +284,8 @@
 		i++;
 		if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE)) {
 			snprintf(buf, sizeof(buf), "XXX %s", mem->name);
+		} else if (mem->is_separator) {
+			snprintf(buf, sizeof(buf), "    --- %s ---", mem->name);
 		} else if (mem->depsfailed == SOFT_FAILURE) {
 			snprintf(buf, sizeof(buf), "<%s> %s", mem->enabled ? "*" : " ", mem->name);
 		} else if (mem->conflictsfailed == SOFT_FAILURE) {
@@ -858,6 +863,7 @@
 	int quit = 0;
 	struct blip *blip;
 	alien_sleeptime = 1000;
+	score = 0;
 
 	while(alien_sleeptime > 100) {
 
@@ -888,8 +894,10 @@
 				/* ignore unknown input */
 				break;
 			}
-			if (quit)
+			if (quit) {
+				alien_sleeptime = 1;
 				break;
+			}
 			if (!(jiffies % 25)) {
 				if (move_aliens() || move_bombs()) {
 					alien_sleeptime = 1;

Modified: trunk/menuselect_gtk.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect_gtk.c?view=diff&rev=944&r1=943&r2=944
==============================================================================
--- trunk/menuselect_gtk.c (original)
+++ trunk/menuselect_gtk.c Fri Oct 14 11:28:26 2011
@@ -290,7 +290,11 @@
 					strncat(cnf_buf, ", ", sizeof(cnf_buf) - strlen(cnf_buf) - 1);
 			}
 
-			snprintf(name_buf, sizeof(name_buf), "%s", mem->name);
+			if (mem->is_separator) {
+				snprintf(name_buf, sizeof(name_buf), "--- %s ---", mem->name);
+			} else {
+				snprintf(name_buf, sizeof(name_buf), "%s", mem->name);
+			}
 			if (mem->depsfailed == HARD_FAILURE)
 				strncat(name_buf, " (Failed Deps.)", sizeof(name_buf) - strlen(name_buf) - 1);
 			if (mem->conflictsfailed == HARD_FAILURE)

Modified: trunk/menuselect_newt.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect_newt.c?view=diff&rev=944&r1=943&r2=944
==============================================================================
--- trunk/menuselect_newt.c (original)
+++ trunk/menuselect_newt.c Fri Oct 14 11:28:26 2011
@@ -20,7 +20,7 @@
  * \file
  *
  * \author Sean Bright <sean.bright at gmail.com>
- * 
+ *
  * \brief newt frontend for selection maintenance
  */
 
@@ -122,7 +122,11 @@
 	}
 
 	if (AST_LIST_EMPTY(&mem->deps)) {
-		newtTextboxSetText(dependsDataTextbox, "N/A");
+		if (mem->is_separator) {
+			newtTextboxSetText(dependsDataTextbox, "");
+		} else {
+			newtTextboxSetText(dependsDataTextbox, "N/A");
+		}
 	} else {
 		strcpy(buffer, "");
 		AST_LIST_TRAVERSE(&mem->deps, dep, list) {
@@ -135,7 +139,11 @@
 	}
 
 	if (AST_LIST_EMPTY(&mem->uses)) {
-		newtTextboxSetText(usesDataTextbox, "N/A");
+		if (mem->is_separator) {
+			newtTextboxSetText(usesDataTextbox, "");
+		} else {
+			newtTextboxSetText(usesDataTextbox, "N/A");
+		}
 	} else {
 		strcpy(buffer, "");
 		AST_LIST_TRAVERSE(&mem->uses, uses, list) {
@@ -148,7 +156,11 @@
 	}
 
 	if (AST_LIST_EMPTY(&mem->conflicts)) {
-		newtTextboxSetText(conflictsDataTextbox, "N/A");
+		if (!mem->is_separator) {
+			newtTextboxSetText(conflictsDataTextbox, "N/A");
+		} else {
+			newtTextboxSetText(conflictsDataTextbox, "");
+		}
 	} else {
 		strcpy(buffer, "");
 		AST_LIST_TRAVERSE(&mem->conflicts, con, list) {
@@ -168,7 +180,11 @@
 			snprintf(buf2, sizeof(buf2), ", Replaced by: %s", mem->replacement);
 			strncat(buffer, buf2, sizeof(buffer) - strlen(buffer) - 1);
 		}
-		newtTextboxSetText(supportLevelDataTextbox, buffer);
+		if (mem->is_separator) {
+			newtTextboxSetText(supportLevelDataTextbox, "");
+		} else {
+			newtTextboxSetText(supportLevelDataTextbox, buffer);
+		}
 	}
 }
 
@@ -190,6 +206,8 @@
 
 		if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE)) {
 			snprintf(buf, sizeof(buf), "XXX %s", mem->name);
+		} else if (mem->is_separator) {
+			snprintf(buf, sizeof(buf), "    --- %s ---", mem->name);
 		} else if (mem->depsfailed == SOFT_FAILURE) {
 			snprintf(buf, sizeof(buf), "<%s> %s", mem->enabled ? "*" : " ", mem->name);
 		} else if (mem->conflictsfailed == SOFT_FAILURE) {




More information about the svn-commits mailing list