From: FreeBirdLjj Date: Sat, 4 Oct 2014 16:23:09 +0000 (+0800) Subject: Add support for bool type. X-Git-Url: https://git.danieliu.xyz/?p=smdp.git;a=commitdiff_plain;h=bdd26d4dde3b3d3180619cc81622081025ca6cb5 Add support for bool type. --- diff --git a/include/common.h b/include/common.h index 99c4382..1e4c07a 100644 --- a/include/common.h +++ b/include/common.h @@ -26,6 +26,23 @@ * */ +#if defined( __STDC__ ) // for standard C compiler +#if __STDC_VERSION__ >= 199901L // for C99 and later +#include +#else // __STDC_VERSION__ >= 199901L +#if !defined( bool ) +typedef enum { + false = 0, + true +} bool; +#endif // !defined( bool ) +#endif // __STDC_VERSION__ >= 199901L +#else // defined( __STDC__ ) +#define bool int +#define true 1 +#define false 0 +#endif // defined( __STDC__ ) + #define MAX(a, b) ({ typeof(a) _a = a; typeof(b) _b = b; _a > _b? _a : _b; }) #define MIN(a, b) ({ typeof(a) _a = a; typeof(b) _b = b; _a < _b? _a : _b; }) diff --git a/include/cstack.h b/include/cstack.h index bea73a6..fd6c60d 100644 --- a/include/cstack.h +++ b/include/cstack.h @@ -38,6 +38,8 @@ * */ +#include "common.h" + typedef struct _cstack_t { char *content; size_t alloc; @@ -45,16 +47,16 @@ typedef struct _cstack_t { int head; void (*push)(struct _cstack_t *self, char c); char (*pop)(struct _cstack_t *self); - int (*top)(struct _cstack_t *self, char c); - int (*empty)(struct _cstack_t *self); + bool (*top)(struct _cstack_t *self, char c); + bool (*empty)(struct _cstack_t *self); void (*delete)(struct _cstack_t *self); } cstack_t; cstack_t *cstack_init(); void cstack_push(cstack_t *self, char c); char cstack_pop(cstack_t *self); -int cstack_top(cstack_t *self, char c); -int cstack_empty(cstack_t *self); +bool cstack_top(cstack_t *self, char c); +bool cstack_empty(cstack_t *self); void cstack_delete(cstack_t *self); #endif // !defined( CSTACK_H ) diff --git a/include/parser.h b/include/parser.h index 4eb9dfe..99f68ff 100644 --- a/include/parser.h +++ b/include/parser.h @@ -45,7 +45,7 @@ deck_t *markdown_load(FILE *input); int markdown_analyse(cstring_t *text); void markdown_debug(deck_t *deck, int debug); -int is_utf8(char ch); +bool is_utf8(char ch); int length_utf8(char ch); int next_nonblank(cstring_t *text, int i); int prev_blank(cstring_t *text, int i); diff --git a/src/cstack.c b/src/cstack.c index 31611c2..4763b5b 100644 --- a/src/cstack.c +++ b/src/cstack.c @@ -59,13 +59,11 @@ char cstack_pop(cstack_t *self) { 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, char 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; } diff --git a/src/parser.c b/src/parser.c index 6294500..ce3f702 100644 --- a/src/parser.c +++ b/src/parser.c @@ -478,8 +478,8 @@ void markdown_debug(deck_t *deck, int debug) { } } -int is_utf8(char ch) { - return (ch & 0x80); +bool is_utf8(char ch) { + return (ch & 0x80) != 0x00; } int length_utf8(char ch) {