diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-05-09 02:56:07 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-05-17 11:13:23 +0200 |
| commit | 527c23b73c8dae16f02cca6f450edb7d8225f60f (patch) | |
| tree | 6b2bfd9e8d814026d6d2c1839d8cfe1bcadc825c /pop.c | |
| download | slcob-master.tar.gz | |
Diffstat (limited to 'pop.c')
| -rw-r--r-- | pop.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -0,0 +1,37 @@ +#include "prv.h" +#include <stdlib.h> + +int pop(const struct lex *l, struct prv *p) +{ + size_t n; + struct pos *npos = NULL; + + if (!p->n) + { + fprintf(stderr, "%s: underflow\n", __func__); + return -1; + } + else if (!(n = p->n - 1)) + { + free(p->pos); + p->pos = NULL; + } + else if (!(npos = realloc(p->pos, n * sizeof *npos))) + { + perror("realloc(3)"); + return -1; + } + + p->pos = npos; + p->n = n; + + if (p->n) + { + const struct pos *old = &p->pos[--p->i]; + + if (old->seq->end && old->seq->end(l, p)) + return -1; + } + + return 0; +} |
