Update tree function and remove gratuitous .h file.
Submitted by: "Anatoly A. Orehovsky" <tolik@mpeks.tomsk.su>
This commit is contained in:
parent
2c4ac21582
commit
f9db8b1233
@ -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;
|
||||
|
@ -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);
|
Loading…
Reference in New Issue
Block a user