|
|
@ -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; |
|
|
|
} |
|
|
|