mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
Backport from xs.
This commit is contained in:
parent
af604f91a9
commit
4baf56c4ce
14
xs.h
14
xs.h
@ -76,7 +76,9 @@ d_char *xs_list_del(d_char *list, int num);
|
||||
d_char *xs_list_insert(d_char *list, int num, const char *data);
|
||||
d_char *xs_list_insert_sorted(d_char *list, const char *str);
|
||||
d_char *xs_list_set(d_char *list, int num, const char *data);
|
||||
d_char *xs_list_pop(d_char *list, char **data);
|
||||
d_char *xs_list_dequeue(d_char *list, char **data, int last);
|
||||
#define xs_list_pop(list, data) xs_list_dequeue(list, data, 1)
|
||||
#define xs_list_shift(list, data) xs_list_dequeue(list, data, 0)
|
||||
int xs_list_in(char *list, const char *val);
|
||||
d_char *xs_join(char *list, const char *sep);
|
||||
d_char *xs_split_n(const char *str, const char *sep, int times);
|
||||
@ -665,13 +667,19 @@ d_char *xs_list_set(d_char *list, int num, const char *data)
|
||||
}
|
||||
|
||||
|
||||
d_char *xs_list_pop(d_char *list, char **data)
|
||||
/* pops the last element from the list */
|
||||
d_char *xs_list_dequeue(d_char *list, char **data, int last)
|
||||
/* gets a copy of the first or last element of a list, shrinking it */
|
||||
{
|
||||
char *p = list, *v = NULL;
|
||||
|
||||
if (!last) {
|
||||
/* get the first */
|
||||
xs_list_iter(&p, &v);
|
||||
}
|
||||
else {
|
||||
/* iterate to the end */
|
||||
while (xs_list_iter(&p, &v));
|
||||
}
|
||||
|
||||
if (v != NULL) {
|
||||
*data = xs_dup(v);
|
||||
|
@ -1 +1 @@
|
||||
/* 366ce5817597e9f4d735bced6b8c40ecc897608e */
|
||||
/* e8b70248081aa9086f64861bc85a67f390c41afb */
|
||||
|
Loading…
Reference in New Issue
Block a user