aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/push.c
blob: 1a9056da8f7513feea4917fc24c38e7b270d1699 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "prv.h"
#include <stdlib.h>

int push(const struct pos *pos, struct prv *p)
{
    size_t n = p->n + 1;
    struct pos *npos = realloc(p->pos, n * sizeof *npos);

    if (!npos)
    {
        perror("realloc(3)");
        return -1;
    }
    else if (p->n)
    {
        struct pos *prev = &npos[p->n - 1];

        prev->end = prev->seq->end;
        prev->seq = prev->stseq;
        prev->step = prev->seq->steps;
        p->i++;
    }

    npos[p->n++] = *pos;
    p->pos = npos;
    return 0;
}