/* bye bye paragraph.
 */
void
___mkd_freeParagraph(Paragraph *p)
{
    if (p->next)
	___mkd_freeParagraph(p->next);
    if (p->down)
	___mkd_freeParagraph(p->down);
    if (p->text)
	___mkd_freeLines(p->text);
    if (p->ident)
	free(p->ident);
    free(p);
}
/* clean up everything allocated in __mkd_compile()
 */
void
mkd_cleanup(Document *doc)
{
    if ( doc && (doc->magic == VALID_DOCUMENT) ) {
	if ( doc->ctx ) {
	    ___mkd_freemmiot(doc->ctx, 0);
	    free(doc->ctx);
	}

	if ( doc->code) ___mkd_freeParagraph(doc->code);
	if ( doc->title) ___mkd_freeLine(doc->title);
	if ( doc->author) ___mkd_freeLine(doc->author);
	if ( doc->date) ___mkd_freeLine(doc->date);
	if ( T(doc->content) ) ___mkd_freeLines(T(doc->content));
	memset(doc, 0, sizeof doc[0]);
	free(doc);
    }
}
Beispiel #3
0
/*
 * prepare and compile `text`, returning a Paragraph tree.
 */
int
mkd_compile(Document *doc, DWORD flags)
{
    if ( !doc )
	return 0;

    flags &= USER_FLAGS;
    
    if ( doc->compiled ) {
	if ( doc->ctx->flags == flags )
	    return 1;
	else {
	    if ( doc->code)
		___mkd_freeParagraph(doc->code);
	    if ( doc->ctx->footnotes )
		___mkd_freefootnotes(doc->ctx);
	}
    }

    doc->compiled = 1;
    memset(doc->ctx, 0, sizeof(MMIOT) );
    doc->ctx->ref_prefix= doc->ref_prefix;
    doc->ctx->cb        = &(doc->cb);
    doc->ctx->flags     = flags;
    CREATE(doc->ctx->in);
    doc->ctx->footnotes = malloc(sizeof doc->ctx->footnotes[0]);
    doc->ctx->footnotes->reference = 0;
    CREATE(doc->ctx->footnotes->note);

    mkd_initialize();

    doc->code = compile_document(T(doc->content), doc->ctx);
    qsort(T(doc->ctx->footnotes->note), S(doc->ctx->footnotes->note),
		        sizeof T(doc->ctx->footnotes->note)[0],
			           (stfu)__mkd_footsort);
    memset(&doc->content, 0, sizeof doc->content);
    return 1;
}