Blame
Date:
Wed Jan 5 15:34:48 2022 UTC
Message:
unroll recursion
01
2021-03-13
op
/*
02
2021-03-13
op
* Copyright (c) 2021 Omar Polo <op@omarpolo.com>
03
2021-03-13
op
*
04
2021-03-13
op
* Permission to use, copy, modify, and distribute this software for any
05
2021-03-13
op
* purpose with or without fee is hereby granted, provided that the above
06
2021-03-13
op
* copyright notice and this permission notice appear in all copies.
07
2021-03-13
op
*
08
2021-03-13
op
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
09
2021-03-13
op
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
2021-03-13
op
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
2021-03-13
op
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
2021-03-13
op
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
2021-03-13
op
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
2021-03-13
op
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
2021-03-13
op
*/
16
2021-03-13
op
17
2021-07-21
op
#include "compat.h"
18
2021-03-13
op
19
2021-03-13
op
#include <stdlib.h>
20
2021-03-13
op
21
2021-07-21
op
#include "telescope.h"
22
2021-07-21
op
23
2021-03-13
op
void
24
2022-01-05
op
hist_clear(struct histhead *head)
25
2022-01-05
op
{
26
2022-01-05
op
struct hist *h, *th;
27
2022-01-05
op
28
2022-01-05
op
TAILQ_FOREACH_SAFE(h, &head->head, entries, th) {
29
2022-01-05
op
TAILQ_REMOVE(&head->head, h, entries);
30
2022-01-05
op
free(h);
31
2022-01-05
op
}
32
2022-01-05
op
head->len = 0;
33
2022-01-05
op
}
34
2022-01-05
op
35
2022-01-05
op
void
36
2021-03-13
op
hist_clear_forward(struct histhead *head, struct hist *h)
37
2021-03-13
op
{
38
2022-01-05
op
struct hist *i;
39
2022-01-05
op
40
2021-03-13
op
if (h == NULL)
41
2021-03-13
op
return;
42
2022-01-05
op
43
2022-01-05
op
while ((i = TAILQ_NEXT(h, entries)) != NULL) {
44
2022-01-05
op
TAILQ_REMOVE(&head->head, i, entries);
45
2022-01-05
op
free(i);
46
2022-01-05
op
head->len--;
47
2022-01-05
op
}
48
2022-01-05
op
49
2021-03-13
op
TAILQ_REMOVE(&head->head, h, entries);
50
2021-03-13
op
free(h);
51
2022-01-05
op
head->len--;
52
2021-03-13
op
}
53
2021-03-13
op
54
2021-03-13
op
void
55
2021-03-13
op
hist_push(struct histhead *head, struct hist *h)
56
2021-03-13
op
{
57
2021-03-13
op
head->len++;
58
2021-08-12
op
TAILQ_INSERT_TAIL(&head->head, h, entries);
59
2021-03-13
op
}
60
2021-11-05
op
61
2021-01-02
op
void
62
2021-01-02
op
hist_add_before(struct histhead *head, struct hist *curr, struct hist *h)
63
2021-01-02
op
{
64
2021-01-02
op
head->len++;
65
2021-01-02
op
TAILQ_INSERT_BEFORE(curr, h, entries);
66
2021-01-02
op
}
67
2021-01-02
op
68
2021-11-05
op
struct hist *
69
2021-11-05
op
hist_pop(struct histhead *head)
70
2021-11-05
op
{
71
2021-11-05
op
struct hist *h, *p;
72
2021-11-05
op
73
2021-11-05
op
if ((h = TAILQ_LAST(&head->head, mhisthead)) == NULL)
74
2021-11-05
op
return NULL;
75
2021-11-05
op
if ((p = TAILQ_PREV(h, mhisthead, entries)) == NULL)
76
2021-11-05
op
return NULL;
77
2021-11-05
op
78
2021-11-05
op
hist_clear_forward(head, h);
79
2021-11-05
op
return p;
80
2021-11-05
op
}
Omar Polo