2013-03-01 16:09:22 +00:00
|
|
|
/*
|
|
|
|
* iter.h
|
|
|
|
* Linked lists and iterators.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 pkgconf authors (see AUTHORS).
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PKGCONF__ITER_H
|
|
|
|
#define PKGCONF__ITER_H
|
|
|
|
|
2017-09-13 19:35:28 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
typedef struct pkgconf_node_ pkgconf_node_t;
|
2013-03-01 16:09:22 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
struct pkgconf_node_ {
|
|
|
|
pkgconf_node_t *prev, *next;
|
2013-03-01 16:09:22 +00:00
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *head, *tail;
|
2016-12-30 15:57:01 +00:00
|
|
|
size_t length;
|
2015-09-06 15:31:21 +00:00
|
|
|
} pkgconf_list_t;
|
2013-03-01 16:09:22 +00:00
|
|
|
|
2016-12-30 15:57:01 +00:00
|
|
|
#define PKGCONF_LIST_INITIALIZER { NULL, NULL, 0 }
|
2013-03-01 16:14:20 +00:00
|
|
|
|
2013-03-01 16:09:22 +00:00
|
|
|
static inline void
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_insert(pkgconf_node_t *node, void *data, pkgconf_list_t *list)
|
2013-03-01 16:09:22 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *tnode;
|
2013-03-01 16:09:22 +00:00
|
|
|
|
|
|
|
node->data = data;
|
|
|
|
|
|
|
|
if (list->head == NULL)
|
|
|
|
{
|
|
|
|
list->head = node;
|
|
|
|
list->tail = node;
|
2016-12-30 15:57:01 +00:00
|
|
|
list->length = 1;
|
2013-03-01 16:09:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tnode = list->head;
|
|
|
|
|
|
|
|
node->next = tnode;
|
|
|
|
tnode->prev = node;
|
|
|
|
|
|
|
|
list->head = node;
|
2016-12-30 15:57:01 +00:00
|
|
|
list->length++;
|
2013-03-01 16:09:22 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
static inline void
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_insert_tail(pkgconf_node_t *node, void *data, pkgconf_list_t *list)
|
2013-03-01 16:24:57 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *tnode;
|
2013-03-01 16:24:57 +00:00
|
|
|
|
|
|
|
node->data = data;
|
|
|
|
|
2017-01-23 06:24:13 +00:00
|
|
|
if (list->tail == NULL)
|
2013-03-01 16:24:57 +00:00
|
|
|
{
|
|
|
|
list->head = node;
|
|
|
|
list->tail = node;
|
2016-12-30 15:57:01 +00:00
|
|
|
list->length = 1;
|
2013-03-01 16:24:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tnode = list->tail;
|
|
|
|
|
|
|
|
node->prev = tnode;
|
|
|
|
tnode->next = node;
|
|
|
|
|
|
|
|
list->tail = node;
|
2016-12-30 15:57:01 +00:00
|
|
|
list->length++;
|
2013-03-01 16:24:57 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 16:09:22 +00:00
|
|
|
static inline void
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_delete(pkgconf_node_t *node, pkgconf_list_t *list)
|
2013-03-01 16:09:22 +00:00
|
|
|
{
|
2016-12-30 15:57:01 +00:00
|
|
|
list->length--;
|
|
|
|
|
2013-03-01 16:09:22 +00:00
|
|
|
if (node->prev == NULL)
|
|
|
|
list->head = node->next;
|
|
|
|
else
|
|
|
|
node->prev->next = node->next;
|
|
|
|
|
|
|
|
if (node->next == NULL)
|
|
|
|
list->tail = node->prev;
|
|
|
|
else
|
|
|
|
node->next->prev = node->prev;
|
|
|
|
}
|
|
|
|
|
2017-09-13 19:35:28 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-01 16:09:22 +00:00
|
|
|
#endif
|