diff --git a/xs.h b/xs.h index 800e407..993aa04 100644 --- a/xs.h +++ b/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; - /* iterate to the end */ - while (xs_list_iter(&p, &v)); + 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); diff --git a/xs_version.h b/xs_version.h index 261706a..87a8874 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 366ce5817597e9f4d735bced6b8c40ecc897608e */ +/* e8b70248081aa9086f64861bc85a67f390c41afb */