summaryrefslogtreecommitdiffstats
path: root/gnu/lib/libdialog
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1998-09-29 12:22:36 +0000
committerjkh <jkh@FreeBSD.org>1998-09-29 12:22:36 +0000
commit2447cf86212eebd2aa6043c50c4d72e61f4e7f31 (patch)
tree6698a8a51eac79ef972ac05bb38ba37947e0f27c /gnu/lib/libdialog
parent4542630b2c3d0a707ead47141c750061b56942a7 (diff)
downloadFreeBSD-src-2447cf86212eebd2aa6043c50c4d72e61f4e7f31.zip
FreeBSD-src-2447cf86212eebd2aa6043c50c4d72e61f4e7f31.tar.gz
Add support for saved trees.
Submitted by: "Anatoly A. Orehovsky" <tolik@mpeks.tomsk.su>
Diffstat (limited to 'gnu/lib/libdialog')
-rw-r--r--gnu/lib/libdialog/dialog.h2
-rw-r--r--gnu/lib/libdialog/tree.c113
2 files changed, 111 insertions, 4 deletions
diff --git a/gnu/lib/libdialog/dialog.h b/gnu/lib/libdialog/dialog.h
index b9d911c..33f8437 100644
--- a/gnu/lib/libdialog/dialog.h
+++ b/gnu/lib/libdialog/dialog.h
@@ -195,7 +195,7 @@ int dialog_ftree(unsigned char *filename, unsigned char FS,
*
* return values:
* -1 - ESC pressed
- * 0 - Ok, result set (must be freed later)
+ * 0 - Ok, result set
* 1 - Cancel
*/
diff --git a/gnu/lib/libdialog/tree.c b/gnu/lib/libdialog/tree.c
index 71ec549..736a2a8 100644
--- a/gnu/lib/libdialog/tree.c
+++ b/gnu/lib/libdialog/tree.c
@@ -117,6 +117,32 @@ static unsigned char *smart_tree(struct queue *queue, unsigned char FS,
/* end of static utils for ftree */
+/* static utils for saved_tree */
+
+/* saved values for unique tree */
+struct saved_tree {
+ unsigned char **names; /* names + */
+ int size; /* size + */
+ unsigned char FS; /* FS + */
+ int height; /* height + */
+ int width; /* width + */
+ int menu_height; /* menu_height - unique for treebox ? */
+ int ch; /* saved ch - choice */
+ int sc; /* saved sc - scroll */
+};
+
+/* search saved tree within queue */
+/* return - struct saved_tree * or NULL if not found */
+static struct saved_tree *search_saved_tree(struct queue *queue,
+ unsigned char **names,
+ int size,
+ unsigned char FS,
+ int height,
+ int width,
+ int menu_height);
+
+/* end of static utils for saved_tree */
+
static void print_item(WINDOW *win, struct leaf item, int choice, int selected);
static void print_position(WINDOW *win, int x, int y,
@@ -581,7 +607,7 @@ int dialog_ftree(unsigned char *filename, unsigned char FS,
*
* return values:
* -1 - ESC pressed
- * 0 - Ok, result set (must be freed later)
+ * 0 - Ok, result set
* 1 - Cancel
*/
@@ -592,6 +618,8 @@ int dialog_tree(unsigned char **names, int size, unsigned char FS,
{
int retcode, choice;
struct leaf *items;
+ struct saved_tree *st;
+ static struct queue *q_saved_tree = NULL;
if (!size)
{
@@ -606,9 +634,43 @@ int dialog_tree(unsigned char **names, int size, unsigned char FS,
end_dialog();
exit(-1);
}
+
+/* is tree saved ? */
+ if (!(st = search_saved_tree(q_saved_tree, names,
+ size, FS,
+ height, width, menu_height))) {
+ if (!q_saved_tree) {
+ if (!(q_saved_tree =
+ calloc(sizeof (struct queue), 1))) {
+ perror("dialog_tree");
+ end_dialog();
+ exit(-1);
+ }
+ }
+
+ if (!(st = calloc(sizeof (struct saved_tree), 1))) {
+ perror("dialog_tree");
+ end_dialog();
+ exit(-1);
+ }
+
+ st->names = names;
+ st->size = size;
+ st->FS = FS;
+ st->height = height;
+ st->width = width;
+ st->menu_height = menu_height;
+
+ if (!p2_queue(q_saved_tree, st)) {
+ perror("dialog_tree");
+ end_dialog();
+ exit(-1);
+ }
+ }
retcode = dialog_treemenu(title, prompt, height, width, menu_height,
- size, items, &choice, NULL, NULL);
+ size, items, &choice,
+ &(st->ch), &(st->sc));
free_leafs(items, size);
@@ -739,7 +801,7 @@ smart_tree(struct queue *queue,
if (*pcurrent == FS) {
pcurrent++;
- if ((pprev == prev) && (*pcurrent)) {
+ if ((!*prev) && (*pcurrent)) {
unsigned char tchar = *pcurrent;
*pcurrent = '\0';
@@ -1015,3 +1077,48 @@ free_names(unsigned char **names, int size, int choice)
} /* free_names() */
/* end of utils for make tree */
+
+/* static utils for saved_tree */
+
+/* search saved tree within queue */
+/* return - struct *saved_tree or NULL if not found */
+static
+struct saved_tree *
+search_saved_tree(struct queue *queue, unsigned char **names, int size,
+ unsigned char FS,
+ int height, int width,
+ int menu_height)
+{
+ struct m_queue *member;
+ struct saved_tree *retval;
+
+ if (!queue || !names || !FS ||
+ !height || !width || !menu_height)
+ return NULL;
+
+ if (!(member = queue->first))
+ return NULL;
+
+ while (member->next) {
+ retval = member->pointer;
+ if ((names == retval->names) &&
+ (size == retval->size) &&
+ (FS == retval->FS) &&
+ (height == retval->height) &&
+ (width == retval->width) &&
+ (menu_height == retval->menu_height))
+ return retval;
+ member = member->next;
+ }
+ retval = member->pointer;
+ if ((names == retval->names) &&
+ (size == retval->size) &&
+ (FS == retval->FS) &&
+ (height == retval->height) &&
+ (width == retval->width) &&
+ (menu_height == retval->menu_height))
+ return retval;
+ return NULL;
+}
+
+/* end of static utils for saved_tree */
OpenPOWER on IntegriCloud