/* free the contents of a MMIOT, but leave the object alone.
 */
void
___mkd_freemmiot(MMIOT *f, void *footnotes)
{
    if ( f ) {
	DELETE(f->in);
	DELETE(f->out);
	DELETE(f->Q);
	if ( f->footnotes != footnotes )
	    ___mkd_freefootnotes(f);
	memset(f, 0, sizeof *f);
    }
}
Пример #2
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;
}