1995-10-15 12:41:09 +00:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1995-10-16 15:14:28 +00:00
|
|
|
* $Id: index.c,v 1.9 1995/10/16 09:25:13 jkh Exp $
|
1995-10-15 12:41:09 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Jordan Hubbard. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* verbatim and that no modifications are made prior to this
|
|
|
|
* point in the file.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Jordan Hubbard
|
|
|
|
* for the FreeBSD Project.
|
|
|
|
* 4. The name of Jordan Hubbard or the FreeBSD project may not be used to
|
|
|
|
* endorse or promote products derived from this software without specific
|
|
|
|
* prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1995-10-16 09:25:22 +00:00
|
|
|
#include <fcntl.h>
|
1995-10-07 11:55:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ncurses.h>
|
|
|
|
#include <dialog.h>
|
|
|
|
#include "sysinstall.h"
|
|
|
|
|
|
|
|
/* Macros and magic values */
|
|
|
|
#define MAX_MENU 13
|
|
|
|
|
|
|
|
/* Smarter strdup */
|
|
|
|
inline char *
|
|
|
|
_strdup(char *ptr)
|
|
|
|
{
|
|
|
|
return ptr ? strdup(ptr) : ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *descrs[] = {
|
1995-10-14 19:13:35 +00:00
|
|
|
"Package Selection",
|
|
|
|
"To select a package or category, move to it and press SPACE.\n"
|
|
|
|
"To remove a package from consideration, press SPACE again.\n"
|
|
|
|
"To go to a previous menu, select UP item or Cancel. To search\n"
|
|
|
|
"for a package by name, press ESC.",
|
|
|
|
"Package Targets", "These are the packages you've selected for extraction.\n\n"
|
|
|
|
"If you're sure of these choices, select OK.\n"
|
|
|
|
"If not, select Cancel to go back to the package selection menu.\n",
|
1995-10-07 11:55:37 +00:00
|
|
|
"All", "All available packages in all categories.",
|
|
|
|
"applications", "User application software.",
|
|
|
|
"archivers", "Utilities for archiving and unarchiving data.",
|
|
|
|
"audio", "Audio utilities - most require a supported sound card.",
|
|
|
|
"benchmarks", "Utilities for measuring system performance.",
|
|
|
|
"benchmarking", "Utilities for measuring system performance.",
|
|
|
|
"cad", "Computer Aided Design utilities.",
|
|
|
|
"comms", "Communications utilities.",
|
|
|
|
"databases", "Database software.",
|
|
|
|
"devel", "Software development utilities and libraries.",
|
|
|
|
"development", "Software development utilities and libraries.",
|
|
|
|
"documentation", "Document preparation utilities.",
|
|
|
|
"editors", "Common text editors.",
|
|
|
|
"emulation", "Utilities for emulating other OS types.",
|
|
|
|
"emulators", "Utilities for emulating other OS types.",
|
|
|
|
"games", "Various and sundry amusements.",
|
|
|
|
"graphics", "Graphics libraries and utilities.",
|
|
|
|
"japanese", "Ported software for the Japanese market.",
|
|
|
|
"lang", "Computer languages.",
|
|
|
|
"languages", "Computer languages.",
|
|
|
|
"libraries", "Software development libraries.",
|
|
|
|
"mail", "Electronic mail packages and utilities.",
|
|
|
|
"math", "Mathematical computation software.",
|
|
|
|
"net", "Networking utilities.",
|
|
|
|
"networking", "Networking utilities.",
|
|
|
|
"news", "USENET News support software.",
|
|
|
|
"numeric", "Mathematical computation software.",
|
|
|
|
"orphans", "Packages without a home elsewhere.",
|
|
|
|
"plan9", "Software from the plan9 Operating System.",
|
|
|
|
"print", "Utilities for dealing with printing.",
|
|
|
|
"printing", "Utilities for dealing with printing.",
|
|
|
|
"programming", "Software development utilities and libraries.",
|
|
|
|
"russian", "Ported software for the Russian market.",
|
|
|
|
"security", "System security software.",
|
|
|
|
"shells", "Various shells (tcsh, bash, etc).",
|
|
|
|
"sysutils", "Various system utilities.",
|
|
|
|
"troff", "TROFF Text formatting utilities.",
|
|
|
|
"utils", "Various user utilities.",
|
|
|
|
"utilities", "Various user utilities.",
|
|
|
|
"x11", "X Window System based utilities.",
|
|
|
|
NULL, NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *
|
|
|
|
fetch_desc(char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; descrs[i]; i += 2) {
|
|
|
|
if (!strcmp(descrs[i], name))
|
|
|
|
return descrs[i + 1];
|
|
|
|
}
|
|
|
|
return "No description provided";
|
|
|
|
}
|
|
|
|
|
|
|
|
static PkgNodePtr
|
|
|
|
new_pkg_node(char *name, node_type type)
|
|
|
|
{
|
|
|
|
PkgNodePtr tmp = malloc(sizeof(PkgNode));
|
|
|
|
|
|
|
|
if (!tmp) {
|
|
|
|
fprintf(stderr, "Out of memory - unable to allocate a new package node!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
bzero(tmp, sizeof(PkgNode));
|
|
|
|
tmp->name = _strdup(name);
|
|
|
|
tmp->type = type;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IndexEntryPtr
|
|
|
|
new_index(char *name, char *pathto, char *prefix, char *comment, char *descr, char *maint)
|
|
|
|
{
|
|
|
|
IndexEntryPtr tmp = malloc(sizeof(IndexEntry));
|
|
|
|
|
|
|
|
if (!tmp) {
|
|
|
|
fprintf(stderr, "Out of memory - unable to allocate a new index node!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(tmp, sizeof(IndexEntry));
|
|
|
|
tmp->name = _strdup(name);
|
|
|
|
tmp->path = _strdup(pathto);
|
|
|
|
tmp->prefix = _strdup(prefix);
|
|
|
|
tmp->comment = _strdup(comment);
|
|
|
|
tmp->descrfile = _strdup(descr);
|
|
|
|
tmp->maintainer = _strdup(maint);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
1995-10-16 07:31:11 +00:00
|
|
|
strchop(char *s1, char *s2, int len)
|
1995-10-07 11:55:37 +00:00
|
|
|
{
|
|
|
|
int len2;
|
|
|
|
|
1995-10-16 07:31:11 +00:00
|
|
|
len2 = strlen(s1);
|
|
|
|
if (len2 >= len) {
|
|
|
|
strncpy(s1, s2, len - 1);
|
|
|
|
s1[len] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcpy(s1, s2);
|
|
|
|
return s1;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
index_register(PkgNodePtr top, char *where, IndexEntryPtr ptr)
|
|
|
|
{
|
|
|
|
PkgNodePtr p, q;
|
|
|
|
|
|
|
|
q = NULL;
|
|
|
|
p = top->kids;
|
|
|
|
while (p) {
|
|
|
|
if (!strcmp(p->name, where)) {
|
|
|
|
q = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
if (!p) {
|
|
|
|
/* Add new category */
|
|
|
|
q = new_pkg_node(where, PLACE);
|
|
|
|
q->desc = fetch_desc(where);
|
|
|
|
q->next = top->kids;
|
|
|
|
top->kids = q;
|
|
|
|
}
|
|
|
|
p = new_pkg_node(ptr->name, PACKAGE);
|
1995-10-16 07:31:11 +00:00
|
|
|
p->desc = ptr->comment;
|
1995-10-07 11:55:37 +00:00
|
|
|
p->data = ptr;
|
|
|
|
p->next = q->kids;
|
|
|
|
q->kids = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
copy_to_sep(char *to, char *from, int sep)
|
|
|
|
{
|
|
|
|
char *tok;
|
|
|
|
|
|
|
|
tok = strchr(from, sep);
|
|
|
|
if (!tok) {
|
|
|
|
fprintf(stderr, "missing '%c' token.\n", sep);
|
|
|
|
*to = '\0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*tok = '\0';
|
|
|
|
strcpy(to, from);
|
|
|
|
return tok + 1 - from;
|
|
|
|
}
|
|
|
|
|
1995-10-16 09:25:22 +00:00
|
|
|
static int
|
|
|
|
readline(int fd, char *buf, int max)
|
|
|
|
{
|
|
|
|
int rv, i = 0;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
while ((rv = read(fd, &ch, 1)) == 1 && ch != '\n' && i < max)
|
|
|
|
buf[i++] = ch;
|
|
|
|
if (i < max)
|
|
|
|
buf[i] = '\0';
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1995-10-07 11:55:37 +00:00
|
|
|
int
|
1995-10-16 09:25:22 +00:00
|
|
|
index_parse(int fd, char *name, char *pathto, char *prefix, char *comment, char *descr, char *maint,
|
1995-10-07 11:55:37 +00:00
|
|
|
char *cats, char *keys)
|
|
|
|
{
|
|
|
|
char line[1024];
|
|
|
|
char *cp;
|
1995-10-16 09:25:22 +00:00
|
|
|
int i;
|
1995-10-07 11:55:37 +00:00
|
|
|
|
1995-10-16 09:25:22 +00:00
|
|
|
i = readline(fd, line, 1024);
|
|
|
|
if (i <= 0)
|
|
|
|
return EOF;
|
1995-10-07 11:55:37 +00:00
|
|
|
cp = line;
|
|
|
|
cp += copy_to_sep(name, cp, '|');
|
|
|
|
cp += copy_to_sep(pathto, cp, '|');
|
|
|
|
cp += copy_to_sep(prefix, cp, '|');
|
|
|
|
cp += copy_to_sep(comment, cp, '|');
|
|
|
|
cp += copy_to_sep(descr, cp, '|');
|
|
|
|
cp += copy_to_sep(maint, cp, '|');
|
|
|
|
cp += copy_to_sep(cats, cp, '|');
|
|
|
|
strcpy(keys, cp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-10-16 09:25:22 +00:00
|
|
|
index_get(char *fname, PkgNodePtr papa)
|
1995-10-07 11:55:37 +00:00
|
|
|
{
|
1995-10-16 09:25:22 +00:00
|
|
|
int i, fd;
|
1995-10-07 11:55:37 +00:00
|
|
|
|
1995-10-16 09:25:22 +00:00
|
|
|
fd = open(fname, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
1995-10-07 11:55:37 +00:00
|
|
|
fprintf(stderr, "Unable to open index file `%s' for reading.\n", fname);
|
|
|
|
i = -1;
|
|
|
|
}
|
1995-10-16 09:25:22 +00:00
|
|
|
else
|
|
|
|
i = index_read(fd, papa);
|
|
|
|
close(fd);
|
1995-10-07 11:55:37 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-10-16 09:25:22 +00:00
|
|
|
index_read(int fd, PkgNodePtr papa)
|
1995-10-07 11:55:37 +00:00
|
|
|
{
|
|
|
|
char name[127], pathto[255], prefix[255], comment[255], descr[127], maint[127], cats[511], keys[511];
|
|
|
|
|
1995-10-16 09:25:22 +00:00
|
|
|
while (!index_parse(fd, name, pathto, prefix, comment, descr, maint, cats, keys)) {
|
1995-10-07 11:55:37 +00:00
|
|
|
char *cp, *cp2, tmp[511];
|
|
|
|
IndexEntryPtr idx;
|
|
|
|
|
|
|
|
idx = new_index(name, pathto, prefix, comment, descr, maint);
|
|
|
|
/* For now, we only add things to menus if they're in categories. Keywords are ignored */
|
|
|
|
cp = strcpy(tmp, cats);
|
|
|
|
while ((cp2 = strchr(cp, ' ')) != NULL) {
|
|
|
|
*cp2 = '\0';
|
|
|
|
index_register(papa, cp, idx);
|
|
|
|
cp = cp2 + 1;
|
|
|
|
}
|
|
|
|
index_register(papa, cp, idx);
|
|
|
|
|
|
|
|
/* Add to special "All" category */
|
|
|
|
index_register(papa, "All", idx);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
index_init(PkgNodePtr top, PkgNodePtr plist)
|
|
|
|
{
|
|
|
|
top->next = top->kids = NULL;
|
|
|
|
top->name = "Package Selection";
|
|
|
|
top->type = PLACE;
|
|
|
|
top->desc = fetch_desc(top->name);
|
|
|
|
|
|
|
|
plist->next = plist->kids = NULL;
|
|
|
|
plist->name = "Package Targets";
|
|
|
|
plist->type = PLACE;
|
|
|
|
plist->desc = fetch_desc(plist->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
index_entry_free(IndexEntryPtr top)
|
|
|
|
{
|
|
|
|
safe_free(top->name);
|
|
|
|
safe_free(top->path);
|
|
|
|
safe_free(top->prefix);
|
|
|
|
safe_free(top->comment);
|
|
|
|
safe_free(top->descrfile);
|
|
|
|
safe_free(top->maintainer);
|
|
|
|
free(top);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
index_node_free(PkgNodePtr top, PkgNodePtr plist)
|
|
|
|
{
|
|
|
|
PkgNodePtr tmp;
|
|
|
|
|
|
|
|
tmp = plist;
|
|
|
|
while (tmp) {
|
|
|
|
PkgNodePtr tmp2 = tmp->next;
|
|
|
|
|
|
|
|
safe_free(tmp);
|
|
|
|
tmp = tmp2;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = top;
|
|
|
|
while (tmp) {
|
|
|
|
free(tmp->name);
|
|
|
|
if (tmp->type == PACKAGE && tmp->data)
|
|
|
|
index_entry_free((IndexEntryPtr)tmp->data);
|
|
|
|
if (tmp->kids)
|
|
|
|
index_node_free(tmp->kids, NULL);
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
index_print(PkgNodePtr top, int level)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while (top) {
|
|
|
|
for (i = 0; i < level; i++) putchar('\t');
|
|
|
|
printf("name [%s]: %s\n", top->type == PLACE ? "place" : "package", top->name);
|
|
|
|
for (i = 0; i < level; i++) putchar('\t');
|
|
|
|
printf("desc: %s\n", top->desc);
|
|
|
|
if (top->kids)
|
|
|
|
index_print(top->kids, level + 1);
|
|
|
|
top = top->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Swap one node for another */
|
|
|
|
static void
|
|
|
|
swap_nodes(PkgNodePtr a, PkgNodePtr b)
|
|
|
|
{
|
|
|
|
PkgNode tmp;
|
|
|
|
|
|
|
|
tmp = *a;
|
|
|
|
*a = *b;
|
|
|
|
a->next = tmp.next;
|
|
|
|
tmp.next = b->next;
|
|
|
|
*b = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use a disgustingly simplistic bubble sort to put our lists in order */
|
|
|
|
void
|
|
|
|
index_sort(PkgNodePtr top)
|
|
|
|
{
|
|
|
|
PkgNodePtr p, q;
|
|
|
|
|
|
|
|
/* Sort everything at the top level */
|
|
|
|
p = top->kids;
|
|
|
|
while (p) {
|
|
|
|
q = top->kids;
|
|
|
|
while (q) {
|
|
|
|
if (q->next && strcmp(q->name, q->next->name) > 0)
|
|
|
|
swap_nodes(q, q->next);
|
|
|
|
q = q->next;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now sub-sort everything n levels down */
|
|
|
|
p = top->kids;
|
|
|
|
while (p) {
|
|
|
|
if (p->kids)
|
|
|
|
index_sort(p);
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-10-15 04:37:07 +00:00
|
|
|
/*
|
|
|
|
* No, we don't free n because someone else is still pointing at it.
|
|
|
|
* It's just clone linked from another location, which we're adjusting.
|
|
|
|
*/
|
1995-10-07 11:55:37 +00:00
|
|
|
void
|
|
|
|
index_delete(PkgNodePtr n)
|
|
|
|
{
|
|
|
|
if (n->next)
|
|
|
|
*n = *(n->next);
|
|
|
|
else /* Kludgy end sentinal */
|
|
|
|
n->name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PkgNodePtr
|
|
|
|
index_search(PkgNodePtr top, char *str, PkgNodePtr *tp)
|
|
|
|
{
|
|
|
|
PkgNodePtr p, sp;
|
|
|
|
|
|
|
|
for (p = top->kids; p && p->name; p = p->next) {
|
|
|
|
/* Subtract out the All category from searches */
|
|
|
|
if (!strcmp(p->name, "All"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If tp == NULL, we're looking for an exact package match */
|
|
|
|
if (!tp && !strcmp(p->name, str))
|
|
|
|
return p;
|
|
|
|
|
|
|
|
/* If tp, we're looking for both a package and a pointer to the place it's in */
|
|
|
|
if (tp && strstr(p->name, str)) {
|
|
|
|
*tp = top;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The usual recursion-out-of-laziness ploy */
|
|
|
|
if (p->kids)
|
|
|
|
if ((sp = index_search(p, str, tp)) != NULL)
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
if (p && !p->name)
|
|
|
|
p = NULL;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
1995-10-14 19:13:35 +00:00
|
|
|
/* Work function for seeing if name x is in result string y */
|
|
|
|
static Boolean
|
|
|
|
is_selected_in(char *name, char *result)
|
|
|
|
{
|
1995-10-15 17:22:24 +00:00
|
|
|
Boolean ret = FALSE;
|
|
|
|
|
|
|
|
while (*result) {
|
1995-10-14 19:13:35 +00:00
|
|
|
char *cp;
|
|
|
|
|
|
|
|
cp = index(result, '\n');
|
1995-10-15 17:22:24 +00:00
|
|
|
if (!cp) {
|
|
|
|
ret = !strcmp(name, result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
1995-10-16 15:14:28 +00:00
|
|
|
ret = !strncmp(name, result, cp - result - 1);
|
1995-10-15 17:22:24 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result = cp + 1;
|
1995-10-14 19:13:35 +00:00
|
|
|
}
|
1995-10-15 17:22:24 +00:00
|
|
|
return ret;
|
1995-10-14 19:13:35 +00:00
|
|
|
}
|
|
|
|
|
1995-10-07 11:55:37 +00:00
|
|
|
int
|
|
|
|
index_menu(PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll)
|
|
|
|
{
|
|
|
|
int n, rval;
|
|
|
|
int curr, max;
|
|
|
|
PkgNodePtr sp, kp;
|
|
|
|
char **nitems;
|
|
|
|
char result[127];
|
1995-10-14 19:13:35 +00:00
|
|
|
Boolean hasPackages;
|
1995-10-07 11:55:37 +00:00
|
|
|
|
1995-10-14 19:13:35 +00:00
|
|
|
curr = max = 0;
|
|
|
|
hasPackages = FALSE;
|
1995-10-07 11:55:37 +00:00
|
|
|
nitems = NULL;
|
1995-10-14 19:13:35 +00:00
|
|
|
|
|
|
|
n = 0;
|
|
|
|
kp = top->kids;
|
|
|
|
/* Figure out if this menu is full of "leaves" or "branches" */
|
1995-10-07 11:55:37 +00:00
|
|
|
while (kp && kp->name) {
|
|
|
|
++n;
|
1995-10-14 19:13:35 +00:00
|
|
|
if (kp->type == PACKAGE) {
|
|
|
|
hasPackages = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
1995-10-07 11:55:37 +00:00
|
|
|
kp = kp->next;
|
|
|
|
}
|
|
|
|
if (!n) {
|
|
|
|
msgConfirm("The %s menu is empty.", top->name);
|
|
|
|
return RET_DONE;
|
|
|
|
}
|
1995-10-14 19:13:35 +00:00
|
|
|
|
1995-10-07 11:55:37 +00:00
|
|
|
dialog_clear();
|
|
|
|
while (1) {
|
1995-10-14 19:13:35 +00:00
|
|
|
n = 0;
|
|
|
|
kp = top->kids;
|
|
|
|
if (!hasPackages && kp && kp->name && plist) {
|
|
|
|
nitems = item_add_pair(nitems, "UP", ".. RETURN TO PREVIOUS MENU ..", &curr, &max);
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
while (kp && kp->name) {
|
1995-10-16 07:31:11 +00:00
|
|
|
char name[10], desc[62];
|
|
|
|
|
|
|
|
strchop(name, kp->name, 8);
|
|
|
|
strchop(desc, kp->desc, 60);
|
|
|
|
nitems = item_add_pair(nitems, name, desc, &curr, &max);
|
1995-10-14 19:13:35 +00:00
|
|
|
if (hasPackages) {
|
|
|
|
if (kp->type == PACKAGE)
|
|
|
|
nitems = item_add(nitems, index_search(plist, kp->name, NULL) ? "ON" : "OFF", &curr, &max);
|
|
|
|
else
|
|
|
|
nitems = item_add(nitems, "OFF", &curr, &max);
|
|
|
|
}
|
|
|
|
++n;
|
|
|
|
kp = kp->next;
|
|
|
|
}
|
|
|
|
nitems = item_add(nitems, NULL, &curr, &max);
|
|
|
|
|
|
|
|
if (hasPackages)
|
|
|
|
rval = dialog_checklist(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, n,
|
|
|
|
(unsigned char **)nitems, result);
|
|
|
|
else /* It's a categories menu */
|
|
|
|
rval = dialog_menu(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, n,
|
|
|
|
(unsigned char **)nitems, result, pos, scroll);
|
|
|
|
items_free(nitems, &curr, &max);
|
|
|
|
if (!rval && plist && strcmp(result, "UP")) {
|
1995-10-07 11:55:37 +00:00
|
|
|
kp = top->kids;
|
|
|
|
while (kp) {
|
1995-10-14 19:13:35 +00:00
|
|
|
if (kp->type == PACKAGE) {
|
|
|
|
sp = index_search(plist, kp->name, NULL);
|
|
|
|
if (is_selected_in(kp->name, result)) {
|
|
|
|
if (!sp) {
|
1995-10-07 11:55:37 +00:00
|
|
|
PkgNodePtr n = (PkgNodePtr)malloc(sizeof(PkgNode));
|
|
|
|
|
|
|
|
if (n) {
|
|
|
|
*n = *kp;
|
|
|
|
n->next = plist->kids;
|
|
|
|
plist->kids = n;
|
|
|
|
standout();
|
|
|
|
mvprintw(23, 0, "Adding package %s to selection list\n", kp->name);
|
|
|
|
standend();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-10-14 19:13:35 +00:00
|
|
|
else if (sp) {
|
|
|
|
standout();
|
|
|
|
mvprintw(23, 0, "Deleting package %s from selection list\n", kp->name);
|
|
|
|
standend();
|
|
|
|
refresh();
|
|
|
|
index_delete(sp);
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
1995-10-14 19:13:35 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp(kp->name, result)) { /* Not a package, must be a directory */
|
|
|
|
int p, s;
|
|
|
|
|
|
|
|
p = s = 0;
|
|
|
|
index_menu(kp, plist, &p, &s);
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
|
|
|
kp = kp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rval == -1) {
|
|
|
|
static char *cp;
|
|
|
|
PkgNodePtr menu;
|
|
|
|
|
|
|
|
/* Search */
|
|
|
|
if ((cp = msgGetInput(cp, "Search by package name. Please enter search string:")) != NULL) {
|
|
|
|
PkgNodePtr p = index_search(top, cp, &menu);
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
int pos, scroll;
|
|
|
|
|
|
|
|
/* These need to be set to point at the found item, actually. Hmmm! */
|
|
|
|
pos = scroll = 0;
|
|
|
|
index_menu(menu, plist, &pos, &scroll);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
msgConfirm("Search string: %s yielded no hits.", cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dialog_clear();
|
|
|
|
return rval ? RET_FAIL : RET_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-10-15 04:37:07 +00:00
|
|
|
int
|
1995-10-07 11:55:37 +00:00
|
|
|
index_extract(Device *dev, PkgNodePtr plist)
|
|
|
|
{
|
|
|
|
PkgNodePtr tmp;
|
|
|
|
|
|
|
|
tmp = plist->kids;
|
|
|
|
while (tmp) {
|
1995-10-15 12:41:09 +00:00
|
|
|
if (package_extract(dev, tmp->name) != RET_SUCCESS) {
|
1995-10-15 04:37:07 +00:00
|
|
|
if (optionIsSet(OPT_NO_CONFIRM))
|
1995-10-15 12:41:09 +00:00
|
|
|
msgNotify("Unable to locate package %s..", tmp->name);
|
1995-10-15 04:37:07 +00:00
|
|
|
else
|
1995-10-15 12:41:09 +00:00
|
|
|
msgConfirm("Unable to locate package %s..", tmp->name);
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
1995-10-15 04:37:07 +00:00
|
|
|
return RET_SUCCESS;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|