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 E2C3C1387C2 for ; Fri, 1 Feb 2013 10:50:07 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A822E21C053; Fri, 1 Feb 2013 10:49:58 +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 2F56F21C053 for ; Fri, 1 Feb 2013 10:49:53 +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 0208733DCB3 for ; Fri, 1 Feb 2013 10:49:52 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id C4F20E4099 for ; Fri, 1 Feb 2013 10:49:49 +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: <1359656382.b07cb5ebe2e03e4be359e898ffcc2a2d0bd1d6dc.yamakuzure@gentoo> Subject: [gentoo-commits] proj/ufed:master commit in: / X-VCS-Repository: proj/ufed X-VCS-Files: ufed-curses-help.c ufed-curses-help.h X-VCS-Directories: / X-VCS-Committer: yamakuzure X-VCS-Committer-Name: Sven Eden X-VCS-Revision: b07cb5ebe2e03e4be359e898ffcc2a2d0bd1d6dc X-VCS-Branch: master Date: Fri, 1 Feb 2013 10:49:49 +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: bd6f6941-f11c-44db-ad83-ef3abfcaa93e X-Archives-Hash: 37522b5bb99472e0cd44bb135ed15c4c commit: b07cb5ebe2e03e4be359e898ffcc2a2d0bd1d6dc Author: Sven Eden gmx de> AuthorDate: Thu Jan 31 18:19:42 2013 +0000 Commit: Sven Eden gmx de> CommitDate: Thu Jan 31 18:19:42 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/ufed.git;a=commit;h=b07cb5eb Changed the help display to use the new flag type. I have used the oportunity to clean up the line initialization which was unneccessarily complicated. Further added a redraw to the borders to not show the new status separators when the help text is to be displayed. --- ufed-curses-help.c | 154 ++++++++++++++++++++++++++-------------------------- ufed-curses-help.h | 8 +++- 2 files changed, 84 insertions(+), 78 deletions(-) diff --git a/ufed-curses-help.c b/ufed-curses-help.c index ba71d04..76825d2 100644 --- a/ufed-curses-help.c +++ b/ufed-curses-help.c @@ -1,5 +1,4 @@ #include "ufed-curses-help.h" - #include "ufed-curses.h" #include @@ -12,13 +11,15 @@ #include /* internal types */ -static struct line { - struct item item; - char *text; -} *lines; +// Do not use an own struct, just use sFlag +//static struct line { +// struct item item; +// char *text; +//} *lines; +static sFlag* lines = NULL; /* internal members */ -static int helpheight, helpwidth; +static size_t helpheight, helpwidth; /* external members */ @@ -107,117 +108,116 @@ static void init_lines(void) { "Copyright 1999-2005 Gentoo Foundation", "Distributed under the terms of the GNU General Public License v2" }; - struct line *line; - const char * const *paragraph = &help[0], *word = &help[0][0]; - int n, y=0; + sFlag* line = NULL; + size_t lineCount = sizeof(help) / sizeof(*help); + size_t currLine = 0; + size_t n = 0; + int y = 0; + const char* word = help[currLine]; helpheight = wHeight(List); - helpwidth = wWidth(List); + helpwidth = wWidth(List); + char buf[helpwidth + 1]; + memset(buf, 0, (helpwidth + 1) * sizeof(char)); atexit(&free_lines); - for(;;) { - line = malloc(sizeof *line); - if(line==NULL) - ERROR_EXIT(-1, "Can not allocate %lu bytes for help line struct\n", sizeof(*line)); - if(lines==NULL) { - line->item.prev = (struct item *) line; - line->item.next = (struct item *) line; - lines = line; - } else { - line->item.next = (struct item *) lines; - line->item.prev = lines->item.prev; - lines->item.prev->next = (struct item *) line; - lines->item.prev = (struct item *) line; - } + while( currLine < lineCount ) { + line = addFlag(&lines, "help", y++, 1, " "); - line->item.currline = 0; - line->item.isMasked = false; - line->item.isGlobal = true; - line->item.listline = y++; - line->item.ndescr = 1; + // Find the last space character in the string + // if it is too long to display. n = strlen(word); - if(n > helpwidth-1) { - for(n = helpwidth-1; word[n]!=' '; n--) { - if(n==0) { - n = helpwidth; - break; - } - } + if(n > helpwidth - 1) { + for(n = helpwidth-1; (n > 0) && (word[n] != ' '); --n) ; + if(n==0) + n = helpwidth; } - line->text = calloc((n+1), sizeof(char)); - if(line->text==NULL) - ERROR_EXIT(-1, "Can not allocate %lu bytes for help line\n", (n+1) * sizeof(char)); - memcpy(line->text, word, n); - while(word[n]==' ') + + // copy the text if there is any + if (n) { + memcpy(buf, word, n); + buf[n++] = '\0'; + addFlagDesc(line, NULL, buf, "+ "); + } else + addFlagDesc(line, NULL, " ", "+ "); + + // Advance behind current spaces + while (word[n] == ' ') n++; - word += n; - if(word[0]=='\0') { - paragraph++; - if(paragraph == &help[sizeof help / sizeof *help]) - break; - word = &(*paragraph)[0]; - } + + // See whether there is text left... + if (strlen(word) > n) + word += n; + else if (++currLine < lineCount) + // ...or advance one line + word = help[currLine]; } } static void free_lines(void) { - struct line *line = lines; - if(line!=NULL) { - line->item.prev->next = NULL; - do { - void *p = line; - free(line->text); - line = (struct line *) line->item.next; - free(p); - } while(line!=NULL); - lines = NULL; + sFlag* line = lines->prev; + + // Clear all lines + while (lines) { + if (line) + destroyFlag(&lines, &line); + else + destroyFlag(&lines, &lines); + line = lines ? lines->prev ? lines->prev : lines : NULL; } } -static const struct key keys[] = { +static const sKey keys[] = { #define key(x) x, sizeof(x)-1 { '\033', key("Back (Esc)") }, { '\0', key("") } #undef key }; -static int drawline(struct item *item, bool highlight) { - struct line *line = (struct line *) item; +static int drawline(sFlag* line, bool highlight) { char buf[wWidth(List)+1]; - sprintf(buf, "%-*.*s", wWidth(List), wWidth(List), line->text); + + sprintf(buf, "%-*.*s", wWidth(List), wWidth(List), line->desc[0].desc); if(!highlight) wattrset(win(List), COLOR_PAIR(3)); else wattrset(win(List), COLOR_PAIR(3) | A_BOLD | A_REVERSE); - mvwaddstr(win(List), line->item.currline, 0, buf); + mvwaddstr(win(List), line->currline, 0, buf); if(highlight) - wmove(win(List), line->item.currline, 0); + wmove(win(List), line->currline, 0); wnoutrefresh(win(List)); return 1; } -static int callback(struct item **currentitem, int key) { +static int callback(sFlag** curr, int key) { switch(key) { - case 'Q': case 'q': - case '\033': - return 0; + case 'Q': case 'q': + case '\033': + return 0; #ifdef KEY_RESIZE - case KEY_RESIZE: - free_lines(); - init_lines(); - *currentitem = (struct item *) lines; - return -2; + case KEY_RESIZE: + free_lines(); + init_lines(); + *curr = lines; + return -2; #endif - default: - return -1; + default: + return -1; } } void help(void) { - if(helpheight!=wHeight(List) || helpwidth!=wWidth(List)) { + if ( ((int)helpheight != wHeight(List)) + || ((int)helpwidth != wWidth(List)) ) { if(lines!=NULL) free_lines(); init_lines(); } - maineventloop("", &callback, &drawline, (struct item *) lines, keys); + + maineventloop("", &callback, &drawline, lines, keys, false); + + // Re-draw separators: + drawTop(true); + drawBottom(true); + drawStatus(true); } diff --git a/ufed-curses-help.h b/ufed-curses-help.h index 5c66482..4cc0df0 100644 --- a/ufed-curses-help.h +++ b/ufed-curses-help.h @@ -1 +1,7 @@ -extern void help(void); +#pragma once +#ifndef UFED_CURSES_HELP_H_INCLUDED +#define UFED_CURSES_HELP_H_INCLUDED + +void help(void); + +#endif /* UFED_CURSES_HELP_H_INCLUDED */