-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathcommon.h
75 lines (63 loc) · 1.57 KB
/
common.h
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
// #include <emscripten/emscripten.h>
#ifdef _MSC_VER
#ifndef __cplusplus
#define inline __inline
#endif
#endif
typedef uint8_t bool;
typedef uint8_t u8;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint32_t u32;
typedef int32_t i32;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define true TRUE
#define false FALSE
#ifndef static_assert
#if __has_feature(c_static_assert)
#define static_assert _Static_assert
#else
#define static_assert(cond, msg) ((void*)0)
#endif
#endif
#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; })
#define countof(x) \
((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#ifndef DEBUG
#define DEBUG 0
#endif
#if DEBUG
#include <stdio.h>
#define dlog(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)
#else
#define dlog(...)
#endif /* DEBUG > 0 */
#include "wbuf.h"
// these should be in sync with "OutputFlags" in md.js
typedef enum OutputFlags {
OutputFlagHTML = 1 << 0,
OutputFlagXHTML = 1 << 1,
OutputFlagAllowJSURI = 1 << 2, // allow "javascript:" URIs in links
OutputFlagDisableHeadlineAnchors = 1 << 3,
} OutputFlags;
typedef int(*JSTextFilterFun)(
const char* metaptr, u32 metalen,
const char* inptr, u32 inlen,
const char** outptrp); // return outlen