gi-server

Unnamed repository; edit this file 'description' to name the repository.
git clone https://logand.com/git/gi-server.git/
Log | Files | Refs

commit 24da4f2a1bb4df68d5d6c706bbbf7ff3c083c132
parent cb16b23be62ad9224ef8513b3269627c8df06d8f
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sun, 16 Aug 2015 18:08:17 +0200

better error handling

Diffstat:
Mgi-server.c | 25++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/gi-server.c b/gi-server.c @@ -15,6 +15,17 @@ static void skip(void) { ungetc(c, stdin); } +enum { + OUT_OF_MEMORY = 1, + UNEXPECTED_EOF = 2 +}; + +static void put(char c) { + if(heap + HSIZE <= top) + exit(OUT_OF_MEMORY); + *top++ = c; +} + static char *token(void) { skip(); char *z = top; @@ -22,21 +33,21 @@ static char *token(void) { if('"' == c) { while('"' != (c = getc(stdin)) && EOF != c) { if(EOF == c) - exit(1); + exit(UNEXPECTED_EOF); if('\\' == c) { c = getc(stdin); if(EOF == c) - exit(1); + exit(UNEXPECTED_EOF); } - *top++ = c; + put(c); } - *top++ = 0; + put(0); return z; } else { - *top++ = c; + put(c); while(!isspace(c = getc(stdin)) && EOF != c) - *top++ = c; - *top++ = 0; + put(c); + put(0); return !strcmp("null", z) ? (char *) NULL : z; }; }