rdiscount 2.0.7.3 → 2.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/BUILDING +4 -3
- data/COPYING +25 -44
- data/Rakefile +4 -0
- data/ext/Csio.c +1 -1
- data/ext/VERSION +1 -1
- data/ext/blocktags +33 -0
- data/ext/config.h +6 -0
- data/ext/cstring.h +2 -2
- data/ext/flags.c +1 -0
- data/ext/generate.c +146 -64
- data/ext/github_flavoured.c +100 -0
- data/ext/html5.c +0 -2
- data/ext/markdown.c +229 -136
- data/ext/markdown.h +40 -3
- data/ext/mkdio.c +25 -28
- data/ext/mkdio.h +9 -2
- data/ext/mktags.c +89 -0
- data/ext/pgm_options.c +138 -0
- data/ext/pgm_options.h +9 -0
- data/ext/rdiscount.c +52 -52
- data/ext/setup.c +1 -9
- data/ext/tags.c +34 -66
- data/ext/toc.c +21 -10
- data/ext/version.c +9 -1
- data/lib/rdiscount.rb +7 -1
- data/rdiscount.gemspec +7 -2
- data/test/rdiscount_test.rb +86 -1
- metadata +7 -2
data/ext/markdown.h
CHANGED
@@ -23,10 +23,20 @@ typedef struct footnote {
|
|
23
23
|
* that all tabs will be expanded to spaces!], and a pointer to
|
24
24
|
* the next line.
|
25
25
|
*/
|
26
|
+
typedef enum { chk_text, chk_code,
|
27
|
+
chk_hr, chk_dash,
|
28
|
+
chk_tilde, chk_backtick,
|
29
|
+
chk_equal } line_type;
|
26
30
|
typedef struct line {
|
27
31
|
Cstring text;
|
28
32
|
struct line *next;
|
29
|
-
int dle;
|
33
|
+
int dle; /* leading indent on the line */
|
34
|
+
int flags; /* special attributes for this line */
|
35
|
+
#define PIPECHAR 0x01 /* line contains a | */
|
36
|
+
#define CHECKED 0x02
|
37
|
+
|
38
|
+
line_type kind;
|
39
|
+
int count;
|
30
40
|
} Line;
|
31
41
|
|
32
42
|
|
@@ -71,6 +81,12 @@ typedef struct callback_data {
|
|
71
81
|
} Callback_data;
|
72
82
|
|
73
83
|
|
84
|
+
struct escaped {
|
85
|
+
char *text;
|
86
|
+
struct escaped *up;
|
87
|
+
} ;
|
88
|
+
|
89
|
+
|
74
90
|
/* a magic markdown io thing holds all the data structures needed to
|
75
91
|
* do the backend processing of a markdown document
|
76
92
|
*/
|
@@ -80,6 +96,7 @@ typedef struct mmiot {
|
|
80
96
|
Qblock Q;
|
81
97
|
int isp;
|
82
98
|
int reference;
|
99
|
+
struct escaped *esc;
|
83
100
|
char *ref_prefix;
|
84
101
|
STRING(Footnote) *footnotes;
|
85
102
|
DWORD flags;
|
@@ -105,6 +122,7 @@ typedef struct mmiot {
|
|
105
122
|
#define MKD_NOALPHALIST 0x00080000
|
106
123
|
#define MKD_NODLIST 0x00100000
|
107
124
|
#define MKD_EXTRA_FOOTNOTE 0x00200000
|
125
|
+
#define MKD_NOSTYLE 0x00400000
|
108
126
|
#define IS_LABEL 0x08000000
|
109
127
|
#define USER_FLAGS 0x0FFFFFFF
|
110
128
|
#define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP)
|
@@ -137,6 +155,16 @@ typedef struct document {
|
|
137
155
|
} Document;
|
138
156
|
|
139
157
|
|
158
|
+
/*
|
159
|
+
* economy FILE-type structure for pulling characters out of a
|
160
|
+
* fixed-length string.
|
161
|
+
*/
|
162
|
+
struct string_stream {
|
163
|
+
const char *data; /* the unread data */
|
164
|
+
int size; /* and how much is there? */
|
165
|
+
} ;
|
166
|
+
|
167
|
+
|
140
168
|
extern int mkd_firstnonblank(Line *);
|
141
169
|
extern int mkd_compile(Document *, DWORD);
|
142
170
|
extern int mkd_document(Document *, char **);
|
@@ -156,7 +184,10 @@ typedef int (*mkd_sta_function_t)(const int,const void*);
|
|
156
184
|
extern void mkd_string_to_anchor(char*,int, mkd_sta_function_t, void*, int);
|
157
185
|
|
158
186
|
extern Document *mkd_in(FILE *, DWORD);
|
159
|
-
extern Document *mkd_string(char*,int, DWORD);
|
187
|
+
extern Document *mkd_string(const char*,int, DWORD);
|
188
|
+
|
189
|
+
extern Document *gfm_in(FILE *, DWORD);
|
190
|
+
extern Document *gfm_string(const char*,int, DWORD);
|
160
191
|
|
161
192
|
extern void mkd_initialize();
|
162
193
|
extern void mkd_shlib_destructor();
|
@@ -174,8 +205,14 @@ extern void ___mkd_initmmiot(MMIOT *, void *);
|
|
174
205
|
extern void ___mkd_freemmiot(MMIOT *, void *);
|
175
206
|
extern void ___mkd_freeLineRange(Line *, Line *);
|
176
207
|
extern void ___mkd_xml(char *, int, FILE *);
|
177
|
-
extern void ___mkd_reparse(char *, int, int, MMIOT*);
|
208
|
+
extern void ___mkd_reparse(char *, int, int, MMIOT*, char*);
|
178
209
|
extern void ___mkd_emblock(MMIOT*);
|
179
210
|
extern void ___mkd_tidy(Cstring *);
|
180
211
|
|
212
|
+
extern Document *__mkd_new_Document();
|
213
|
+
extern void __mkd_enqueue(Document*, Cstring *);
|
214
|
+
extern void __mkd_header_dle(Line *);
|
215
|
+
|
216
|
+
extern int __mkd_io_strget(struct string_stream *);
|
217
|
+
|
181
218
|
#endif/*_MARKDOWN_D*/
|
data/ext/mkdio.c
CHANGED
@@ -18,13 +18,13 @@ typedef ANCHOR(Line) LineAnchor;
|
|
18
18
|
|
19
19
|
/* create a new blank Document
|
20
20
|
*/
|
21
|
-
|
22
|
-
|
21
|
+
Document*
|
22
|
+
__mkd_new_Document()
|
23
23
|
{
|
24
24
|
Document *ret = calloc(sizeof(Document), 1);
|
25
25
|
|
26
26
|
if ( ret ) {
|
27
|
-
if (
|
27
|
+
if ( ret->ctx = calloc(sizeof(MMIOT), 1) ) {
|
28
28
|
ret->magic = VALID_DOCUMENT;
|
29
29
|
return ret;
|
30
30
|
}
|
@@ -34,10 +34,11 @@ new_Document()
|
|
34
34
|
}
|
35
35
|
|
36
36
|
|
37
|
-
/* add a line to the markdown input chain
|
37
|
+
/* add a line to the markdown input chain, expanding tabs and
|
38
|
+
* noting the presence of special characters as we go.
|
38
39
|
*/
|
39
|
-
|
40
|
-
|
40
|
+
void
|
41
|
+
__mkd_enqueue(Document* a, Cstring *line)
|
41
42
|
{
|
42
43
|
Line *p = calloc(sizeof *p, 1);
|
43
44
|
unsigned char c;
|
@@ -60,6 +61,8 @@ queue(Document* a, Cstring *line)
|
|
60
61
|
} while ( ++xp % a->tabstop );
|
61
62
|
}
|
62
63
|
else if ( c >= ' ' ) {
|
64
|
+
if ( c == '|' )
|
65
|
+
p->flags |= PIPECHAR;
|
63
66
|
EXPAND(p->text) = c;
|
64
67
|
++xp;
|
65
68
|
}
|
@@ -72,8 +75,8 @@ queue(Document* a, Cstring *line)
|
|
72
75
|
|
73
76
|
/* trim leading blanks from a header line
|
74
77
|
*/
|
75
|
-
|
76
|
-
|
78
|
+
void
|
79
|
+
__mkd_header_dle(Line *p)
|
77
80
|
{
|
78
81
|
CLIP(p->text, 0, 1);
|
79
82
|
p->dle = mkd_firstnonblank(p);
|
@@ -88,7 +91,7 @@ Document *
|
|
88
91
|
populate(getc_func getc, void* ctx, int flags)
|
89
92
|
{
|
90
93
|
Cstring line;
|
91
|
-
Document *a =
|
94
|
+
Document *a = __mkd_new_Document();
|
92
95
|
int c;
|
93
96
|
int pandoc = 0;
|
94
97
|
|
@@ -106,7 +109,7 @@ populate(getc_func getc, void* ctx, int flags)
|
|
106
109
|
else
|
107
110
|
pandoc = EOF;
|
108
111
|
}
|
109
|
-
|
112
|
+
__mkd_enqueue(a, &line);
|
110
113
|
S(line) = 0;
|
111
114
|
}
|
112
115
|
else if ( isprint(c) || isspace(c) || (c & 0x80) )
|
@@ -114,7 +117,7 @@ populate(getc_func getc, void* ctx, int flags)
|
|
114
117
|
}
|
115
118
|
|
116
119
|
if ( S(line) )
|
117
|
-
|
120
|
+
__mkd_enqueue(a, &line);
|
118
121
|
|
119
122
|
DELETE(line);
|
120
123
|
|
@@ -125,9 +128,9 @@ populate(getc_func getc, void* ctx, int flags)
|
|
125
128
|
*/
|
126
129
|
Line *headers = T(a->content);
|
127
130
|
|
128
|
-
a->title = headers;
|
129
|
-
a->author= headers->next;
|
130
|
-
a->date = headers->next->next;
|
131
|
+
a->title = headers; __mkd_header_dle(a->title);
|
132
|
+
a->author= headers->next; __mkd_header_dle(a->author);
|
133
|
+
a->date = headers->next->next; __mkd_header_dle(a->date);
|
131
134
|
|
132
135
|
T(a->content) = headers->next->next->next;
|
133
136
|
}
|
@@ -147,14 +150,8 @@ mkd_in(FILE *f, DWORD flags)
|
|
147
150
|
|
148
151
|
/* return a single character out of a buffer
|
149
152
|
*/
|
150
|
-
|
151
|
-
|
152
|
-
int size; /* and how much is there? */
|
153
|
-
} ;
|
154
|
-
|
155
|
-
|
156
|
-
static int
|
157
|
-
strget(struct string_ctx *in)
|
153
|
+
int
|
154
|
+
__mkd_io_strget(struct string_stream *in)
|
158
155
|
{
|
159
156
|
if ( !in->size ) return EOF;
|
160
157
|
|
@@ -167,14 +164,14 @@ strget(struct string_ctx *in)
|
|
167
164
|
/* convert a block of text into a linked list
|
168
165
|
*/
|
169
166
|
Document *
|
170
|
-
mkd_string(char *buf, int len, DWORD flags)
|
167
|
+
mkd_string(const char *buf, int len, DWORD flags)
|
171
168
|
{
|
172
|
-
struct
|
169
|
+
struct string_stream about;
|
173
170
|
|
174
171
|
about.data = buf;
|
175
172
|
about.size = len;
|
176
173
|
|
177
|
-
return populate((getc_func)
|
174
|
+
return populate((getc_func)__mkd_io_strget, &about, flags & INPUT_MASK);
|
178
175
|
}
|
179
176
|
|
180
177
|
|
@@ -225,7 +222,7 @@ mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar,
|
|
225
222
|
|
226
223
|
size = mkd_line(s, len, &line, IS_LABEL);
|
227
224
|
|
228
|
-
if ( labelformat && size && !isalpha(line[0]) )
|
225
|
+
if ( labelformat && (size>0) && !isalpha(line[0]) )
|
229
226
|
(*outchar)('L',out);
|
230
227
|
for ( i=0; i < size ; i++ ) {
|
231
228
|
c = line[i];
|
@@ -233,7 +230,7 @@ mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar,
|
|
233
230
|
if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) )
|
234
231
|
(*outchar)(c, out);
|
235
232
|
else
|
236
|
-
(*outchar)('.',out);
|
233
|
+
(*outchar)('.', out);
|
237
234
|
}
|
238
235
|
else
|
239
236
|
(*outchar)(c,out);
|
@@ -251,7 +248,7 @@ mkd_parse_line(char *bfr, int size, MMIOT *f, int flags)
|
|
251
248
|
{
|
252
249
|
___mkd_initmmiot(f, 0);
|
253
250
|
f->flags = flags & USER_FLAGS;
|
254
|
-
___mkd_reparse(bfr, size, 0, f);
|
251
|
+
___mkd_reparse(bfr, size, 0, f, 0);
|
255
252
|
___mkd_emblock(f);
|
256
253
|
}
|
257
254
|
|
data/ext/mkdio.h
CHANGED
@@ -10,7 +10,12 @@ typedef unsigned int mkd_flag_t;
|
|
10
10
|
/* line builder for markdown()
|
11
11
|
*/
|
12
12
|
MMIOT *mkd_in(FILE*,mkd_flag_t); /* assemble input from a file */
|
13
|
-
MMIOT *mkd_string(char*,int,mkd_flag_t); /* assemble input from a buffer */
|
13
|
+
MMIOT *mkd_string(const char*,int,mkd_flag_t); /* assemble input from a buffer */
|
14
|
+
|
15
|
+
/* line builder for github flavoured markdown
|
16
|
+
*/
|
17
|
+
MMIOT *gfm_in(FILE*,mkd_flag_t); /* assemble input from a file */
|
18
|
+
MMIOT *gfm_string(const char*,int,mkd_flag_t); /* assemble input from a buffer */
|
14
19
|
|
15
20
|
void mkd_basename(MMIOT*,char*);
|
16
21
|
|
@@ -21,7 +26,7 @@ void mkd_shlib_destructor();
|
|
21
26
|
/* compilation, debugging, cleanup
|
22
27
|
*/
|
23
28
|
int mkd_compile(MMIOT*, mkd_flag_t);
|
24
|
-
|
29
|
+
void mkd_cleanup(MMIOT*);
|
25
30
|
|
26
31
|
/* markup functions
|
27
32
|
*/
|
@@ -84,6 +89,7 @@ void mkd_ref_prefix(MMIOT*, char*);
|
|
84
89
|
#define MKD_TAGTEXT 0x00000020 /* process text inside an html tag; no
|
85
90
|
* <em>, no <bold>, no html or [] expansion */
|
86
91
|
#define MKD_NO_EXT 0x00000040 /* don't allow pseudo-protocols */
|
92
|
+
#define MKD_NOEXT MKD_NO_EXT /* ^^^ (aliased for user convenience) */
|
87
93
|
#define MKD_CDATA 0x00000080 /* generate code for xml ![CDATA[...]] */
|
88
94
|
#define MKD_NOSUPERSCRIPT 0x00000100 /* no A^B */
|
89
95
|
#define MKD_NORELAXED 0x00000200 /* emphasis happens /everywhere/ */
|
@@ -99,6 +105,7 @@ void mkd_ref_prefix(MMIOT*, char*);
|
|
99
105
|
#define MKD_NOALPHALIST 0x00080000 /* forbid alphabetic lists */
|
100
106
|
#define MKD_NODLIST 0x00100000 /* forbid definition lists */
|
101
107
|
#define MKD_EXTRA_FOOTNOTE 0x00200000 /* enable markdown extra-style footnotes */
|
108
|
+
#define MKD_NOSTYLE 0x00400000 /* don't extract <style> blocks */
|
102
109
|
#define MKD_EMBED MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT
|
103
110
|
|
104
111
|
/* special flags for mkd_in() and mkd_string()
|
data/ext/mktags.c
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
/* block-level tags for passing html blocks through the blender
|
2
|
+
*/
|
3
|
+
#include <stdio.h>
|
4
|
+
|
5
|
+
#define __WITHOUT_AMALLOC 1
|
6
|
+
#include "cstring.h"
|
7
|
+
#include "tags.h"
|
8
|
+
|
9
|
+
STRING(struct kw) blocktags;
|
10
|
+
|
11
|
+
|
12
|
+
/* define a html block tag
|
13
|
+
*/
|
14
|
+
static void
|
15
|
+
define_one_tag(char *id, int selfclose)
|
16
|
+
{
|
17
|
+
struct kw *p = &EXPAND(blocktags);
|
18
|
+
|
19
|
+
p->id = id;
|
20
|
+
p->size = strlen(id);
|
21
|
+
p->selfclose = selfclose;
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
/* case insensitive string sort (for qsort() and bsearch() of block tags)
|
26
|
+
*/
|
27
|
+
static int
|
28
|
+
casort(struct kw *a, struct kw *b)
|
29
|
+
{
|
30
|
+
if ( a->size != b->size )
|
31
|
+
return a->size - b->size;
|
32
|
+
return strncasecmp(a->id, b->id, b->size);
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
/* stupid cast to make gcc shut up about the function types being
|
37
|
+
* passed into qsort() and bsearch()
|
38
|
+
*/
|
39
|
+
typedef int (*stfu)(const void*,const void*);
|
40
|
+
|
41
|
+
|
42
|
+
/* load in the standard collection of html tags that markdown supports
|
43
|
+
*/
|
44
|
+
main()
|
45
|
+
{
|
46
|
+
int i;
|
47
|
+
|
48
|
+
#define KW(x) define_one_tag(x, 0)
|
49
|
+
#define SC(x) define_one_tag(x, 1)
|
50
|
+
|
51
|
+
KW("STYLE");
|
52
|
+
KW("SCRIPT");
|
53
|
+
KW("ADDRESS");
|
54
|
+
KW("BDO");
|
55
|
+
KW("BLOCKQUOTE");
|
56
|
+
KW("CENTER");
|
57
|
+
KW("DFN");
|
58
|
+
KW("DIV");
|
59
|
+
KW("OBJECT");
|
60
|
+
KW("H1");
|
61
|
+
KW("H2");
|
62
|
+
KW("H3");
|
63
|
+
KW("H4");
|
64
|
+
KW("H5");
|
65
|
+
KW("H6");
|
66
|
+
KW("LISTING");
|
67
|
+
KW("NOBR");
|
68
|
+
KW("UL");
|
69
|
+
KW("P");
|
70
|
+
KW("OL");
|
71
|
+
KW("DL");
|
72
|
+
KW("PLAINTEXT");
|
73
|
+
KW("PRE");
|
74
|
+
KW("TABLE");
|
75
|
+
KW("WBR");
|
76
|
+
KW("XMP");
|
77
|
+
SC("HR");
|
78
|
+
KW("IFRAME");
|
79
|
+
KW("MAP");
|
80
|
+
|
81
|
+
qsort(T(blocktags), S(blocktags), sizeof(struct kw), (stfu)casort);
|
82
|
+
|
83
|
+
printf("static struct kw blocktags[] = {\n");
|
84
|
+
for (i=0; i < S(blocktags); i++)
|
85
|
+
printf(" { \"%s\", %d, %d },\n", T(blocktags)[i].id, T(blocktags)[i].size, T(blocktags)[i].selfclose );
|
86
|
+
printf("};\n\n");
|
87
|
+
printf("#define NR_blocktags %d\n", S(blocktags));
|
88
|
+
exit(0);
|
89
|
+
}
|
data/ext/pgm_options.c
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
/* markdown: a C implementation of John Gruber's Markdown markup language.
|
2
|
+
*
|
3
|
+
* Copyright (C) 2007-2011 David L Parsons.
|
4
|
+
* The redistribution terms are provided in the COPYRIGHT file that must
|
5
|
+
* be distributed with this source code.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <limits.h>
|
11
|
+
#include <unistd.h>
|
12
|
+
#include <mkdio.h>
|
13
|
+
#include <errno.h>
|
14
|
+
#include <string.h>
|
15
|
+
#include <stdarg.h>
|
16
|
+
|
17
|
+
#include "config.h"
|
18
|
+
#include "amalloc.h"
|
19
|
+
|
20
|
+
#if HAVE_LIBGEN_H
|
21
|
+
#include <libgen.h>
|
22
|
+
#endif
|
23
|
+
|
24
|
+
static struct _opt {
|
25
|
+
char *name;
|
26
|
+
char *desc;
|
27
|
+
int off;
|
28
|
+
int skip;
|
29
|
+
int sayenable;
|
30
|
+
mkd_flag_t flag;
|
31
|
+
} opts[] = {
|
32
|
+
{ "tabstop", "default (4-space) tabstops", 0, 0, 1, MKD_TABSTOP },
|
33
|
+
{ "image", "images", 1, 0, 1, MKD_NOIMAGE },
|
34
|
+
{ "links", "links", 1, 0, 1, MKD_NOLINKS },
|
35
|
+
{ "relax", "emphasis inside words", 1, 1, 1, MKD_STRICT },
|
36
|
+
{ "strict", "emphasis inside words", 0, 0, 1, MKD_STRICT },
|
37
|
+
{ "tables", "tables", 1, 0, 1, MKD_NOTABLES },
|
38
|
+
{ "header", "pandoc-style headers", 1, 0, 1, MKD_NOHEADER },
|
39
|
+
{ "html", "raw html", 1, 0, 1, MKD_NOHTML },
|
40
|
+
{ "ext", "extended protocols", 1, 0, 1, MKD_NO_EXT },
|
41
|
+
{ "cdata", "generate cdata", 0, 0, 0, MKD_CDATA },
|
42
|
+
{ "smarty", "smartypants", 1, 0, 1, MKD_NOPANTS },
|
43
|
+
{ "pants", "smartypants", 1, 1, 1, MKD_NOPANTS },
|
44
|
+
{ "toc", "tables of contents", 0, 0, 1, MKD_TOC },
|
45
|
+
{ "autolink", "autolinking", 0, 0, 1, MKD_AUTOLINK },
|
46
|
+
{ "safelink", "safe links", 0, 0, 1, MKD_SAFELINK },
|
47
|
+
{ "strikethrough", "strikethrough", 1, 0, 1, MKD_NOSTRIKETHROUGH },
|
48
|
+
{ "del", "strikethrough", 1, 1, 1, MKD_NOSTRIKETHROUGH },
|
49
|
+
{ "superscript", "superscript", 1, 0, 1, MKD_NOSUPERSCRIPT },
|
50
|
+
{ "emphasis", "emphasis inside words", 0, 0, 1, MKD_NORELAXED },
|
51
|
+
{ "divquote", ">%class% blockquotes", 1, 0, 1, MKD_NODIVQUOTE },
|
52
|
+
{ "alphalist", "alpha lists", 1, 0, 1, MKD_NOALPHALIST },
|
53
|
+
{ "definitionlist","definition lists", 1, 0, 1, MKD_NODLIST },
|
54
|
+
{ "1.0", "markdown 1.0 compatibility", 0, 0, 1, MKD_1_COMPAT },
|
55
|
+
{ "footnotes", "markdown extra footnotes", 0, 0, 1, MKD_EXTRA_FOOTNOTE },
|
56
|
+
{ "footnote", "markdown extra footnotes", 0, 1, 1, MKD_EXTRA_FOOTNOTE },
|
57
|
+
{ "style", "extract style blocks", 1, 0, 1, MKD_NOSTYLE },
|
58
|
+
} ;
|
59
|
+
|
60
|
+
#define NR(x) (sizeof x / sizeof x[0])
|
61
|
+
|
62
|
+
|
63
|
+
typedef int (*stfu)(const void *, const void *);
|
64
|
+
|
65
|
+
int
|
66
|
+
sort_by_name(struct _opt *a, struct _opt *b)
|
67
|
+
{
|
68
|
+
return strcmp(a->name,b->name);
|
69
|
+
}
|
70
|
+
|
71
|
+
int
|
72
|
+
sort_by_flag(struct _opt *a, struct _opt *b)
|
73
|
+
{
|
74
|
+
return a->flag - b->flag;
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
void
|
79
|
+
show_flags(int byname)
|
80
|
+
{
|
81
|
+
int i;
|
82
|
+
|
83
|
+
if ( byname ) {
|
84
|
+
qsort(opts, NR(opts), sizeof(opts[0]), (stfu)sort_by_name);
|
85
|
+
|
86
|
+
for (i=0; i < NR(opts); i++)
|
87
|
+
if ( ! opts[i].skip )
|
88
|
+
fprintf(stderr, "%16s : %s\n", opts[i].name, opts[i].desc);
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
qsort(opts, NR(opts), sizeof(opts[0]), (stfu)sort_by_flag);
|
92
|
+
|
93
|
+
for (i=0; i < NR(opts); i++)
|
94
|
+
if ( ! opts[i].skip ) {
|
95
|
+
fprintf(stderr, "%08lx : ", (long)opts[i].flag);
|
96
|
+
if ( opts[i].sayenable )
|
97
|
+
fprintf(stderr, opts[i].off ? "disable " : "enable ");
|
98
|
+
fprintf(stderr, "%s\n", opts[i].desc);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
int
|
105
|
+
set_flag(mkd_flag_t *flags, char *optionstring)
|
106
|
+
{
|
107
|
+
int i;
|
108
|
+
int enable;
|
109
|
+
char *arg;
|
110
|
+
|
111
|
+
for ( arg = strtok(optionstring, ","); arg; arg = strtok(NULL, ",") ) {
|
112
|
+
if ( *arg == '+' || *arg == '-' )
|
113
|
+
enable = (*arg++ == '+') ? 1 : 0;
|
114
|
+
else if ( strncasecmp(arg, "no", 2) == 0 ) {
|
115
|
+
arg += 2;
|
116
|
+
enable = 0;
|
117
|
+
}
|
118
|
+
else
|
119
|
+
enable = 1;
|
120
|
+
|
121
|
+
for ( i=0; i < NR(opts); i++ )
|
122
|
+
if ( strcasecmp(arg, opts[i].name) == 0 )
|
123
|
+
break;
|
124
|
+
|
125
|
+
if ( i < NR(opts) ) {
|
126
|
+
if ( opts[i].off )
|
127
|
+
enable = !enable;
|
128
|
+
|
129
|
+
if ( enable )
|
130
|
+
*flags |= opts[i].flag;
|
131
|
+
else
|
132
|
+
*flags &= ~opts[i].flag;
|
133
|
+
}
|
134
|
+
else
|
135
|
+
return 0;
|
136
|
+
}
|
137
|
+
return 1;
|
138
|
+
}
|