summaryrefslogtreecommitdiff
path: root/bin/hoedown.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/hoedown.c')
-rw-r--r--bin/hoedown.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/bin/hoedown.c b/bin/hoedown.c
index 5aac21a..c0e5279 100644
--- a/bin/hoedown.c
+++ b/bin/hoedown.c
@@ -2,7 +2,7 @@
#include "html.h"
#include "common.h"
-/*#include <time.h>*/
+#include <time.h>
/* FEATURES INFO / DEFAULTS */
@@ -362,7 +362,7 @@ int
main(int argc, char **argv)
{
struct option_data data;
- /*struct timespec start, end;*/
+ clock_t t1, t2;
FILE *file = stdin;
hoedown_buffer *ib, *ob;
hoedown_renderer *renderer = NULL;
@@ -398,13 +398,9 @@ main(int argc, char **argv)
/* Read everything */
ib = hoedown_buffer_new(data.iunit);
- while (!feof(file)) {
- if (ferror(file)) {
- fprintf(stderr, "I/O errors found while reading input.\n");
- return 5;
- }
- hoedown_buffer_grow(ib, ib->size + data.iunit);
- ib->size += fread(ib->data + ib->size, 1, data.iunit, file);
+ if (hoedown_buffer_putf(ib, file)) {
+ fprintf(stderr, "I/O errors found while reading input.\n");
+ return 5;
}
if (file != stdin) fclose(file);
@@ -425,35 +421,39 @@ main(int argc, char **argv)
ob = hoedown_buffer_new(data.ounit);
document = hoedown_document_new(renderer, data.extensions, data.max_nesting);
- /*clock_gettime(CLOCK_MONOTONIC, &start);*/
+ t1 = clock();
hoedown_document_render(document, ob, ib->data, ib->size);
- /*clock_gettime(CLOCK_MONOTONIC, &end);*/
-
- /* Write the result to stdout */
- (void)fwrite(ob->data, 1, ob->size, stdout);
-
- /* Show rendering time */
- if (data.show_time) {
- /*TODO: enable this
- long long elapsed = (end.tv_sec - start.tv_sec)*1e9 + (end.tv_nsec - start.tv_nsec);
- if (elapsed < 1e9)
- fprintf(stderr, "Time spent on rendering: %.2f ms.\n", ((double)elapsed)/1e6);
- else
- fprintf(stderr, "Time spent on rendering: %.3f s.\n", ((double)elapsed)/1e9);
- */
- }
+ t2 = clock();
/* Cleanup */
hoedown_buffer_free(ib);
- hoedown_buffer_free(ob);
-
hoedown_document_free(document);
renderer_free(renderer);
+ /* Write the result to stdout */
+ (void)fwrite(ob->data, 1, ob->size, stdout);
+ hoedown_buffer_free(ob);
+
if (ferror(stdout)) {
fprintf(stderr, "I/O errors found while writing output.\n");
return 5;
}
+ /* Show rendering time */
+ if (data.show_time) {
+ double elapsed;
+
+ if (t1 == -1 || t2 == -1) {
+ fprintf(stderr, "Failed to get the time.\n");
+ return 1;
+ }
+
+ elapsed = (double)(t2 - t1) / CLOCKS_PER_SEC;
+ if (elapsed < 1)
+ fprintf(stderr, "Time spent on rendering: %7.2f ms.\n", elapsed*1e3);
+ else
+ fprintf(stderr, "Time spent on rendering: %6.3f s.\n", elapsed);
+ }
+
return 0;
}