Skip to content

Commit b92c454

Browse files
author
Devin Torres
committed
Merge pull request vmg#116 from jmendeth/lanli-import
Import improvements from Lanli (and more things)
2 parents 7e5ba30 + 8c14212 commit b92c454

18 files changed

+485
-428
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CFLAGS = -g -O3 -Wall -Wextra -Wno-unused-parameter -Isrc
1+
CFLAGS = -g -O3 -Wall -Wextra -Wno-unused-parameter -Isrc -std=c99
22

33
ifneq ($(OS),Windows_NT)
44
CFLAGS += -fPIC

bin/hoedown.c

+3-27
Original file line numberDiff line numberDiff line change
@@ -401,20 +401,13 @@ main(int argc, char **argv)
401401

402402
/* reading everything */
403403
ib = hoedown_buffer_new(iunit);
404-
if (!ib) {
405-
fprintf(stderr, "Couldn't allocate input buffer.\n");
406-
return 4;
407-
}
408404

409405
while (!feof(in)) {
410406
if (ferror(in)) {
411407
fprintf(stderr, "I/O errors found while reading input.\n");
412408
return 5;
413409
}
414-
if (hoedown_buffer_grow(ib, ib->size + iunit) != HOEDOWN_BUF_OK) {
415-
fprintf(stderr, "Couldn't grow input buffer.\n");
416-
return 4;
417-
}
410+
hoedown_buffer_grow(ib, ib->size + iunit);
418411
ib->size += fread(ib->data + ib->size, 1, iunit, in);
419412
}
420413

@@ -423,8 +416,8 @@ main(int argc, char **argv)
423416

424417

425418
/* creating the renderer */
426-
hoedown_renderer *renderer;
427-
void (*renderer_free)(hoedown_renderer*);
419+
hoedown_renderer *renderer = NULL;
420+
void (*renderer_free)(hoedown_renderer*) = NULL;
428421

429422
switch (renderer_type) {
430423
case RENDERER_HTML:
@@ -439,29 +432,12 @@ main(int argc, char **argv)
439432
renderer = null_renderer_new();
440433
renderer_free = null_renderer_free;
441434
break;
442-
default:
443-
renderer = NULL;
444-
renderer_free = NULL;
445435
};
446436

447-
if (!renderer) {
448-
fprintf(stderr, "Couldn't allocate renderer.\n");
449-
return 4;
450-
}
451-
452437

453438
/* performing markdown rendering */
454439
ob = hoedown_buffer_new(ounit);
455-
if (!ob) {
456-
fprintf(stderr, "Couldn't allocate output buffer.\n");
457-
return 4;
458-
}
459-
460440
document = hoedown_document_new(renderer, extensions, max_nesting);
461-
if (!document) {
462-
fprintf(stderr, "Couldn't allocate document parser.\n");
463-
return 4;
464-
}
465441

466442
//clock_gettime(CLOCK_MONOTONIC, &start);
467443
hoedown_document_render(document, ob, ib->data, ib->size);

bin/smartypants.c

+1-12
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,13 @@ main(int argc, char **argv)
183183

184184
/* reading everything */
185185
ib = hoedown_buffer_new(iunit);
186-
if (!ib) {
187-
fprintf(stderr, "Couldn't allocate input buffer.\n");
188-
return 4;
189-
}
190186

191187
while (!feof(in)) {
192188
if (ferror(in)) {
193189
fprintf(stderr, "I/O errors found while reading input.\n");
194190
return 5;
195191
}
196-
if (hoedown_buffer_grow(ib, ib->size + iunit) != HOEDOWN_BUF_OK) {
197-
fprintf(stderr, "Couldn't grow input buffer.\n");
198-
return 4;
199-
}
192+
hoedown_buffer_grow(ib, ib->size + iunit);
200193
ib->size += fread(ib->data + ib->size, 1, iunit, in);
201194
}
202195

@@ -206,10 +199,6 @@ main(int argc, char **argv)
206199

207200
/* performing SmartyPants processing */
208201
ob = hoedown_buffer_new(ounit);
209-
if (!ob) {
210-
fprintf(stderr, "Couldn't allocate output buffer.\n");
211-
return 4;
212-
}
213202

214203
//clock_gettime(CLOCK_MONOTONIC, &start);
215204
hoedown_html_smartypants(ob, ib->data, ib->size);

hoedown.def

+15-9
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,36 @@ EXPORTS
44
hoedown_autolink__www
55
hoedown_autolink__email
66
hoedown_autolink__url
7-
hoedown_buffer_grow
7+
hoedown_buffer_init
88
hoedown_buffer_new
9-
hoedown_buffer_cstr
10-
hoedown_buffer_prefix
9+
hoedown_buffer_reset
10+
hoedown_buffer_grow
1111
hoedown_buffer_put
1212
hoedown_buffer_puts
1313
hoedown_buffer_putc
14-
hoedown_buffer_free
15-
hoedown_buffer_reset
14+
hoedown_buffer_set
15+
hoedown_buffer_sets
16+
hoedown_buffer_eq
17+
hoedown_buffer_eqs
18+
hoedown_buffer_prefix
1619
hoedown_buffer_slurp
20+
hoedown_buffer_cstr
1721
hoedown_buffer_printf
22+
hoedown_buffer_free
1823
hoedown_document_new
1924
hoedown_document_render
25+
hoedown_document_render_inline
2026
hoedown_document_free
21-
hoedown_escape_html
2227
hoedown_escape_href
28+
hoedown_escape_html
29+
hoedown_html_smartypants
2330
hoedown_html_is_tag
2431
hoedown_html_renderer_new
2532
hoedown_html_toc_renderer_new
2633
hoedown_html_renderer_free
27-
hoedown_html_smartypants
28-
hoedown_stack_free
34+
hoedown_stack_init
35+
hoedown_stack_uninit
2936
hoedown_stack_grow
30-
hoedown_stack_new
3137
hoedown_stack_push
3238
hoedown_stack_pop
3339
hoedown_stack_top

src/autolink.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@
1010
#endif
1111

1212
int
13-
hoedown_autolink_is_safe(const uint8_t *link, size_t link_len)
13+
hoedown_autolink_is_safe(const uint8_t *data, size_t size)
1414
{
1515
static const size_t valid_uris_count = 6;
1616
static const char *valid_uris[] = {
17-
"#", "/", "http://", "https://", "ftp://", "mailto:"
17+
"http://", "https://", "/", "#", "ftp://", "mailto:"
1818
};
19+
static const size_t valid_uris_size[] = { 7, 8, 1, 1, 6, 7 };
1920

20-
size_t i;
21-
22-
for (i = 0; i < valid_uris_count; ++i) {
23-
size_t len = strlen(valid_uris[i]);
21+
for (size_t i = 0; i < valid_uris_count; ++i) {
22+
size_t len = valid_uris_size[i];
2423

25-
if (link_len > len &&
26-
strncasecmp((char *)link, valid_uris[i], len) == 0 &&
27-
isalnum(link[len]))
24+
if (size > len &&
25+
strncasecmp((char *)data, valid_uris[i], len) == 0 &&
26+
isalnum(data[len]))
2827
return 1;
2928
}
3029

src/autolink.h

+24-13
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,35 @@
99
extern "C" {
1010
#endif
1111

12-
enum {
12+
13+
/*************
14+
* CONSTANTS *
15+
*************/
16+
17+
typedef enum hoedown_autolink_flags {
1318
HOEDOWN_AUTOLINK_SHORT_DOMAINS = (1 << 0)
14-
};
19+
} hoedown_autolink_flags;
20+
21+
22+
/*************
23+
* FUNCTIONS *
24+
*************/
25+
26+
/* hoedown_autolink_is_safe: verify that a URL has a safe protocol */
27+
int hoedown_autolink_is_safe(const uint8_t *data, size_t size);
1528

16-
int
17-
hoedown_autolink_is_safe(const uint8_t *link, size_t link_len);
29+
/* hoedown_autolink__www: search for the next www link in data */
30+
size_t hoedown_autolink__www(size_t *rewind_p, hoedown_buffer *link,
31+
uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);
1832

19-
size_t
20-
hoedown_autolink__www(size_t *rewind_p, hoedown_buffer *link,
21-
uint8_t *data, size_t offset, size_t size, unsigned int flags);
33+
/* hoedown_autolink__email: search for the next email in data */
34+
size_t hoedown_autolink__email(size_t *rewind_p, hoedown_buffer *link,
35+
uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);
2236

23-
size_t
24-
hoedown_autolink__email(size_t *rewind_p, hoedown_buffer *link,
25-
uint8_t *data, size_t offset, size_t size, unsigned int flags);
37+
/* hoedown_autolink__url: search for the next URL in data */
38+
size_t hoedown_autolink__url(size_t *rewind_p, hoedown_buffer *link,
39+
uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);
2640

27-
size_t
28-
hoedown_autolink__url(size_t *rewind_p, hoedown_buffer *link,
29-
uint8_t *data, size_t offset, size_t size, unsigned int flags);
3041

3142
#ifdef __cplusplus
3243
}

0 commit comments

Comments
 (0)