-
Notifications
You must be signed in to change notification settings - Fork 156
/
flags.c
135 lines (114 loc) · 2.83 KB
/
flags.c
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdio.h>
#include "markdown.h"
struct flagnames {
int flag;
char *name;
};
static struct flagnames flagnames[] = {
{ MKD_NOLINKS, "!LINKS" },
{ MKD_NOIMAGE, "!IMAGE" },
{ MKD_NOPANTS, "!PANTS" },
{ MKD_NOHTML, "!HTML" },
{ MKD_TAGTEXT, "TAGTEXT" },
{ MKD_NO_EXT, "!EXT" },
{ MKD_CDATA, "CDATA" },
{ MKD_NOSUPERSCRIPT, "!SUPERSCRIPT" },
{ MKD_STRICT, "STRICT" },
{ MKD_NOTABLES, "!TABLES" },
{ MKD_NOSTRIKETHROUGH,"!STRIKETHROUGH" },
{ MKD_TOC, "TOC" },
{ MKD_1_COMPAT, "MKD_1_COMPAT" },
{ MKD_AUTOLINK, "AUTOLINK" },
{ MKD_SAFELINK, "SAFELINK" },
{ MKD_NOHEADER, "!HEADER" },
{ MKD_TABSTOP, "TABSTOP" },
{ MKD_NODIVQUOTE, "!DIVQUOTE" },
{ MKD_NOALPHALIST, "!ALPHALIST" },
{ MKD_EXTRA_FOOTNOTE, "FOOTNOTE" },
{ MKD_NOSTYLE, "!STYLE" },
{ MKD_DLDISCOUNT, "DLDISCOUNT" },
{ MKD_DLEXTRA, "DLEXTRA" },
{ MKD_FENCEDCODE, "FENCEDCODE" },
{ MKD_IDANCHOR, "IDANCHOR" },
{ MKD_GITHUBTAGS, "GITHUBTAGS" },
{ MKD_NORMAL_LISTITEM, "NORMAL_LISTITEM" },
{ MKD_URLENCODEDANCHOR, "URLENCODEDANCHOR" },
{ MKD_LATEX, "LATEX" },
{ MKD_EXPLICITLIST, "EXPLICITLIST" },
{ MKD_ALT_AS_TITLE, "ALT_AS_TITLE" },
};
#define NR(x) (sizeof x/sizeof x[0])
int
mkd_flag_isset(mkd_flag_t *flags, int i)
{
return flags ? is_flag_set(flags, i) : 0;
}
void
mkd_flags_are(FILE *f, mkd_flag_t* flags, int htmlplease)
{
int i;
int not, set, even=1;
char *name;
if ( htmlplease )
fprintf(f, "<table class=\"mkd_flags_are\">\n");
for (i=0; i < NR(flagnames); i++) {
set = mkd_flag_isset(flags, flagnames[i].flag);
name = flagnames[i].name;
if ( not = (*name == '!') ) {
++name;
set = !set;
}
if ( htmlplease ) {
if ( even ) fprintf(f, " <tr>");
fprintf(f, "<td>");
}
else
fputc(' ', f);
if ( !set )
fprintf(f, htmlplease ? "<s>" : "!");
fprintf(f, "%s", name);
if ( htmlplease ) {
if ( !set )
fprintf(f, "</s>");
fprintf(f, "</td>");
if ( !even ) fprintf(f, "</tr>\n");
}
even = !even;
}
if ( htmlplease ) {
if ( even ) fprintf(f, "</tr>\n");
fprintf(f, "</table>\n");
}
}
void
mkd_mmiot_flags(FILE *f, MMIOT *m, int htmlplease)
{
if ( m )
mkd_flags_are(f, &(m->flags), htmlplease);
}
void
mkd_init_flags(mkd_flag_t *p)
{
memset(p, 0, sizeof(*p));
}
mkd_flag_t *
mkd_flags(void)
{
mkd_flag_t *p = malloc( sizeof(mkd_flag_t) );
if ( p )
mkd_init_flags(p);
return p;
}
mkd_flag_t *
mkd_copy_flags(mkd_flag_t *original)
{
mkd_flag_t *copy = mkd_flags();
if ( original && copy )
*copy = *original;
return copy;
}
void
mkd_free_flags(mkd_flag_t *rip)
{
if (rip) free(rip);
}