Browse Source

Use di_pkg_parse from libd-i

r939
keep-around/c8703c509368e1805e513d61f98a9d17d2cdd9cc
Martin Sjögren 20 years ago
parent
commit
f4d411def7
  1. 4
      Makefile
  2. 2
      debian/changelog
  3. 2
      debian/control
  4. 25
      main-menu.h
  5. 133
      status.c
  6. 9
      tree.c

4
Makefile

@ -1,10 +1,10 @@
CFLAGS=-Wall -g -D_GNU_SOURCE
OBJS=$(subst .c,.o,$(wildcard *.c))
BIN=main-menu
LIBS=-ldebconf
LIBS=-ldebconf -ldebian-installer
ifdef DEBUG
CFLAGS:=$(CFLAGS) -DDODEBUG
CFLAGS:=$(CFLAGS) -DDODEBUG=1
endif
all: $(BIN)

2
debian/changelog

@ -5,6 +5,8 @@ main-menu (0.014) unstable; urgency=low
* Apply patch from Martin Sjögren to use asprintf.
* Add Swedish debconf template.
* Add Brazilian Portuguese debconf template.
Martin Sjögren
- Use di_pkg_parse from libd-i
-- Tollef Fog Heen <tfheen@debian.org> Fri, 30 Aug 2002 17:09:38 +0200

2
debian/control

@ -2,7 +2,7 @@ Source: main-menu
Section: debian-installer
Priority: standard
Maintainer: Joey Hess <joeyh@debian.org>
Build-Depends: debhelper (>= 2.1.18), dpkg-dev (>= 1.7.0), libcdebconf-dev, dpkg-dev (>= 1.9)
Build-Depends: debhelper (>= 2.1.18), dpkg-dev (>= 1.7.0), libcdebconf-dev, dpkg-dev (>= 1.9), libdebian-installer1-dev (>= 0.04)
Standards-Version: 3.5.6.1
Package: main-menu

25
main-menu.h

@ -13,36 +13,15 @@
#define DPKGDIR "/var/lib/dpkg/"
#define STATUSFILE DPKGDIR "status"
#define DEPENDSMAX 64 /* maximum number of depends we can handle */
#define MAIN_MENU "debian-installer/main-menu"
#define DPKG_CONFIGURE_COMMAND "/usr/bin/udpkg --configure"
typedef enum { unpacked, installed, half_configured, other } package_status;
struct language_description
{
char *language;
char *description;
char *extended_description;
struct language_description *next;
};
struct package_t {
char *package;
int installer_menu_item;
char *description; /* short only, and only for menu items */
char *depends[DEPENDSMAX];
package_status status;
int processed;
struct language_description *localized_descriptions;
struct package_t *next;
};
#include <debian-installer.h>
/* status.c */
struct package_t *status_read(void);
/* tree.c */
struct package_t *tree_find(char *);
struct package_t *tree_add(const char *);
struct package_t *tree_add(struct package_t *);
void tree_clear();

133
status.c

@ -15,10 +15,8 @@
*/
struct package_t *status_read(void) {
FILE *f;
char *b, buf[BUFSIZE], *lang_code;
int i;
struct package_t *found, *newp, *p = 0;
struct language_description *langdesc;
struct package_t *found, *plist, *p;
tree_clear();
@ -26,101 +24,36 @@ struct package_t *status_read(void) {
perror(STATUSFILE);
return 0;
}
while (fgets(buf, BUFSIZE, f) && !feof(f)) {
buf[strlen(buf)-1] = 0;
if (strstr(buf, "Package: ") == buf) {
newp = tree_add(buf + 9);
newp->next = p;
p = newp;
}
else if (strstr(buf, "installer-menu-item: ") == buf) {
p->installer_menu_item = atoi(buf + 21);
}
else if (strstr(buf, "Status: ") == buf) {
if (strstr(buf, " unpacked")) {
p->status = unpacked;
}
else if (strstr(buf, " half-configured")) {
p->status = half_configured;
}
else if (strstr(buf, " installed")) {
p->status = installed;
}
else {
p->status = other;
}
}
else if (strstr(buf, "Description: ") == buf) {
/*
* If there is already a description, it must be
* the translated one, which we prefer to use if
* possible.
*/
if (! p->description)
p->description = strdup(buf+13);
}
else if (strstr(buf, "Description-") == buf &&
strlen(buf) >= 16 && buf[14] == ':') {
lang_code = (char *) malloc(3);
memcpy(lang_code, buf + 12, 2);
lang_code[2] = 0;
langdesc = malloc(sizeof (struct language_description));
memset(langdesc,0,sizeof(struct language_description));
langdesc->language = lang_code;
langdesc->description = strdup(buf+16);
if (p->localized_descriptions)
langdesc->next = p->localized_descriptions;
p->localized_descriptions = langdesc;
}
else if (strstr(buf, "Depends: ") == buf) {
/*
* Basic depends line parser. Can ignore versioning
* info since the depends are already satisfied.
*/
b=strdup(buf+9);
i = 0;
while (*b != 0 && *b != '\n') {
if (*b != ' ') {
if (*b == ',') {
*b = 0;
p->depends[++i] = 0;
}
else if (p->depends[i] == 0) {
p->depends[i] = b;
}
}
else {
*b = 0; /* eat the space... */
}
b++;
}
*b = 0;
p->depends[i+1] = 0;
}
else if (strstr(buf, "Provides: ") == buf) {
/*
* A provides causes a fake package to be made,
* that depends on the package that provides it. If
* the fake package already exists, just add the
* providing package to its dependancy list. This
* means that virtual packages are actually ANDed
* for the purposes of this program.
*/
if ((found = tree_find(buf + 10))) {
newp=found;
}
else {
newp = tree_add(buf + 10);
newp->next=p->next;
p->next=newp;
}
for (i=0; newp->depends[i] != 0; i++);
newp->depends[i] = p->package;
newp->depends[i+1] = 0;
}
}
fclose(f);
return p;
plist = di_pkg_parse(f);
fclose(f);
for (p = plist; p != NULL; p = p->next)
{
tree_add(p);
}
for (p = plist; p != NULL; p = p->next)
{
if (p->provides != NULL)
{
found = tree_find(p->provides);
if (found == NULL)
{
found = (struct package_t *)malloc(sizeof(struct package_t));
memset(found, 0, sizeof(struct package_t));
found->package = strdup(p->provides);
tree_add(found);
/* TODO: Do we want the virtual packages in the list
* or just the tree? */
found->next = plist;
plist = found;
}
for (i = 0; found->depends[i] != 0; i++)
;
found->depends[i] = p->package;
found->depends[i+1] = 0;
}
}
return plist;
}

9
tree.c

@ -29,13 +29,10 @@ struct package_t *tree_find(char *packagename) {
}
/*
* Adds a package to the tree. Just feed in the package's name; the
* struct to hold it is automatically created.
* Adds a package to the tree. Note that the structure is now created
* by e.g. di_pkg_parse.
*/
struct package_t *tree_add(const char *packagename) {
struct package_t *pkg=malloc(sizeof(struct package_t));
memset(pkg, 0, sizeof(struct package_t));
pkg->package = strdup(packagename);
struct package_t *tree_add(struct package_t *pkg) {
/*
* I should just be able to return tsearch's return code, but this
* makes my code fail horribly later on. I think tsearch has

Loading…
Cancel
Save