Add stack_push_many method
This commit is contained in:
parent
862e85145c
commit
3cbf7a6fdf
@ -14,6 +14,7 @@ typedef struct libcdsb_stack_node {
|
|||||||
|
|
||||||
extern void libcdsb_stack_init (stack_t* stack) Nonnull__(1);
|
extern void libcdsb_stack_init (stack_t* stack) Nonnull__(1);
|
||||||
extern void libcdsb_stack_push (stack_t* stack, void* value) Nonnull__(1);
|
extern void libcdsb_stack_push (stack_t* stack, void* value) Nonnull__(1);
|
||||||
|
extern void libcdsb_stack_push_many(stack_t* stack, size_t n, ...) Nonnull__(1);
|
||||||
extern void* libcdsb_stack_pop (stack_t* stack) Nonnull__(1);
|
extern void* libcdsb_stack_pop (stack_t* stack) Nonnull__(1);
|
||||||
extern void libcdsb_stack_flush (stack_t* stack) Nonnull__(1);
|
extern void libcdsb_stack_flush (stack_t* stack) Nonnull__(1);
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ extern void libcdsb_free(void* s);
|
|||||||
|
|
||||||
#define stack_init libcdsb_stack_init
|
#define stack_init libcdsb_stack_init
|
||||||
#define stack_push libcdsb_stack_push
|
#define stack_push libcdsb_stack_push
|
||||||
|
#define stack_push_many libcdsb_stack_push_many
|
||||||
#define stack_pop libcdsb_stack_pop
|
#define stack_pop libcdsb_stack_pop
|
||||||
#define stack_flush libcdsb_stack_flush
|
#define stack_flush libcdsb_stack_flush
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* This software is licensed by the MIT License, see LICENSE file */
|
/* This software is licensed by the MIT License, see LICENSE file */
|
||||||
/* Copyright © 2022 Gregory Lirent */
|
/* Copyright © 2022 Gregory Lirent */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "__internal/include.h"
|
#include "__internal/include.h"
|
||||||
#undef malloc
|
#undef malloc
|
||||||
@ -26,6 +27,31 @@ void libcdsb_stack_push(stack_t* x, void* value) {
|
|||||||
x->value = value;
|
x->value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void libcdsb_stack_push_many(stack_t* x, size_t c, ...) {
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
stack_t* n;
|
||||||
|
va_start(args, c);
|
||||||
|
|
||||||
|
if (c) {
|
||||||
|
if (!x->value) {
|
||||||
|
x->value = va_arg(args, void*);
|
||||||
|
--c;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (c--) {
|
||||||
|
if (!(n = malloc(sizeof(*n))))
|
||||||
|
abort();
|
||||||
|
|
||||||
|
n->prev = x->prev;
|
||||||
|
n->value = x->value;
|
||||||
|
x->prev = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
void* libcdsb_stack_pop(stack_t* x) {
|
void* libcdsb_stack_pop(stack_t* x) {
|
||||||
|
|
||||||
stack_t* n;
|
stack_t* n;
|
||||||
|
Loading…
Reference in New Issue
Block a user