From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 8E3FC1381F3 for ; Fri, 20 Sep 2013 08:30:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id F3674E0B78; Fri, 20 Sep 2013 08:30:43 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 466EAE0B4C for ; Fri, 20 Sep 2013 08:30:43 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A0D8333ECEB for ; Fri, 20 Sep 2013 08:30:41 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 4268DE545D for ; Fri, 20 Sep 2013 08:30:40 +0000 (UTC) From: "Sven Eden" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sven Eden" Message-ID: <1379576309.a42e79a4cab19cedb9995eda1e557ee491a74355.yamakuzure@gentoo> Subject: [gentoo-commits] proj/ufed:master commit in: / X-VCS-Repository: proj/ufed X-VCS-Files: ufed-curses-types.c X-VCS-Directories: / X-VCS-Committer: yamakuzure X-VCS-Committer-Name: Sven Eden X-VCS-Revision: a42e79a4cab19cedb9995eda1e557ee491a74355 X-VCS-Branch: master Date: Fri, 20 Sep 2013 08:30:40 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 51042247-9a32-420b-9b78-0f2aa1a42322 X-Archives-Hash: d578c8d353a8061ae45fd93d9dba80db commit: a42e79a4cab19cedb9995eda1e557ee491a74355 Author: Sven Eden gmx net> AuthorDate: Thu Sep 19 07:38:29 2013 +0000 Commit: Sven Eden gmx de> CommitDate: Thu Sep 19 07:38:29 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=a42e79a4 Fixed calculateDescWrap() to ensure clean wrapped parts chains. --- ufed-curses-types.c | 73 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/ufed-curses-types.c b/ufed-curses-types.c index b61ec38..9d59234 100644 --- a/ufed-curses-types.c +++ b/ufed-curses-types.c @@ -528,13 +528,13 @@ static void calculateDescWrap(sDesc* desc) 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 width = desc->wrapWidth - 2; // Follow-up lines are indented + size_t dLen = pDesc ? strlen(pDesc) : 0; + size_t pLen = pPkg ? strlen(pPkg) : 0; size_t left = dLen + pLen; size_t wLen = eOrder_left == desc->wrapOrder ? pLen : dLen; - /* To go by next a valid curr is needed first */ + /* A valid curr is needed first */ if (NULL == curr) { curr = (sWrap*)malloc(sizeof(sWrap)); if (curr) { @@ -543,10 +543,28 @@ static void calculateDescWrap(sDesc* desc) curr->pos = 0; desc->wrap = curr; } else - ERROR_EXIT(-1, "Unable to allocate %lu bytes for sWrap_ struct\n", sizeof(sWrap)) + ERROR_EXIT(-1, + "Unable to allocate %lu bytes for sWrap_ struct\n", + sizeof(sWrap)) } - /* Now distribute all characters */ + // The description starts without a valid wrap now + desc->wrapCount = 0; + + /* When starting there are two possible situations. + * a) A global flag with order left, so desc->pkg and therefore + * pch also are NULL + * b) any other combination. + * Any other is just fine, but situation a must be caught and handled + * before going any further. + */ + if (NULL == pch) { + pch = pDesc; + wLen = dLen; + left = dLen; + } + + // Now distribute all characters while (left) { // Step 1: Set current wrap part end @@ -555,7 +573,7 @@ static void calculateDescWrap(sDesc* desc) end = wLen - 1; // Step 2: Find last space character before end+1 - if (' ' != pch[end]) { + if ((end > start) && (end < (wLen - 1)) && (' ' != pch[end])) { size_t newEnd = end; for (; (newEnd > start) && (' ' != pch[newEnd]) ; --newEnd) ; if (newEnd > start) @@ -564,35 +582,49 @@ static void calculateDescWrap(sDesc* desc) // Step 3: Note values and increase start curr->pos = start; - curr->len = end - start; + curr->len = end - start + (' ' == pch[end] ? 0 : 1); start += curr->len; left -= curr->len; + ++desc->wrapCount; + + // skip white space + while (left && (start < wLen) && (' ' == pch[start])) { + ++start; + --left; + } + // Step 4: Switch if the current string is exhausted: - if (left && (end == (wLen - 1))) { + if (left && (!wLen || (end >= (wLen - 1)) || (start >= wLen) ) ) { if (eOrder_left == desc->wrapOrder) { // Switch from pkg to desc pch = pDesc; wLen = dLen; + left = dLen; } else { // Switch from desc to pkg pch = pPkg; wLen = pLen; + left = 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)) + if (curr->len) { + 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 @@ -603,7 +635,8 @@ static void calculateDescWrap(sDesc* desc) } // Step 7: Advance - curr = next; + if (curr->len) + curr = next; } // End of having characters left to distribute } // End of having a not NULL pointer }