From: Michael Göhler Date: Fri, 15 Aug 2014 21:37:56 +0000 (+0200) Subject: draft markdown header + bit test X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=b83e558d4fa221404aadb87bac1c25ce82774efd;p=smdp.git draft markdown header + bit test --- diff --git a/include/markdown.h b/include/markdown.h new file mode 100644 index 0000000..357de78 --- /dev/null +++ b/include/markdown.h @@ -0,0 +1,44 @@ +#if !defined( MARKDOWN_H ) +#define MARKDOWN_H + +/* + * A implementation of markdown objects. + * + */ + +#include "cstring.h" + +#define SET_BIT(var, pos) ((var) |= (1<<(pos))) +#define CLEAR_BIT(var, pos) ((var) &= (~(1<<(pos)))) +#define TOGGLE_BIT(var, pos) ((var) ^= (1<<(pos))) +#define CHECK_BIT(var, pos) ((var) & (1<<(pos))) + +enum line_bitmask { + IS_HEADER, + IS_HEADER2, + IS_QUOTE, + IS_CODE, + IS_LIST, + IS_NUMLIST +}; + +typedef struct _line_t { + cstring_t *text; + struct _line_t *next; + int bits; + int left_white_space; +} line_t; + +typedef struct _page_t { + line_t *lines; + struct _page_t *next; +} page_t; + +typedef struct _document_t { + line_t *title; + line_t *author; + line_t *date; + page_t *pages; +} document_t; + +#endif // !defined( MARKDOWN_H ) diff --git a/test/bits.c b/test/bits.c new file mode 100644 index 0000000..58eb687 --- /dev/null +++ b/test/bits.c @@ -0,0 +1,29 @@ +#include + +#include "../include/markdown.h" + +int main(int argc, char *argv[]) { + + int i; + printf("INIT: %i\n", i); + + SET_BIT(i, IS_HEADER); + printf("SET_BIT(%i): %i\n", IS_HEADER, i); + + printf("CHECK_BIT(%i): %i\n", IS_HEADER, CHECK_BIT(i, IS_HEADER)); + + TOGGLE_BIT(i, IS_HEADER2); + printf("TOGGLE_BIT(%i): %i\n", IS_HEADER2, i); + + printf("CHECK_BIT(%i): %i\n", IS_HEADER2, CHECK_BIT(i, IS_HEADER2)); + + TOGGLE_BIT(i, IS_HEADER2); + printf("TOGGLE_BIT(%i): %i\n", IS_HEADER2, i); + + CLEAR_BIT(i, IS_HEADER); + printf("CLEAR_BIT(%i): %i\n", IS_HEADER, i); + + printf("CHECK_BIT(%i): %i\n", IS_HEADER, CHECK_BIT(i, IS_HEADER)); + printf("CHECK_BIT(%i): %i\n", IS_HEADER2, CHECK_BIT(i, IS_HEADER2)); +} +