public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sven Eden" <sven.eden@gmx.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/ufed:master commit in: /
Date: Fri, 20 Sep 2013 08:30:38 +0000 (UTC)	[thread overview]
Message-ID: <1379313337.960cc1b3587cf63bc99e1a8976c10b110aafb5d1.yamakuzure@gentoo> (raw)

commit:     960cc1b3587cf63bc99e1a8976c10b110aafb5d1
Author:     Sven Eden <yamakuzure <AT> gmx <DOT> net>
AuthorDate: Mon Sep 16 06:35:37 2013 +0000
Commit:     Sven Eden <sven.eden <AT> gmx <DOT> de>
CommitDate: Mon Sep 16 06:35:37 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=960cc1b3

types: Added calculation of wrapped description parameters.

---
 ufed-curses-checklist.c |   6 +-
 ufed-curses-types.c     | 154 ++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 144 insertions(+), 16 deletions(-)

diff --git a/ufed-curses-checklist.c b/ufed-curses-checklist.c
index 61e0de5..f55cf66 100644
--- a/ufed-curses-checklist.c
+++ b/ufed-curses-checklist.c
@@ -202,11 +202,11 @@ static void free_flags(void)
 
 static int drawflag(sFlag* flag, bool highlight)
 {
+	int  idx     = 0;
+	int  usedY   = 0;
+	int  line    = flag->currline;
 	char buf[wWidth(List)+1];
 	char desc[maxDescWidth];
-	int idx   = 0;
-	int usedY = 0;
-	int line  = flag->currline;
 
 	// Return early if there is nothing to display:
 	if (!isFlagLegal(flag))

diff --git a/ufed-curses-types.c b/ufed-curses-types.c
index 2ccfa9a..b61ec38 100644
--- a/ufed-curses-types.c
+++ b/ufed-curses-types.c
@@ -21,6 +21,10 @@ extern eMask  e_mask;
 extern eScope e_scope;
 extern eState e_state;
 
+/* internal prototypes of functions only used here */
+static void calculateDescWrap(sDesc* desc);
+static void destroyWrapList(sWrap* wrap);
+
 /* function implementations */
 
 /** @brief create a new flag without description lines
@@ -219,16 +223,7 @@ void destroyFlag (sFlag** root, sFlag** flag)
 				free (xFlag->desc[i].desc);
 			if (xFlag->desc[i].desc_alt)
 				free (xFlag->desc[i].desc_alt);
-			if (xFlag->desc[i].wrap) {
-				sWrap* wrapRoot = xFlag->desc[i].wrap;
-				sWrap* wrapNext = wrapRoot ? wrapRoot->next : NULL;
-				xFlag->desc[i].wrap = NULL;
-				while (wrapRoot) {
-					free (wrapRoot);
-					wrapRoot = wrapNext;
-					wrapNext = wrapRoot ? wrapRoot->next : NULL;
-				}
-			}
+			destroyWrapList(xFlag->desc[i].wrap);
 		}
 		if (xFlag->desc)
 			free (xFlag->desc);
@@ -298,6 +293,8 @@ void genFlagStats (sFlag* flag)
 /** @brief determine the number of lines used by @a flag
  *  This method checks the flag and its description line(s)
  *  settings against the globally active filters.
+ *  If line wrapping is active, the wrap settings are
+ *  recalculated if neccessary.
  *  If @a flag is NULL, the result will be 0.
  *  @param[in] flag pointer to the flag to check.
  *  @return number of lines needed to display the line *without* possible line wrapping.
@@ -307,9 +304,31 @@ int getFlagHeight (const sFlag* flag)
 	int result = 0;
 
 	if (flag) {
-		for (int i = 0; i < flag->ndesc; ++i)
-			result += isDescLegal(flag, i) ? 1 : 0;
-	}
+		size_t maxLen = wWidth(List) - (minwidth + 8);;
+		for (int i = 0; i < flag->ndesc; ++i) {
+			if (isDescLegal(flag, i)) {
+				if (eWrap_normal == e_wrap)
+					++result;
+				else {
+					/* Check settings. The calculations must not
+					 * be done unless neccessary to not cripple
+					 * performance.
+					 */
+					sDesc* desc = &(flag->desc[i]);
+					if ( !desc->wrap
+					  || (desc->wrapWidth != maxLen)
+					  || (desc->wrapOrder != e_order)
+					  || (desc->wrapStripped != e_desc) ) {
+						desc->wrapWidth    = maxLen;
+						desc->wrapOrder    = e_order;
+						desc->wrapStripped = e_desc;
+						calculateDescWrap(desc);
+					}
+					result += desc->wrapCount;
+				}
+			} // End of having a legal flag
+		} // End of looping descriptions
+	} // End of having a flag
 
 	return result;
 }
@@ -494,3 +513,112 @@ void setKeyDispLen(sKey* keys, size_t dispWidth)
 		} // End of having a key
 	} // End of setting button display lengths
 }
+
+
+/* === Internal functions only used here === */
+
+/// @brief calculate the current wrap chain for description @a desc
+static void calculateDescWrap(sDesc* desc)
+{
+	if (desc) {
+		sWrap* curr  = desc->wrap;
+		sWrap* next  = NULL;
+		char*  pDesc = eDesc_ori == desc->wrapStripped ? desc->desc : desc->desc_alt;
+		char*  pPkg  = desc->pkg;
+		char*  pch   = eOrder_left == desc->wrapOrder ? pPkg : pDesc;
+		size_t start = 0;
+		size_t end   = 0;
+		size_t width = desc->wrapWidth - 2; // Foloow-up lines are indented
+		size_t dLen  = strlen(pDesc);
+		size_t pLen  = strlen(pPkg);
+		size_t left  = dLen + pLen;
+		size_t wLen  = eOrder_left == desc->wrapOrder ? pLen : dLen;
+
+		/* To go by next a valid curr is needed first */
+		if (NULL == curr) {
+			curr = (sWrap*)malloc(sizeof(sWrap));
+			if (curr) {
+				curr->len  = 0;
+				curr->next = NULL;
+				curr->pos  = 0;
+				desc->wrap = curr;
+			} else
+				ERROR_EXIT(-1, "Unable to allocate %lu bytes for sWrap_ struct\n", sizeof(sWrap))
+		}
+
+		/* Now distribute all characters */
+		while (left) {
+
+			// Step 1: Set current wrap part end
+			end = start + width + (curr == desc->wrap ? 2 : 0);
+			if (end >= wLen)
+				end = wLen - 1;
+
+			// Step 2: Find last space character before end+1
+			if (' ' != pch[end]) {
+				size_t newEnd = end;
+				for (; (newEnd > start) && (' ' != pch[newEnd]) ; --newEnd) ;
+				if (newEnd > start)
+					end = newEnd;
+			}
+
+			// Step 3: Note values and increase start
+			curr->pos = start;
+			curr->len = end - start;
+			start += curr->len;
+			left  -= curr->len;
+
+			// Step 4: Switch if the current string is exhausted:
+			if (left && (end == (wLen - 1))) {
+				if (eOrder_left == desc->wrapOrder) {
+					// Switch from pkg to desc
+					pch  = pDesc;
+					wLen = dLen;
+				} else {
+					// Switch from desc to pkg
+					pch  = pPkg;
+					wLen = pLen;
+				}
+				start = 0;
+			} // End of having to swap pkg/desc
+
+			// Step 5: Extend if needed
+			next = curr->next;
+			if (left && !next) {
+				next = (sWrap*)malloc(sizeof(sWrap));
+				if (next) {
+					next->len  = 0;
+					next->next = NULL;
+					next->pos  = 0;
+					curr->next = next;
+				} else
+					ERROR_EXIT(-1, "Unable to allocate %lu bytes for sWrap_ struct\n", sizeof(sWrap))
+			}
+
+			// Step 6: Clean up if done
+			if (!left && next) {
+				curr->next = NULL;
+				destroyWrapList(next);
+				next = NULL;
+			}
+
+			// Step 7: Advance
+			curr = next;
+		} // End of having characters left to distribute
+	} // End of having a not NULL pointer
+}
+
+
+/// @brief destroy one sWrap singly linked list
+static void destroyWrapList(sWrap* wrap)
+{
+	if (wrap) {
+		sWrap* wrapRoot = wrap;
+		sWrap* wrapNext = wrapRoot ? wrapRoot->next : NULL;
+		while (wrapRoot) {
+			free (wrapRoot);
+			wrapRoot = wrapNext;
+			wrapNext = wrapRoot ? wrapRoot->next : NULL;
+		}
+	}
+}


             reply	other threads:[~2013-09-20  8:30 UTC|newest]

Thread overview: 238+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-20  8:30 Sven Eden [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-11-07 14:25 [gentoo-commits] proj/ufed:master commit in: / Sven Eden
2020-05-02  8:38 Ulrich Müller
2019-09-27  6:42 Sven Eden
2019-09-27  6:39 Sven Eden
2019-09-24 17:57 Sven Eden
2019-09-24 17:56 Sven Eden
2019-04-07 15:17 David Seifert
2019-04-07 13:56 David Seifert
2019-04-07 13:19 David Seifert
2019-04-07 13:19 David Seifert
2019-04-07 13:19 David Seifert
2019-04-07 13:19 David Seifert
2019-04-07 13:19 David Seifert
2015-02-12 15:47 Sven Eden
2015-02-11  9:03 Sven Eden
2014-11-10  9:59 Sven Eden
2014-10-28 11:43 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-26 10:26 Sven Eden
2014-02-25  8:18 Sven Eden
2014-02-25  8:18 Sven Eden
2014-02-25  8:18 Sven Eden
2014-02-25  8:18 Sven Eden
2013-11-25 21:43 Sven Eden
2013-11-25 21:43 Sven Eden
2013-11-25 21:43 Sven Eden
2013-11-25 21:43 Sven Eden
2013-11-25 21:43 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-20  8:30 Sven Eden
2013-09-11  7:09 Sven Eden
2013-09-11  6:31 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-11  6:04 Sven Eden
2013-09-10 12:37 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-09-10  6:36 Sven Eden
2013-07-22  9:34 Sven Eden
2013-07-22  6:09 Sven Eden
2013-07-22  6:09 Sven Eden
2013-04-09  7:22 Sven Eden
2013-04-09  7:22 Sven Eden
2013-04-09  7:22 Sven Eden
2013-04-08  7:18 Sven Eden
2013-04-03 13:39 Sven Eden
2013-03-05 16:53 Sven Eden
2013-03-05 16:49 Sven Eden
2013-03-05 16:49 Sven Eden
2013-03-05 16:49 Sven Eden
2013-03-05 16:49 Sven Eden
2013-03-05 16:49 Sven Eden
2013-02-21 10:02 Sven Eden
2013-02-19 15:16 Sven Eden
2013-02-19 13:34 Sven Eden
2013-02-18  7:22 Sven Eden
2013-02-15  8:36 Sven Eden
2013-02-15  8:36 Sven Eden
2013-02-15  8:36 Sven Eden
2013-02-14  8:35 Sven Eden
2013-02-14  8:35 Sven Eden
2013-02-14  8:35 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-13  9:23 Sven Eden
2013-02-12 10:51 Sven Eden
2013-02-12 10:51 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-12  9:01 Sven Eden
2013-02-06  9:09 Sven Eden
2013-02-06  9:09 Sven Eden
2013-02-05 18:06 Paul Varner
2013-02-05 13:53 Sven Eden
2013-02-05 13:53 Sven Eden
2013-02-05 11:24 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-03 14:32 Sven Eden
2013-02-02 20:49 Sven Eden
2013-02-02 10:11 Sven Eden
2013-02-02  9:47 Sven Eden
2013-02-02  9:47 Sven Eden
2013-02-02  9:47 Sven Eden
2013-02-01 21:12 Sven Eden
2013-02-01 21:12 Sven Eden
2013-02-01 21:12 Sven Eden
2013-02-01 16:04 Sven Eden
2013-02-01 15:55 Sven Eden
2013-02-01 15:26 Sven Eden
2013-02-01 14:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-02-01 10:49 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-24 10:15 Sven Eden
2013-01-23 14:44 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-23 12:05 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-19 21:43 Sven Eden
2013-01-16 13:43 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-16 12:56 Sven Eden
2013-01-08 11:02 Sven Eden
2013-01-02  8:47 Sven Eden
2013-01-02  8:01 Sven Eden
2013-01-02  8:01 Sven Eden
2012-11-20 17:31 Paul Varner
2012-11-20 17:25 Paul Varner
2012-10-23 16:13 Paul Varner
2012-10-23 16:13 Paul Varner
2012-10-23 16:13 Paul Varner
2012-10-23 16:01 Paul Varner
2012-10-22 20:42 Paul Varner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379313337.960cc1b3587cf63bc99e1a8976c10b110aafb5d1.yamakuzure@gentoo \
    --to=sven.eden@gmx.de \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox