Add missing files.

This commit is contained in:
Black Hat 2019-02-02 20:59:27 +08:00
parent 495dbf2ba2
commit 232ae235a1
6 changed files with 4908 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
#ifndef CMARK_EXPORT_H
#define CMARK_EXPORT_H
#ifdef CMARK_STATIC_DEFINE
# define CMARK_EXPORT
# define CMARK_NO_EXPORT
#else
# ifndef CMARK_EXPORT
# ifdef libcmark_EXPORTS
/* We are building this library */
# define CMARK_EXPORT __attribute__((visibility("default")))
# else
/* We are using this library */
# define CMARK_EXPORT __attribute__((visibility("default")))
# endif
# endif
# ifndef CMARK_NO_EXPORT
# define CMARK_NO_EXPORT __attribute__((visibility("hidden")))
# endif
#endif
#ifndef CMARK_DEPRECATED
# define CMARK_DEPRECATED __attribute__ ((__deprecated__))
#endif
#ifndef CMARK_DEPRECATED_EXPORT
# define CMARK_DEPRECATED_EXPORT CMARK_EXPORT CMARK_DEPRECATED
#endif
#ifndef CMARK_DEPRECATED_NO_EXPORT
# define CMARK_DEPRECATED_NO_EXPORT CMARK_NO_EXPORT CMARK_DEPRECATED
#endif
#if 0 /* DEFINE_NO_DEPRECATED */
# ifndef CMARK_NO_DEPRECATED
# define CMARK_NO_DEPRECATED
# endif
#endif
#endif /* CMARK_EXPORT_H */

View File

@ -0,0 +1,7 @@
#ifndef CMARK_VERSION_H
#define CMARK_VERSION_H
#define CMARK_VERSION ((0 << 16) | (28 << 8) | 3)
#define CMARK_VERSION_STRING "0.28.3"
#endif

211
include/cmark/main.c Normal file
View File

@ -0,0 +1,211 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "config.h"
#include "memory.h"
#include "cmark.h"
#include "node.h"
#if defined(__OpenBSD__)
# include <sys/param.h>
# if OpenBSD >= 201605
# define USE_PLEDGE
# include <unistd.h>
# endif
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <io.h>
#include <fcntl.h>
#endif
typedef enum {
FORMAT_NONE,
FORMAT_HTML,
FORMAT_XML,
FORMAT_MAN,
FORMAT_COMMONMARK,
FORMAT_LATEX
} writer_format;
void print_usage() {
printf("Usage: cmark [FILE*]\n");
printf("Options:\n");
printf(" --to, -t FORMAT Specify output format (html, xml, man, "
"commonmark, latex)\n");
printf(" --width WIDTH Specify wrap width (default 0 = nowrap)\n");
printf(" --sourcepos Include source position attribute\n");
printf(" --hardbreaks Treat newlines as hard line breaks\n");
printf(" --nobreaks Render soft line breaks as spaces\n");
printf(" --safe Suppress raw HTML and dangerous URLs\n");
printf(" --smart Use smart punctuation\n");
printf(" --validate-utf8 Replace UTF-8 invalid sequences with U+FFFD\n");
printf(" --help, -h Print usage information\n");
printf(" --version Print version\n");
}
static void print_document(cmark_node *document, writer_format writer,
int options, int width) {
char *result;
switch (writer) {
case FORMAT_HTML:
result = cmark_render_html(document, options);
break;
case FORMAT_XML:
result = cmark_render_xml(document, options);
break;
case FORMAT_MAN:
result = cmark_render_man(document, options, width);
break;
case FORMAT_COMMONMARK:
result = cmark_render_commonmark(document, options, width);
break;
case FORMAT_LATEX:
result = cmark_render_latex(document, options, width);
break;
default:
fprintf(stderr, "Unknown format %d\n", writer);
exit(1);
}
printf("%s", result);
cmark_node_mem(document)->free(result);
}
int main(int argc, char *argv[]) {
int i, numfps = 0;
int *files;
char buffer[4096];
cmark_parser *parser;
size_t bytes;
cmark_node *document;
int width = 0;
char *unparsed;
writer_format writer = FORMAT_HTML;
int options = CMARK_OPT_DEFAULT;
#ifdef USE_PLEDGE
if (pledge("stdio rpath", NULL) != 0) {
perror("pledge");
return 1;
}
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
#endif
files = (int *)calloc(argc, sizeof(*files));
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--version") == 0) {
printf("cmark %s", CMARK_VERSION_STRING);
printf(" - CommonMark converter\n(C) 2014-2016 John MacFarlane\n");
exit(0);
} else if (strcmp(argv[i], "--sourcepos") == 0) {
options |= CMARK_OPT_SOURCEPOS;
} else if (strcmp(argv[i], "--hardbreaks") == 0) {
options |= CMARK_OPT_HARDBREAKS;
} else if (strcmp(argv[i], "--nobreaks") == 0) {
options |= CMARK_OPT_NOBREAKS;
} else if (strcmp(argv[i], "--smart") == 0) {
options |= CMARK_OPT_SMART;
} else if (strcmp(argv[i], "--safe") == 0) {
options |= CMARK_OPT_SAFE;
} else if (strcmp(argv[i], "--validate-utf8") == 0) {
options |= CMARK_OPT_VALIDATE_UTF8;
} else if ((strcmp(argv[i], "--help") == 0) ||
(strcmp(argv[i], "-h") == 0)) {
print_usage();
exit(0);
} else if (strcmp(argv[i], "--width") == 0) {
i += 1;
if (i < argc) {
width = (int)strtol(argv[i], &unparsed, 10);
if (unparsed && strlen(unparsed) > 0) {
fprintf(stderr, "failed parsing width '%s' at '%s'\n", argv[i],
unparsed);
exit(1);
}
} else {
fprintf(stderr, "--width requires an argument\n");
exit(1);
}
} else if ((strcmp(argv[i], "-t") == 0) || (strcmp(argv[i], "--to") == 0)) {
i += 1;
if (i < argc) {
if (strcmp(argv[i], "man") == 0) {
writer = FORMAT_MAN;
} else if (strcmp(argv[i], "html") == 0) {
writer = FORMAT_HTML;
} else if (strcmp(argv[i], "xml") == 0) {
writer = FORMAT_XML;
} else if (strcmp(argv[i], "commonmark") == 0) {
writer = FORMAT_COMMONMARK;
} else if (strcmp(argv[i], "latex") == 0) {
writer = FORMAT_LATEX;
} else {
fprintf(stderr, "Unknown format %s\n", argv[i]);
exit(1);
}
} else {
fprintf(stderr, "No argument provided for %s\n", argv[i - 1]);
exit(1);
}
} else if (*argv[i] == '-') {
print_usage();
exit(1);
} else { // treat as file argument
files[numfps++] = i;
}
}
parser = cmark_parser_new(options);
for (i = 0; i < numfps; i++) {
FILE *fp = fopen(argv[files[i]], "rb");
if (fp == NULL) {
fprintf(stderr, "Error opening file %s: %s\n", argv[files[i]],
strerror(errno));
exit(1);
}
while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
cmark_parser_feed(parser, buffer, bytes);
if (bytes < sizeof(buffer)) {
break;
}
}
fclose(fp);
}
if (numfps == 0) {
while ((bytes = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
cmark_parser_feed(parser, buffer, bytes);
if (bytes < sizeof(buffer)) {
break;
}
}
}
#ifdef USE_PLEDGE
if (pledge("stdio", NULL) != 0) {
perror("pledge");
return 1;
}
#endif
document = cmark_parser_finish(parser);
cmark_parser_free(parser);
print_document(document, writer, options, width);
cmark_node_free(document);
free(files);
return 0;
}

320
include/cmark/scanners.re Normal file
View File

@ -0,0 +1,320 @@
#include <stdlib.h>
#include "chunk.h"
#include "scanners.h"
bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c, bufsize_t offset)
{
bufsize_t res;
unsigned char *ptr = (unsigned char *)c->data;
if (ptr == NULL || offset > c->len) {
return 0;
} else {
unsigned char lim = ptr[c->len];
ptr[c->len] = '\0';
res = scanner(ptr + offset);
ptr[c->len] = lim;
}
return res;
}
/*!re2c
re2c:define:YYCTYPE = "unsigned char";
re2c:define:YYCURSOR = p;
re2c:define:YYMARKER = marker;
re2c:define:YYCTXMARKER = marker;
re2c:yyfill:enable = 0;
wordchar = [^\x00-\x20];
spacechar = [ \t\v\f\r\n];
reg_char = [^\\()\x00-\x20];
escaped_char = [\\][!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~-];
tagname = [A-Za-z][A-Za-z0-9-]*;
blocktagname = 'address'|'article'|'aside'|'base'|'basefont'|'blockquote'|'body'|'caption'|'center'|'col'|'colgroup'|'dd'|'details'|'dialog'|'dir'|'div'|'dl'|'dt'|'fieldset'|'figcaption'|'figure'|'footer'|'form'|'frame'|'frameset'|'h1'|'h2'|'h3'|'h4'|'h5'|'h6'|'head'|'header'|'hr'|'html'|'iframe'|'legend'|'li'|'link'|'main'|'menu'|'menuitem'|'nav'|'noframes'|'ol'|'optgroup'|'option'|'p'|'param'|'section'|'source'|'title'|'summary'|'table'|'tbody'|'td'|'tfoot'|'th'|'thead'|'title'|'tr'|'track'|'ul';
attributename = [a-zA-Z_:][a-zA-Z0-9:._-]*;
unquotedvalue = [^ \t\r\n\v\f"'=<>`\x00]+;
singlequotedvalue = ['][^'\x00]*['];
doublequotedvalue = ["][^"\x00]*["];
attributevalue = unquotedvalue | singlequotedvalue | doublequotedvalue;
attributevaluespec = spacechar* [=] spacechar* attributevalue;
attribute = spacechar+ attributename attributevaluespec?;
opentag = tagname attribute* spacechar* [/]? [>];
closetag = [/] tagname spacechar* [>];
htmlcomment = "!---->" | ("!--" ([-]? [^\x00>-]) ([-]? [^\x00-])* "-->");
processinginstruction = "?" ([^?>\x00]+ | [?][^>\x00] | [>])* "?>";
declaration = "!" [A-Z]+ spacechar+ [^>\x00]* ">";
cdata = "![CDATA[" ([^\]\x00]+ | "]" [^\]\x00] | "]]" [^>\x00])* "]]>";
htmltag = opentag | closetag | htmlcomment | processinginstruction |
declaration | cdata;
in_parens_nosp = [(] (reg_char|escaped_char|[\\])* [)];
in_double_quotes = ["] (escaped_char|[^"\x00])* ["];
in_single_quotes = ['] (escaped_char|[^'\x00])* ['];
in_parens = [(] (escaped_char|[^)\x00])* [)];
scheme = [A-Za-z][A-Za-z0-9.+-]{1,31};
*/
// Try to match a scheme including colon.
bufsize_t _scan_scheme(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
scheme [:] { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match URI autolink after first <, returning number of chars matched.
bufsize_t _scan_autolink_uri(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
scheme [:][^\x00-\x20<>]*[>] { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match email autolink after first <, returning num of chars matched.
bufsize_t _scan_autolink_email(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+
[@]
[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?
([.][a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*
[>] { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match an HTML tag after first <, returning num of chars matched.
bufsize_t _scan_html_tag(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
htmltag { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match an HTML block tag start line, returning
// an integer code for the type of block (1-6, matching the spec).
// #7 is handled by a separate function, below.
bufsize_t _scan_html_block_start(const unsigned char *p)
{
const unsigned char *marker = NULL;
/*!re2c
[<] ('script'|'pre'|'style') (spacechar | [>]) { return 1; }
'<!--' { return 2; }
'<?' { return 3; }
'<!' [A-Z] { return 4; }
'<![CDATA[' { return 5; }
[<] [/]? blocktagname (spacechar | [/]? [>]) { return 6; }
* { return 0; }
*/
}
// Try to match an HTML block tag start line of type 7, returning
// 7 if successful, 0 if not.
bufsize_t _scan_html_block_start_7(const unsigned char *p)
{
const unsigned char *marker = NULL;
/*!re2c
[<] (opentag | closetag) [\t\n\f ]* [\r\n] { return 7; }
* { return 0; }
*/
}
// Try to match an HTML block end line of type 1
bufsize_t _scan_html_block_end_1(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[^\n\x00]* [<] [/] ('script'|'pre'|'style') [>] { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match an HTML block end line of type 2
bufsize_t _scan_html_block_end_2(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[^\n\x00]* '-->' { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match an HTML block end line of type 3
bufsize_t _scan_html_block_end_3(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[^\n\x00]* '?>' { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match an HTML block end line of type 4
bufsize_t _scan_html_block_end_4(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[^\n\x00]* '>' { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match an HTML block end line of type 5
bufsize_t _scan_html_block_end_5(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[^\n\x00]* ']]>' { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Try to match a link title (in single quotes, in double quotes, or
// in parentheses), returning number of chars matched. Allow one
// level of internal nesting (quotes within quotes).
bufsize_t _scan_link_title(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
["] (escaped_char|[^"\x00])* ["] { return (bufsize_t)(p - start); }
['] (escaped_char|[^'\x00])* ['] { return (bufsize_t)(p - start); }
[(] (escaped_char|[^)\x00])* [)] { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Match space characters, including newlines.
bufsize_t _scan_spacechars(const unsigned char *p)
{
const unsigned char *start = p; \
/*!re2c
[ \t\v\f\r\n]+ { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Match ATX heading start.
bufsize_t _scan_atx_heading_start(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[#]{1,6} ([ \t]+|[\r\n]) { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Match setext heading line. Return 1 for level-1 heading,
// 2 for level-2, 0 for no match.
bufsize_t _scan_setext_heading_line(const unsigned char *p)
{
const unsigned char *marker = NULL;
/*!re2c
[=]+ [ \t]* [\r\n] { return 1; }
[-]+ [ \t]* [\r\n] { return 2; }
* { return 0; }
*/
}
// Scan a thematic break line: "...three or more hyphens, asterisks,
// or underscores on a line by themselves. If you wish, you may use
// spaces between the hyphens or asterisks."
bufsize_t _scan_thematic_break(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
([*][ \t]*){3,} [ \t]* [\r\n] { return (bufsize_t)(p - start); }
([_][ \t]*){3,} [ \t]* [\r\n] { return (bufsize_t)(p - start); }
([-][ \t]*){3,} [ \t]* [\r\n] { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Scan an opening code fence.
bufsize_t _scan_open_code_fence(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[`]{3,} / [^`\r\n\x00]*[\r\n] { return (bufsize_t)(p - start); }
[~]{3,} / [^\r\n\x00]*[\r\n] { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Scan a closing code fence with length at least len.
bufsize_t _scan_close_code_fence(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[`]{3,} / [ \t]*[\r\n] { return (bufsize_t)(p - start); }
[~]{3,} / [ \t]*[\r\n] { return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Scans an entity.
// Returns number of chars matched.
bufsize_t _scan_entity(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
[&] ([#] ([Xx][A-Fa-f0-9]{1,6}|[0-9]{1,7}) |[A-Za-z][A-Za-z0-9]{1,31} ) [;]
{ return (bufsize_t)(p - start); }
* { return 0; }
*/
}
// Returns positive value if a URL begins in a way that is potentially
// dangerous, with javascript:, vbscript:, file:, or data:, otherwise 0.
bufsize_t _scan_dangerous_url(const unsigned char *p)
{
const unsigned char *marker = NULL;
const unsigned char *start = p;
/*!re2c
'data:image/' ('png'|'gif'|'jpeg'|'webp') { return 0; }
'javascript:' | 'vbscript:' | 'file:' | 'data:' { return (bufsize_t)(p - start); }
* { return 0; }
*/
}

View File

@ -48,6 +48,7 @@ $$USE_SYSTEM_CMARK {
include/cmark/chunk.h \
include/cmark/cmark.h \
include/cmark/cmark_ctype.h \
include/cmark/cmark_export.h \
include/cmark/config.h \
include/cmark/houdini.h \
include/cmark/inlines.h \