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)
40 hist_clear_forward(head, TAILQ_NEXT(h, entries));
41 TAILQ_REMOVE(&head->head, h, entries);
46 hist_push(struct histhead *head, struct hist *h)
49 TAILQ_INSERT_TAIL(&head->head, h, entries);
53 hist_add_before(struct histhead *head, struct hist *curr, struct hist *h)
56 TAILQ_INSERT_BEFORE(curr, h, entries);
60 hist_pop(struct histhead *head)
64 if ((h = TAILQ_LAST(&head->head, mhisthead)) == NULL)
66 if ((p = TAILQ_PREV(h, mhisthead, entries)) == NULL)
69 hist_clear_forward(head, h);