aboutsummaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorJordan K. Hubbard <jkh@FreeBSD.org>1998-09-28 16:12:49 +0000
committerJordan K. Hubbard <jkh@FreeBSD.org>1998-09-28 16:12:49 +0000
commit31f0cd629b010c9430fd7c9139cf105dfe135573 (patch)
tree90ad4553553fc812aaa85df0ea28b69c315a7215 /gnu
parent364c8e85fb08d8571d62558a86040b8d69e761a8 (diff)
downloadsrc-31f0cd629b010c9430fd7c9139cf105dfe135573.tar.gz
src-31f0cd629b010c9430fd7c9139cf105dfe135573.zip
Update tree function and remove gratuitous .h file.
Submitted by: "Anatoly A. Orehovsky" <tolik@mpeks.tomsk.su>
Notes
Notes: svn path=/head/; revision=39718
Diffstat (limited to 'gnu')
-rw-r--r--gnu/lib/libdialog/tree.c81
-rw-r--r--gnu/lib/libdialog/tree.h46
2 files changed, 79 insertions, 48 deletions
diff --git a/gnu/lib/libdialog/tree.c b/gnu/lib/libdialog/tree.c
index 957beb5cfea9..71ec549172fa 100644
--- a/gnu/lib/libdialog/tree.c
+++ b/gnu/lib/libdialog/tree.c
@@ -4,6 +4,7 @@
* Author: Anatoly A. Orehovsky (tolik@mpeks.tomsk.su)
*
* Copyright (c) 1997, Anatoly A. Orehovsky
+ * 09/28/98 - patched by Anatoly A. Orehovsky (smart_tree())
*
*/
@@ -108,6 +109,12 @@ static void *first_queue(struct queue *queue);
/* return - pointer to array or NULL if error */
static void **q2arr(struct queue *queue, int depth);
+/* smart_tree (for like find(1) with -d flag output compliance) */
+/* return - not NULL or NULL if malloc error */
+static unsigned char *smart_tree(struct queue *queue, unsigned char FS,
+ unsigned char *current,
+ unsigned char *prev);
+
/* end of static utils for ftree */
static void print_item(WINDOW *win, struct leaf item, int choice, int selected);
@@ -700,6 +707,75 @@ q2arr(struct queue *queue, int depth)
}
+/*
+ * smart_tree (for like find(1) with -d flag output compliance)
+ *
+ * return values:
+ * NULL - malloc error
+ * not NULL - ok
+ *
+ */
+static
+unsigned char *
+smart_tree(struct queue *queue,
+ unsigned char FS,
+ unsigned char *current,
+ unsigned char *prev) {
+ unsigned char *pcurrent = current, *pprev = prev, *toqueue;
+ register char break_flag = 0;
+
+ while(*pcurrent && *pprev) {
+ if (*pcurrent == *pprev) {
+ pcurrent++;
+ pprev++;
+ }
+ else {
+ break_flag = 1;
+ break;
+ }
+ }
+
+ if (!*pprev || break_flag) {
+ if (*pcurrent == FS) {
+ pcurrent++;
+
+ if ((pprev == prev) && (*pcurrent)) {
+ unsigned char tchar = *pcurrent;
+
+ *pcurrent = '\0';
+ if (!(toqueue = strdup(current))) {
+ *pcurrent = tchar;
+ return NULL;
+ }
+ if (!p2_queue(queue, toqueue)) {
+ *pcurrent = tchar;
+ return NULL;
+ }
+ *pcurrent = tchar;
+ }
+ }
+
+ while(*pcurrent) {
+ if (*pcurrent == FS) {
+ *pcurrent = '\0';
+ if (!(toqueue = strdup(current))) {
+ *pcurrent = FS;
+ return NULL;
+ }
+ if (!p2_queue(queue, toqueue)) {
+ *pcurrent = FS;
+ return NULL;
+ }
+ *pcurrent = FS;
+ }
+ pcurrent++;
+ }
+ if (!p2_queue(queue, current))
+ return NULL;
+ }
+ return current;
+}
+
/* end of utils for ftree */
/* utils for make tree */
@@ -765,7 +841,7 @@ mk_ftree(char *filename,
{
int NR; /* number of input records */
struct queue queue;
- unsigned char *string;
+ unsigned char *string, *sstring = "";
unsigned char **names;
FILE *input_file;
@@ -787,8 +863,9 @@ mk_ftree(char *filename,
if (!(string = realloc(string, strlen(string) + 1)))
return -1;
- if (!p2_queue(&queue, string))
+ if (!smart_tree(&queue, FS, string, sstring))
return -1;
+ sstring = string;
if (!(string = malloc(BUFSIZ)))
return -1;
diff --git a/gnu/lib/libdialog/tree.h b/gnu/lib/libdialog/tree.h
deleted file mode 100644
index e78b3d5b0f05..000000000000
--- a/gnu/lib/libdialog/tree.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Display a tree menu from file
- *
- * filename - file with like find(1) output
- * FS - fields separator
- * title - title of dialog box
- * prompt - prompt text into dialog box
- * height - height of dialog box
- * width - width of dialog box
- * menu_height - height of menu box
- * result - pointer to char array
- *
- * return values:
- * -1 - ESC pressed
- * 0 - Ok, result set (must be freed later)
- * 1 - Cancel
- */
-
-int dialog_ftree(unsigned char *filename, unsigned char FS,
- unsigned char *title, unsigned char *prompt,
- int height, int width, int menu_height,
- unsigned char **result);
-
-/*
- * Display a tree menu from array
- *
- * names - array with like find(1) output
- * size - size of array
- * FS - fields separator
- * title - title of dialog box
- * prompt - prompt text into dialog box
- * height - height of dialog box
- * width - width of dialog box
- * menu_height - height of menu box
- * result - pointer to char array
- *
- * return values:
- * -1 - ESC pressed
- * 0 - Ok, result set (must be freed later)
- * 1 - Cancel
- */
-
-int dialog_tree(unsigned char **names, int size, unsigned char FS,
- unsigned char *title, unsigned char *prompt,
- int height, int width, int menu_height,
- unsigned char **result);