X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=src%2Fcstack.c;h=0906ea5b287effa431356ae7875433c4f23fcf13;hb=354cf2e07ccd0d7900f96bffc279093997cbe203;hp=31611c21f6c3df18dc7f5981f1c8e5bd839e136d;hpb=b1e0c986d6e531f71d0a3ecc01551ab2d9cd8929;p=smdp.git diff --git a/src/cstack.c b/src/cstack.c index 31611c2..0906ea5 100644 --- a/src/cstack.c +++ b/src/cstack.c @@ -1,6 +1,6 @@ /* * An implementation of a char stack in heap memory. - * Copyright (C) 2014 Michael Goehler + * Copyright (C) 2018 Michael Goehler * * This file is part of mdp. * @@ -19,6 +19,7 @@ * */ +#include #include // fprintf #include // malloc, realloc @@ -42,30 +43,28 @@ cstack_t *cstack_init() { return stack; } -void cstack_push(cstack_t *self, char c) { +void cstack_push(cstack_t *self, wchar_t c) { if(self->size + sizeof(c) > self->alloc) { - self->alloc += (sizeof(char)); + self->alloc += (sizeof(wchar_t)); if((self->content = realloc(self->content, self->alloc)) == NULL) { fprintf(stderr, "%s\n", "cstack_push() failed to reallocate memory."); exit(EXIT_FAILURE); } } self->content[++self->head] = c; - self->size += (sizeof(char)); + self->size += (sizeof(wchar_t)); } -char cstack_pop(cstack_t *self) { - self->size -= (sizeof(char)); +wchar_t cstack_pop(cstack_t *self) { + self->size -= (sizeof(wchar_t)); return self->content[self->head--]; } -int cstack_top(cstack_t *self, char c) { - if(self->head >= 0 && self->content[self->head] == c) - return 1; - return 0; +bool cstack_top(cstack_t *self, wchar_t c) { + return self->head >= 0 && self->content[self->head] == c; } -int cstack_empty(cstack_t *self) { +bool cstack_empty(cstack_t *self) { return self->head == -1; }