toolbox

Check-in [f070c34d00]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:lib: switch to TAILQ for jtlst implementation for openbsd compatibility
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f070c34d002be2eec82f00eb64b93797445912e986b54c9f6e88b75ef36e94d0
User & Date: jef 2020-05-02 09:16:10
Context
2020-06-10
04:19
rss: remove useless variable check-in: 8648f0c046 user: jef tags: trunk
2020-05-02
09:16
lib: switch to TAILQ for jtlst implementation for openbsd compatibility check-in: f070c34d00 user: jef tags: trunk
08:48
retab: simplify max_widths() check-in: 2ff913e864 user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/include/jt.h.

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

/*
** jtlst
*/

typedef struct jtlstnode {
	void *data;
	STAILQ_ENTRY(jtlstnode) next;
} jtlstnode;

STAILQ_HEAD(jt_tailq_list, jtlstnode);

typedef struct jtlst {
	size_t size;
	struct jt_tailq_list list;
} jtlst;

jtlst *jtlst_new();
................................................................................
size_t jtlst_size(jtlst *arr);

// scary macro to walk a jtlst list in a
// convenient manner from the user perspective
#define __jtlstnode JTGENSYM()
#define JTLST_FOREACH(value, arr) \
         struct jtlstnode * __jtlstnode; \
         for (__jtlstnode = STAILQ_FIRST((&arr->list)); \
                 (void) (__jtlstnode && ((value) = __jtlstnode->data)), __jtlstnode; \
                 __jtlstnode = STAILQ_NEXT(__jtlstnode, next))

/*
** str
*/ 

char *str_del_prefix(char *str, const char *prefix);
char *str_del_suffix(char *str, const char *suffix);







|


|







 







|

|







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

/*
** jtlst
*/

typedef struct jtlstnode {
	void *data;
	TAILQ_ENTRY(jtlstnode) next;
} jtlstnode;

TAILQ_HEAD(jt_tailq_list, jtlstnode);

typedef struct jtlst {
	size_t size;
	struct jt_tailq_list list;
} jtlst;

jtlst *jtlst_new();
................................................................................
size_t jtlst_size(jtlst *arr);

// scary macro to walk a jtlst list in a
// convenient manner from the user perspective
#define __jtlstnode JTGENSYM()
#define JTLST_FOREACH(value, arr) \
         struct jtlstnode * __jtlstnode; \
         for (__jtlstnode = TAILQ_FIRST((&arr->list)); \
                 (void) (__jtlstnode && ((value) = __jtlstnode->data)), __jtlstnode; \
                 __jtlstnode = TAILQ_NEXT(__jtlstnode, next))

/*
** str
*/ 

char *str_del_prefix(char *str, const char *prefix);
char *str_del_suffix(char *str, const char *suffix);

Changes to src/lib/jtlst.c.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

jtlst *
jtlst_new()
{
	jtlst *arr;

	arr = xcalloc(1, sizeof(jtlst));
	STAILQ_INIT(&arr->list);

	return arr;
}

jtlst *
jtlst_clone(jtlst *arr)
{
................................................................................
jtlst_free(jtlst *arr)
{
	struct jtlstnode *e;

	if (arr == NULL)
		return;

	while (! STAILQ_EMPTY(&arr->list)) {
		e = STAILQ_FIRST(&arr->list);
		STAILQ_REMOVE_HEAD(&arr->list, next);
		xfree(e);
	}
	xfree(arr);
}

void
jtlst_free_all(jtlst *arr)
{
	struct jtlstnode *e;

	if (arr == NULL)
		return;

	while (! STAILQ_EMPTY(&arr->list)) {
		e = STAILQ_FIRST(&arr->list);
		STAILQ_REMOVE_HEAD(&arr->list, next);
		xfree(e->data);
		xfree(e);
	}
	xfree(arr);
}

void
................................................................................
jtlst_prepend(jtlst *arr, void *data)
{

	struct jtlstnode *e;

	e = xcalloc(1, sizeof(struct jtlstnode));
	e->data = data;
	STAILQ_INSERT_HEAD(&arr->list, e, next);
	arr->size++;
}

void
jtlst_append(jtlst *arr, void *data)
{
	struct jtlstnode *e;

	e = xcalloc(1, sizeof(struct jtlstnode));
	e->data = data;
	STAILQ_INSERT_TAIL(&arr->list, e, next);
	arr->size++;
}

int
jtlst_pop(jtlst *arr, void **data)
{
	jtlstnode *e;

	if (STAILQ_EMPTY(&arr->list))
		return 0;

	e = STAILQ_FIRST(&arr->list);
	*data = e->data;
	STAILQ_REMOVE_HEAD(&arr->list, next);
	xfree(e);
	arr->size--;

	return 1;
}

size_t
................................................................................
{
	return arr->size;
}

jtlstnode *
jtlst_iter(jtlst *arr)
{
	return STAILQ_FIRST(&arr->list);
}

int
jtlst_next(jtlstnode **node, void **data)
{
	if (*node == NULL)
		return 0;
	*data = (*node)->data;
	*node = STAILQ_NEXT(*node, next);

	return 1;
}







|







 







|
|
|













|
|
|







 







|










|








|


|

|







 







|








|



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

jtlst *
jtlst_new()
{
	jtlst *arr;

	arr = xcalloc(1, sizeof(jtlst));
	TAILQ_INIT(&arr->list);

	return arr;
}

jtlst *
jtlst_clone(jtlst *arr)
{
................................................................................
jtlst_free(jtlst *arr)
{
	struct jtlstnode *e;

	if (arr == NULL)
		return;

	while (! TAILQ_EMPTY(&arr->list)) {
		e = TAILQ_FIRST(&arr->list);
		TAILQ_REMOVE(&arr->list, e, next);
		xfree(e);
	}
	xfree(arr);
}

void
jtlst_free_all(jtlst *arr)
{
	struct jtlstnode *e;

	if (arr == NULL)
		return;

	while (! TAILQ_EMPTY(&arr->list)) {
		e = TAILQ_FIRST(&arr->list);
		TAILQ_REMOVE(&arr->list, e, next);
		xfree(e->data);
		xfree(e);
	}
	xfree(arr);
}

void
................................................................................
jtlst_prepend(jtlst *arr, void *data)
{

	struct jtlstnode *e;

	e = xcalloc(1, sizeof(struct jtlstnode));
	e->data = data;
	TAILQ_INSERT_HEAD(&arr->list, e, next);
	arr->size++;
}

void
jtlst_append(jtlst *arr, void *data)
{
	struct jtlstnode *e;

	e = xcalloc(1, sizeof(struct jtlstnode));
	e->data = data;
	TAILQ_INSERT_TAIL(&arr->list, e, next);
	arr->size++;
}

int
jtlst_pop(jtlst *arr, void **data)
{
	jtlstnode *e;

	if (TAILQ_EMPTY(&arr->list))
		return 0;

	e = TAILQ_FIRST(&arr->list);
	*data = e->data;
	TAILQ_REMOVE(&arr->list, e, next);
	xfree(e);
	arr->size--;

	return 1;
}

size_t
................................................................................
{
	return arr->size;
}

jtlstnode *
jtlst_iter(jtlst *arr)
{
	return TAILQ_FIRST(&arr->list);
}

int
jtlst_next(jtlstnode **node, void **data)
{
	if (*node == NULL)
		return 0;
	*data = (*node)->data;
	*node = TAILQ_NEXT(*node, next);

	return 1;
}