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.
|
|
|
|
*
|
1996-04-13 13:32:15 +00:00
|
|
|
* $Id: index.c,v 1.22 1996/03/21 09:30:11 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.
|
|
|
|
*
|
|
|
|
* 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
|
1995-10-20 20:10:49 +00:00
|
|
|
#define _MAX_DESC 62
|
1995-10-07 11:55:37 +00:00
|
|
|
|
1996-03-21 09:30:18 +00:00
|
|
|
static int index_extract_one(Device *dev, PkgNodePtr top, PkgNodePtr who, Boolean depended);
|
1996-03-18 15:28:10 +00:00
|
|
|
|
1995-10-07 11:55:37 +00:00
|
|
|
/* Smarter strdup */
|
|
|
|
inline char *
|
|
|
|
_strdup(char *ptr)
|
|
|
|
{
|
1995-10-20 20:10:49 +00:00
|
|
|
return ptr ? strdup(ptr) : NULL;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *descrs[] = {
|
1995-10-20 20:10:49 +00:00
|
|
|
"Package Selection", "To mark a package or select a category, move to it and press SPACE.\n"
|
1996-04-13 13:32:15 +00:00
|
|
|
"To unmark a package, press SPACE again. To go to a previous menu, select the Cancel\n"
|
|
|
|
"button. To search for a package by name, press ESC. To finally extract packages, you\n"
|
|
|
|
"should Cancel all the way out of any submenus and this top menu.",
|
1995-10-14 19:13:35 +00:00
|
|
|
"Package Targets", "These are the packages you've selected for extraction.\n\n"
|
1995-11-12 20:47:15 +00:00
|
|
|
"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.",
|
1996-03-18 15:28:10 +00:00
|
|
|
"misc", "Miscellaneous utilities.",
|
1995-10-07 11:55:37 +00:00
|
|
|
"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.",
|
1996-03-18 15:28:10 +00:00
|
|
|
"www", "WEB utilities (browers, HTTP servers, etc).",
|
1995-10-07 11:55:37 +00:00
|
|
|
"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)
|
|
|
|
{
|
1995-10-20 07:02:53 +00:00
|
|
|
PkgNodePtr tmp = safe_malloc(sizeof(PkgNode));
|
1995-10-07 11:55:37 +00:00
|
|
|
|
|
|
|
tmp->name = _strdup(name);
|
|
|
|
tmp->type = type;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IndexEntryPtr
|
1996-03-18 15:28:10 +00:00
|
|
|
new_index(char *name, char *pathto, char *prefix, char *comment, char *descr, char *maint, char *deps)
|
1995-10-07 11:55:37 +00:00
|
|
|
{
|
1995-10-20 07:02:53 +00:00
|
|
|
IndexEntryPtr tmp = safe_malloc(sizeof(IndexEntry));
|
1995-10-07 11:55:37 +00:00
|
|
|
|
|
|
|
tmp->name = _strdup(name);
|
|
|
|
tmp->path = _strdup(pathto);
|
|
|
|
tmp->prefix = _strdup(prefix);
|
|
|
|
tmp->comment = _strdup(comment);
|
|
|
|
tmp->descrfile = _strdup(descr);
|
|
|
|
tmp->maintainer = _strdup(maint);
|
1996-03-18 15:28:10 +00:00
|
|
|
tmp->deps = _strdup(deps);
|
1995-10-07 11:55:37 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
index_register(PkgNodePtr top, char *where, IndexEntryPtr ptr)
|
|
|
|
{
|
|
|
|
PkgNodePtr p, q;
|
|
|
|
|
1995-10-20 20:10:49 +00:00
|
|
|
for (q = NULL, p = top->kids; p; p = p->next) {
|
1995-10-07 11:55:37 +00:00
|
|
|
if (!strcmp(p->name, where)) {
|
|
|
|
q = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
*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
|
1996-03-18 15:28:10 +00:00
|
|
|
index_parse(int fd, char *name, char *pathto, char *prefix, char *comment, char *descr, char *maint, char *cats, char *deps)
|
1995-10-07 11:55:37 +00:00
|
|
|
{
|
|
|
|
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, '|');
|
1996-03-18 15:28:10 +00:00
|
|
|
(void)copy_to_sep(deps, cp, '|');
|
|
|
|
/* We're not actually interested in any of the other fields */
|
1995-10-07 11:55:37 +00:00
|
|
|
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
|
|
|
{
|
1996-03-18 15:28:10 +00:00
|
|
|
char name[127], pathto[255], prefix[255], comment[255], descr[127], maint[127], cats[511], deps[511];
|
1995-10-07 11:55:37 +00:00
|
|
|
|
1996-03-18 15:28:10 +00:00
|
|
|
while (index_parse(fd, name, pathto, prefix, comment, descr, maint, cats, deps) != EOF) {
|
1995-10-07 11:55:37 +00:00
|
|
|
char *cp, *cp2, tmp[511];
|
|
|
|
IndexEntryPtr idx;
|
|
|
|
|
1996-03-18 15:28:10 +00:00
|
|
|
idx = new_index(name, pathto, prefix, comment, descr, maint, deps);
|
1995-10-07 11:55:37 +00:00
|
|
|
/* For now, we only add things to menus if they're in categories. Keywords are ignored */
|
1995-10-20 20:10:49 +00:00
|
|
|
for (cp = strcpy(tmp, cats); (cp2 = strchr(cp, ' ')) != NULL; cp = cp2 + 1) {
|
1995-10-07 11:55:37 +00:00
|
|
|
*cp2 = '\0';
|
|
|
|
index_register(papa, cp, idx);
|
|
|
|
}
|
|
|
|
index_register(papa, cp, idx);
|
|
|
|
|
|
|
|
/* Add to special "All" category */
|
|
|
|
index_register(papa, "All", idx);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
index_init(PkgNodePtr top, PkgNodePtr plist)
|
|
|
|
{
|
1996-03-21 09:30:18 +00:00
|
|
|
if (top) {
|
|
|
|
top->next = top->kids = NULL;
|
|
|
|
top->name = "Package Selection";
|
|
|
|
top->type = PLACE;
|
|
|
|
top->desc = fetch_desc(top->name);
|
|
|
|
top->data = NULL;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
1996-03-21 09:30:18 +00:00
|
|
|
if (plist) {
|
|
|
|
plist->next = plist->kids = NULL;
|
|
|
|
plist->name = "Package Targets";
|
|
|
|
plist->type = PLACE;
|
|
|
|
plist->desc = fetch_desc(plist->name);
|
|
|
|
plist->data = NULL;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
|
|
|
}
|
1996-03-21 09:30:18 +00:00
|
|
|
|
1995-10-07 11:55:37 +00:00
|
|
|
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 */
|
1995-10-20 20:10:49 +00:00
|
|
|
for (p = top->kids; p; p = p->next) {
|
|
|
|
for (q = top->kids; q; q = q->next) {
|
1995-10-07 11:55:37 +00:00
|
|
|
if (q->next && strcmp(q->name, q->next->name) > 0)
|
|
|
|
swap_nodes(q, q->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now sub-sort everything n levels down */
|
1995-10-20 20:10:49 +00:00
|
|
|
|
|
|
|
for (p = top->kids; p; p = p->next) {
|
1995-10-07 11:55:37 +00:00
|
|
|
if (p->kids)
|
|
|
|
index_sort(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-04-13 13:32:15 +00:00
|
|
|
/* Delete an entry out of the index */
|
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;
|
|
|
|
}
|
|
|
|
|
1996-04-13 13:32:15 +00:00
|
|
|
/*
|
|
|
|
* Search for a given node by name, returning the category in if
|
|
|
|
* tp is non-NULL.
|
|
|
|
*/
|
1995-10-07 11:55:37 +00:00
|
|
|
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 */
|
1996-03-21 09:30:18 +00:00
|
|
|
if (tp && !strcmp(p->name, str)) {
|
1995-10-07 11:55:37 +00:00
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
1996-04-13 13:32:15 +00:00
|
|
|
int
|
|
|
|
pkg_checked(dialogMenuItem *self)
|
1995-10-14 19:13:35 +00:00
|
|
|
{
|
1996-04-13 13:32:15 +00:00
|
|
|
PkgNodePtr kp = self->data, plist = (PkgNodePtr)self->aux;
|
1995-10-15 17:22:24 +00:00
|
|
|
|
1996-04-13 13:32:15 +00:00
|
|
|
if (kp->type == PACKAGE && plist)
|
|
|
|
return index_search(plist, kp->name, NULL) ? TRUE : FALSE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
1995-10-14 19:13:35 +00:00
|
|
|
|
1996-04-13 13:32:15 +00:00
|
|
|
int
|
|
|
|
pkg_fire(dialogMenuItem *self)
|
|
|
|
{
|
|
|
|
PkgNodePtr sp, kp = self->data, plist = (PkgNodePtr)self->aux;
|
|
|
|
|
|
|
|
if (!plist)
|
|
|
|
return DITEM_FAILURE;
|
|
|
|
if (kp->type == PACKAGE) {
|
|
|
|
sp = index_search(plist, kp->name, NULL);
|
|
|
|
/* Not already selected? */
|
|
|
|
if (!sp) {
|
|
|
|
PkgNodePtr np = (PkgNodePtr)safe_malloc(sizeof(PkgNode));
|
|
|
|
|
|
|
|
*np = *kp;
|
|
|
|
np->next = plist->kids;
|
|
|
|
plist->kids = np;
|
|
|
|
msgInfo("%s added to selection list", kp->name);
|
1995-10-15 17:22:24 +00:00
|
|
|
}
|
1996-04-13 13:32:15 +00:00
|
|
|
else if (sp) {
|
|
|
|
msgInfo("Removing %s from selection list", kp->name);
|
|
|
|
index_delete(sp);
|
1995-10-15 17:22:24 +00:00
|
|
|
}
|
1995-10-14 19:13:35 +00:00
|
|
|
}
|
1996-04-13 13:32:15 +00:00
|
|
|
else { /* Not a package, must be a directory */
|
|
|
|
int p, s;
|
|
|
|
|
|
|
|
p = s = 0;
|
|
|
|
index_menu(kp, plist, &p, &s);
|
|
|
|
}
|
|
|
|
return DITEM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pkg_selected(dialogMenuItem *self, int is_selected)
|
|
|
|
{
|
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)
|
|
|
|
{
|
1995-10-20 20:10:49 +00:00
|
|
|
int n, rval, maxname;
|
1995-10-07 11:55:37 +00:00
|
|
|
int curr, max;
|
1996-04-13 13:32:15 +00:00
|
|
|
PkgNodePtr kp;
|
|
|
|
dialogMenuItem *nitems;
|
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
|
|
|
hasPackages = FALSE;
|
1995-10-07 11:55:37 +00:00
|
|
|
nitems = NULL;
|
1995-10-14 19:13:35 +00:00
|
|
|
|
1995-10-20 20:10:49 +00:00
|
|
|
n = maxname = 0;
|
1995-10-14 19:13:35 +00:00
|
|
|
/* Figure out if this menu is full of "leaves" or "branches" */
|
1995-10-20 20:10:49 +00:00
|
|
|
for (kp = top->kids; kp && kp->name; kp = kp->next) {
|
|
|
|
int len;
|
|
|
|
|
1995-10-07 11:55:37 +00:00
|
|
|
++n;
|
1995-10-20 20:10:49 +00:00
|
|
|
if (kp->type == PACKAGE && plist) {
|
1995-10-14 19:13:35 +00:00
|
|
|
hasPackages = TRUE;
|
1995-10-20 20:10:49 +00:00
|
|
|
if ((len = strlen(kp->name)) > maxname)
|
|
|
|
maxname = len;
|
1995-10-14 19:13:35 +00:00
|
|
|
}
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
1995-10-20 20:10:49 +00:00
|
|
|
if (!n && plist) {
|
1995-10-22 17:18:36 +00:00
|
|
|
dialog_clear();
|
1995-10-07 11:55:37 +00:00
|
|
|
msgConfirm("The %s menu is empty.", top->name);
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_LEAVE_MENU;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
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;
|
1995-11-06 12:49:27 +00:00
|
|
|
curr = max = 0;
|
1995-10-14 19:13:35 +00:00
|
|
|
kp = top->kids;
|
|
|
|
while (kp && kp->name) {
|
1996-04-13 13:32:15 +00:00
|
|
|
char buf[256];
|
|
|
|
|
1995-10-20 20:10:49 +00:00
|
|
|
/* Brutally adjust description to fit in menu */
|
1996-04-13 13:32:15 +00:00
|
|
|
strcpy(buf, kp->desc);
|
|
|
|
if (strlen(buf) > (_MAX_DESC - maxname))
|
|
|
|
buf[_MAX_DESC - maxname] = '\0';
|
|
|
|
nitems = item_add(nitems, kp->name, buf, pkg_checked, pkg_fire, pkg_selected, kp, (int)plist, &curr, &max);
|
1995-10-14 19:13:35 +00:00
|
|
|
++n;
|
|
|
|
kp = kp->next;
|
|
|
|
}
|
1996-04-13 13:32:15 +00:00
|
|
|
/* NULL delimiter so item_free() knows when to stop later */
|
|
|
|
nitems = item_add(nitems, NULL, NULL, NULL, NULL, NULL, NULL, 0, &curr, &max);
|
1995-10-14 19:13:35 +00:00
|
|
|
|
|
|
|
if (hasPackages)
|
1996-04-13 13:32:15 +00:00
|
|
|
rval = dialog_checklist(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, -n, nitems, NULL);
|
1995-10-14 19:13:35 +00:00
|
|
|
else /* It's a categories menu */
|
1996-04-13 13:32:15 +00:00
|
|
|
rval = dialog_menu(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, -n,
|
|
|
|
nitems, NULL, pos, scroll);
|
|
|
|
if (rval == -1 && plist) {
|
1995-10-07 11:55:37 +00:00
|
|
|
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);
|
|
|
|
}
|
1995-10-22 17:18:36 +00:00
|
|
|
else {
|
1995-10-07 11:55:37 +00:00
|
|
|
msgConfirm("Search string: %s yielded no hits.", cp);
|
1995-10-22 17:18:36 +00:00
|
|
|
}
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
1996-04-13 13:32:15 +00:00
|
|
|
continue;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
1996-04-13 13:32:15 +00:00
|
|
|
dialog_clear();
|
|
|
|
items_free(nitems, &curr, &max);
|
|
|
|
return rval ? DITEM_FAILURE : DITEM_SUCCESS;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-10-15 04:37:07 +00:00
|
|
|
int
|
1996-03-18 15:28:10 +00:00
|
|
|
index_extract(Device *dev, PkgNodePtr top, PkgNodePtr plist)
|
1995-10-07 11:55:37 +00:00
|
|
|
{
|
|
|
|
PkgNodePtr tmp;
|
1996-04-13 13:32:15 +00:00
|
|
|
int status = DITEM_SUCCESS;
|
1995-10-07 11:55:37 +00:00
|
|
|
|
1996-03-18 15:28:10 +00:00
|
|
|
for (tmp = plist->kids; tmp; tmp = tmp->next)
|
1996-03-21 09:30:18 +00:00
|
|
|
status = index_extract_one(dev, top, tmp, FALSE);
|
1996-03-18 15:28:10 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1996-03-21 09:30:18 +00:00
|
|
|
index_extract_one(Device *dev, PkgNodePtr top, PkgNodePtr who, Boolean depended)
|
1996-03-18 15:28:10 +00:00
|
|
|
{
|
1996-04-13 13:32:15 +00:00
|
|
|
int status = DITEM_SUCCESS;
|
1996-03-18 15:28:10 +00:00
|
|
|
PkgNodePtr tmp2;
|
1996-03-21 09:30:18 +00:00
|
|
|
IndexEntryPtr id = who->data;
|
1996-03-18 15:28:10 +00:00
|
|
|
|
1996-03-21 09:30:18 +00:00
|
|
|
if (id && id->deps && strlen(id->deps)) {
|
1996-03-18 15:28:10 +00:00
|
|
|
char t[1024], *cp, *cp2;
|
|
|
|
|
1996-03-21 09:30:18 +00:00
|
|
|
strcpy(t, id->deps);
|
1996-03-18 15:28:10 +00:00
|
|
|
cp = t;
|
1996-04-13 13:32:15 +00:00
|
|
|
while (cp && status == DITEM_SUCCESS) {
|
1996-03-18 15:28:10 +00:00
|
|
|
if ((cp2 = index(cp, ' ')) != NULL)
|
|
|
|
*cp2 = '\0';
|
1996-03-21 09:30:18 +00:00
|
|
|
if ((tmp2 = index_search(top, cp, NULL)) != NULL) {
|
|
|
|
status = index_extract_one(dev, top, tmp2, TRUE);
|
1996-04-13 13:32:15 +00:00
|
|
|
if (status != DITEM_SUCCESS) {
|
1996-03-21 09:30:18 +00:00
|
|
|
if (variable_get(VAR_NO_CONFIRM))
|
|
|
|
msgNotify("Loading of dependant package %s failed", cp);
|
|
|
|
else
|
|
|
|
msgConfirm("Loading of dependant package %s failed", cp);
|
1996-03-18 15:28:10 +00:00
|
|
|
}
|
|
|
|
if (cp2)
|
|
|
|
cp = cp2 + 1;
|
|
|
|
else
|
|
|
|
cp = NULL;
|
|
|
|
}
|
|
|
|
}
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|
1996-03-18 15:28:10 +00:00
|
|
|
/* Done with the deps? Load the real m'coy */
|
1996-04-13 13:32:15 +00:00
|
|
|
if (status == DITEM_SUCCESS)
|
1996-03-21 09:30:18 +00:00
|
|
|
status = package_extract(dev, who->name, depended);
|
1995-10-20 20:10:49 +00:00
|
|
|
return status;
|
1995-10-07 11:55:37 +00:00
|
|
|
}
|