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 A548D1381F3 for ; Fri, 20 Sep 2013 08:31:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2D03CE0BE3; Fri, 20 Sep 2013 08:31:05 +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 B6C91E0BE3 for ; Fri, 20 Sep 2013 08:31:04 +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 A792933ECEB for ; Fri, 20 Sep 2013 08:30:43 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 5B47CE545D for ; Fri, 20 Sep 2013 08:30:42 +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: <1379661183.5b527ddbd050f6ec0a5cdf6b5ecce8f923e00683.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: 5b527ddbd050f6ec0a5cdf6b5ecce8f923e00683 X-VCS-Branch: master Date: Fri, 20 Sep 2013 08:30:42 +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: 7c273a5d-dd85-486d-a98e-f1c668706b3b X-Archives-Hash: cc3a1cb9b9b33652da7ed21e91c6a42e commit: 5b527ddbd050f6ec0a5cdf6b5ecce8f923e00683 Author: Sven Eden gmx net> AuthorDate: Fri Sep 20 07:13:03 2013 +0000 Commit: Sven Eden gmx de> CommitDate: Fri Sep 20 07:13:03 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=5b527ddb calculateDescWrap(): Cleaned the code up and made it more robust. The code can now correctly break any situation but one. The missing one is a one line affected package, that, although it is broken in time, it is broken 2-3 characters early then if the available space is just not enough. Hoewever, I believe everybody can live with this. --- ufed-curses-types.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/ufed-curses-types.c b/ufed-curses-types.c index 1a30392..b3eb012 100644 --- a/ufed-curses-types.c +++ b/ufed-curses-types.c @@ -532,7 +532,7 @@ static void calculateDescWrap(sDesc* desc) 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; + size_t wLen = (eOrder_left == desc->wrapOrder ? pLen : dLen) - 1; size_t oLen = 0; // Set to the first part to be added to pos on the second // part, so drawflag knows from where to start taking in the unified desc. @@ -562,7 +562,7 @@ static void calculateDescWrap(sDesc* desc) */ if (NULL == pch) { pch = pDesc; - wLen = dLen; + wLen = dLen - 1; left = dLen; } @@ -581,19 +581,28 @@ static void calculateDescWrap(sDesc* desc) // and two spaces less in their last line, because another // bracked is postfixed and the leading whitespace is // skipped below. + bool isEnd = (end >= wLen); + bool isStart = (!start || (start == oLen)); if (pch == pPkg) { - if (!start || (start == oLen)) + // Add one space for leading bracket on pure starts + if (isStart) --end; - else if (end >= (wLen - 1)) + + // Add two spaces for leading whitespace and closing bracket + // on pure end, or both brackets if this is start and end + if (isEnd) end -= 2; } // Don't shoot over the target! - if (end >= wLen) - end = wLen - 1; + if (end > wLen) { + end = wLen; + isEnd = true; + } else + isEnd = (end == wLen); // Step 2: Find last space character before end+1 - if ((end > start) && (end < (wLen - 1)) && (' ' != pch[end])) { + if ((end > start) && !isEnd && (' ' != pch[end])) { size_t newEnd = end; for (; (newEnd > start) && (' ' != pch[newEnd]) ; --newEnd) ; if (newEnd > start) @@ -602,13 +611,13 @@ static void calculateDescWrap(sDesc* desc) // Step 3: Note values and increase start curr->pos = start + oLen; - curr->len = end - start + (end == (wLen - 1) ? 1 : 0); + curr->len = end - start + (isEnd ? 1 : 0); start += curr->len; left -= curr->len; ++desc->wrapCount; // skip white space - while (left && (start < wLen) && (' ' == pch[start])) { + while (left && (start <= wLen) && (' ' == pch[start])) { ++start; --left; } @@ -617,28 +626,25 @@ static void calculateDescWrap(sDesc* desc) // Note: in drawflag() the string is pre- and postfixed with '(' / ')' if (pch == pPkg) { // And one to start - if (oLen == curr->pos) - ++curr->len; + if (isStart) ++curr->len; // Add one to the end - if (end >= (wLen - 1)) - ++curr->len; + if (isEnd) ++curr->len; // If this is not the first line, add one to pos: - if (curr->pos && (oLen != curr->pos)) - ++curr->pos; + if (!isStart) ++curr->pos; } // Step 4: Switch if the current string is exhausted: - if (left && (!wLen || (end >= (wLen - 1)) || (start >= wLen) ) ) { + if (left && (isEnd || (start > wLen) ) ) { if (eOrder_left == desc->wrapOrder) { // Switch from pkg to desc pch = pDesc; - wLen = dLen; + wLen = dLen - 1; oLen = pLen + 3; // +2 for the brackets, + 1 for leading space } else { // Switch from desc to pkg pch = pPkg; - wLen = pLen; + wLen = pLen - 1; oLen = dLen + 1; // +1 for leading space } start = 0;