summaryrefslogtreecommitdiffstats
path: root/src/opk.c
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-28 21:38:39 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-04-28 21:38:39 (EDT)
commite8b9703043c49e49edd4d705b7ce198e92f0b79e (patch)
tree9f2cfd08cd4bc6bf8d33475965aa43977c39f9ca /src/opk.c
parent2b2d66c0e3d0f65cd56f0e3b3a3662ee05608558 (diff)
opk: Remove found members from list
Diffstat (limited to 'src/opk.c')
-rw-r--r--src/opk.c93
1 files changed, 62 insertions, 31 deletions
diff --git a/src/opk.c b/src/opk.c
index 3090add..8045b55 100644
--- a/src/opk.c
+++ b/src/opk.c
@@ -30,12 +30,13 @@
struct _opkg_opk_opk_seek_name {
const char *name;
- int found;
+ struct _opkg_opk_opk_seek_name *prev;
struct _opkg_opk_opk_seek_name *next;
};
struct opkg_opk_opk {
- struct _opkg_opk_opk_seek_name *print_control;
+ struct _opkg_opk_opk_seek_name *print_control_head;
+ struct _opkg_opk_opk_seek_name *print_control_tail;
int list_data;
FILE *file;
char file_buffer[8192];
@@ -56,7 +57,8 @@ opkg_opk_opk_init(void)
return NULL;
}
- opk->print_control = NULL;
+ opk->print_control_head = NULL;
+ opk->print_control_tail = NULL;
opk->list_data = 0;
opk->previously_printed = 0;
@@ -64,31 +66,39 @@ opkg_opk_opk_init(void)
}
static int
-_opkg_opk_opk_add_seek_name(struct _opkg_opk_opk_seek_name **names,
- const char *name)
+_opkg_opk_opk_add_seek_name(struct _opkg_opk_opk_seek_name **head,
+ struct _opkg_opk_opk_seek_name **tail, const char *name)
{
- struct _opkg_opk_opk_seek_name *seek_name;
+ struct _opkg_opk_opk_seek_name *new;
- seek_name = malloc(sizeof(*seek_name));
- if (seek_name == NULL) {
+ new = malloc(sizeof(*new));
+ if (new == NULL) {
return OPKG_OPK_ERROR;
}
if (name[0] == '.' && name[1] == '/') {
- seek_name->name = name + 2;
+ new->name = name + 2;
} else {
- seek_name->name = name;
+ new->name = name;
}
- seek_name->found = 0;
- seek_name->next = *names;
- *names = seek_name;
+ new->prev = *tail;
+ new->next = NULL;
+
+ if (*head == NULL) {
+ *head = new;
+ } else {
+ (*tail)->next = new;
+ }
+ *tail = new;
+
return OPKG_OPK_OK;
}
int
opkg_opk_opk_print_control(struct opkg_opk_opk *opk, const char *name)
{
- return _opkg_opk_opk_add_seek_name(&opk->print_control, name);
+ return _opkg_opk_opk_add_seek_name(&opk->print_control_head,
+ &opk->print_control_tail, name);
}
int
@@ -147,11 +157,11 @@ _opkg_opk_opk_free_inner(struct opkg_opk_opk *opk)
static int
_opkg_opk_opk_seek(struct opkg_opk_ustar *ustar,
- struct _opkg_opk_opk_seek_name *names)
+ struct _opkg_opk_opk_seek_name **head,
+ struct _opkg_opk_opk_seek_name **tail)
{
struct opkg_opk_ustar_member *member;
int found;
- int found_all;
struct _opkg_opk_opk_seek_name *seek_name;
for (;;) {
@@ -161,15 +171,23 @@ _opkg_opk_opk_seek(struct opkg_opk_ustar *ustar,
}
/* Check each requested name. */
- found = 0;
- found_all = 1;
- for (seek_name = names; seek_name != NULL;
+ found = 0;
+ for (seek_name = *head; seek_name != NULL;
seek_name = seek_name->next) {
- if (seek_name->found == 1) {
- continue; /* Previously found this member */
- }
if (strcmp(member->name, seek_name->name) == 0) {
- seek_name->found = 1;
+ if (seek_name->prev != NULL) {
+ seek_name->prev->next = seek_name->next;
+ } else {
+ /* This was the head. Update. */
+ *head = seek_name->next;
+ }
+ if (seek_name->next != NULL) {
+ seek_name->next->prev = seek_name->prev;
+ } else {
+ /* This was the tail. Update. */
+ *tail = seek_name->prev;
+ }
+ free(seek_name);
found = 1;
break;
}
@@ -177,15 +195,26 @@ _opkg_opk_opk_seek(struct opkg_opk_ustar *ustar,
strcmp(member->name + 2,
seek_name->name) == 0)
{
- seek_name->found = 1;
+ if (seek_name->prev != NULL) {
+ seek_name->prev->next = seek_name->next;
+ } else {
+ /* This was the head. Update. */
+ *head = seek_name->next;
+ }
+ if (seek_name->next != NULL) {
+ seek_name->next->prev = seek_name->prev;
+ } else {
+ /* This was the tail. Update. */
+ *tail = seek_name->prev;
+ }
+ free(seek_name);
found = 1;
break;
}
- found_all = 0;
}
free(member);
if (found == 1) {
- if (found_all == 1) {
+ if (*head == NULL) {
/* All requested members found */
return OPKG_OPK_END;
}
@@ -204,7 +233,7 @@ _opkg_opk_opk_read_control(struct opkg_opk_opk *opk)
int ret_seek;
int ret_read;
- if (opk->print_control == NULL) {
+ if (opk->print_control_head == NULL) {
/* No control files requested. */
return OPKG_OPK_OK;
}
@@ -214,7 +243,9 @@ _opkg_opk_opk_read_control(struct opkg_opk_opk *opk)
}
while ((ret_seek = _opkg_opk_opk_seek(opk->inner_ustar,
- opk->print_control)) != OPKG_OPK_ERROR)
+ &opk->print_control_head,
+ &opk->print_control_tail)) !=
+ OPKG_OPK_ERROR)
{
if (opk->previously_printed == 1) {
puts("");
@@ -472,9 +503,9 @@ opkg_opk_opk_free(struct opkg_opk_opk *opk)
{
struct _opkg_opk_opk_seek_name *name;
- while (opk->print_control != NULL) {
- name = opk->print_control;
- opk->print_control = opk->print_control->next;
+ while (opk->print_control_head != NULL) {
+ name = opk->print_control_head;
+ opk->print_control_head = opk->print_control_head->next;
free(name);
}
free(opk);