2011-05-06 17:29:41 +00:00
|
|
|
#include "html.h"
|
2011-05-05 14:47:37 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define READ_UNIT 1024
|
|
|
|
#define OUTPUT_UNIT 64
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2013-09-20 06:09:52 +00:00
|
|
|
struct hoedown_buffer *ib, *ob;
|
2011-05-05 14:47:37 +00:00
|
|
|
FILE *in = stdin;
|
|
|
|
|
|
|
|
/* opening the file if given from the command line */
|
|
|
|
if (argc > 1) {
|
|
|
|
in = fopen(argv[1], "r");
|
|
|
|
if (!in) {
|
2013-09-21 13:29:41 +00:00
|
|
|
fprintf(stderr, "Unable to open input file \"%s\": %s\n", argv[1], strerror(errno));
|
2011-05-05 14:47:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reading everything */
|
2013-09-20 06:09:52 +00:00
|
|
|
ib = hoedown_buffer_new(READ_UNIT);
|
2013-09-21 13:20:56 +00:00
|
|
|
while (!feof(in) && !ferror(in)) {
|
2013-09-20 06:09:52 +00:00
|
|
|
hoedown_buffer_grow(ib, ib->size + READ_UNIT);
|
2013-09-21 13:20:56 +00:00
|
|
|
ib->size += fread(ib->data + ib->size, 1, READ_UNIT, in);
|
2011-05-05 14:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (in != stdin)
|
|
|
|
fclose(in);
|
|
|
|
|
2013-09-20 17:06:25 +00:00
|
|
|
/* performing SmartyPants parsing */
|
2013-09-20 06:09:52 +00:00
|
|
|
ob = hoedown_buffer_new(OUTPUT_UNIT);
|
2011-05-05 14:47:37 +00:00
|
|
|
|
2013-09-20 06:09:52 +00:00
|
|
|
hoedown_html_smartypants(ob, ib->data, ib->size);
|
2011-05-05 14:47:37 +00:00
|
|
|
|
|
|
|
/* writing the result to stdout */
|
2011-11-18 03:31:29 +00:00
|
|
|
(void)fwrite(ob->data, 1, ob->size, stdout);
|
2011-05-05 14:47:37 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2013-09-20 06:09:52 +00:00
|
|
|
hoedown_buffer_release(ib);
|
|
|
|
hoedown_buffer_release(ob);
|
2011-05-05 14:47:37 +00:00
|
|
|
|
2013-09-21 13:29:41 +00:00
|
|
|
return ferror(stdout);
|
2011-05-05 14:47:37 +00:00
|
|
|
}
|