2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include "telescope.h"
24 hist_clear(struct histhead *head)
28 TAILQ_FOREACH_SAFE(h, &head->head, entries, th) {
29 TAILQ_REMOVE(&head->head, h, entries);
36 hist_clear_forward(struct histhead *head, struct hist *h)
43 while ((i = TAILQ_NEXT(h, entries)) != NULL) {
44 TAILQ_REMOVE(&head->head, i, entries);
49 TAILQ_REMOVE(&head->head, h, entries);
55 hist_push(struct histhead *head, struct hist *h)
58 TAILQ_INSERT_TAIL(&head->head, h, entries);
62 hist_add_before(struct histhead *head, struct hist *curr, struct hist *h)
65 TAILQ_INSERT_BEFORE(curr, h, entries);
69 hist_pop(struct histhead *head)
73 if ((h = TAILQ_LAST(&head->head, mhisthead)) == NULL)
75 if ((p = TAILQ_PREV(h, mhisthead, entries)) == NULL)
78 hist_clear_forward(head, h);