5. Main Interface
Orgparse is a callback interface. These functions will handle the various parts of the org file.
5.1. Struct
5.1.1. Declaration
typedef struct orgparse orgparse;
struct orgparse {
<<interface>>
};
5.1.2. Init
void orgparse_init(orgparse *op);
void orgparse_init(orgparse *op)
{
<<init>>
}
5.1.3. Size
size_t orgparse_size(void);
size_t orgparse_size(void)
{
return sizeof(orgparse);
}
5.2. Callbacks
All callbacks have the same first 3 arguments: a generic pointer, the string, and the length of the string.
5.2.1. Header
An org header. In addition to the header name, also supplies the header level.
typedef void (*orgparse_header)(void *,
const char *,
size_t,
int);
orgparse_header header;
op->header = NULL;
void orgparse_set_header(orgparse *op, orgparse_header f);
void orgparse_set_header(orgparse *op, orgparse_header f)
{
op->header = f;
}
5.2.2. Text
This function is anything that isn't formatted text.
typedef void (*orgparse_text)(void *,
const char *,
size_t);
orgparse_text text;
op->text = NULL;
void orgparse_set_text(orgparse *op, orgparse_text f);
void orgparse_set_text(orgparse *op, orgparse_text f)
{
op->text = f;
}
5.2.3. Code
Text that is defined inside the codeblock tags.
orgparse_text code;
op->code = NULL;
void orgparse_set_code(orgparse *op, orgparse_text f);
void orgparse_set_code(orgparse *op, orgparse_text f)
{
op->code = f;
}
5.2.4. Bold
Text that is defined inside the bold tags.
orgparse_text bold;
op->bold = NULL;
void orgparse_set_bold(orgparse *op, orgparse_text f);
void orgparse_set_bold(orgparse *op, orgparse_text f)
{
op->bold = f;
}
5.2.5. Italic
Text that is defined inside the italic tags.
orgparse_text italic;
op->italic = NULL;
void orgparse_set_italic(orgparse *op, orgparse_text f);
void orgparse_set_italic(orgparse *op, orgparse_text f)
{
op->italic = f;
}
5.2.6. Underline
Text that is contained inside the tags.
orgparse_text underline;
op->underline = NULL;
void orgparse_set_underline(orgparse *op, orgparse_text f);
void orgparse_set_underline(orgparse *op, orgparse_text f)
{
op->underline = f;
}
5.2.7. Code Block
orgparse_text codeblock;
op->codeblock = NULL;
void orgparse_set_codeblock(orgparse *op, orgparse_text f);
void orgparse_set_codeblock(orgparse *op, orgparse_text f)
{
op->codeblock = f;
}
5.2.8. Aux
A special non-org tag, used for interpolated code in tags @!and !@.
orgparse_text aux;
op->aux = NULL;
void orgparse_set_aux(orgparse *op, orgparse_text f);
void orgparse_set_aux(orgparse *op, orgparse_text f)
{
op->aux = f;
}
5.2.9. Newline
The newline callback gets called anytime there is an empty
line, which means an explicit line break is needed.
For convenience, the orgparse_text callback is used,
though the arguments will be unused and set to NULL.
orgparse_text newline;
op->newline = NULL;
void orgparse_set_newline(orgparse *op, orgparse_text f);
void orgparse_set_newline(orgparse *op, orgparse_text f)
{
op->newline = f;
}
5.2.10. Name
orgparse_text name;
op->name = NULL;
void orgparse_set_name(orgparse *op, orgparse_text f);
void orgparse_set_name(orgparse *op, orgparse_text f)
{
op->name = f;
}
5.2.11. Title
orgparse_text title;
op->title = NULL;
void orgparse_set_title(orgparse *op, orgparse_text f);
void orgparse_set_title(orgparse *op, orgparse_text f)
{
op->title = f;
}
5.2.12. Link
typedef void (*orgparse_link)(void *,
const char *,
size_t,
const char *,
size_t);
orgparse_link link;
op->link = NULL;
void orgparse_set_link(orgparse *op, orgparse_link f);
void orgparse_set_link(orgparse *op, orgparse_link f)
{
op->link = f;
}
5.2.13. Paragraph
The pargraph callback gets called anytime a paragraph block starts or end. For HTML generation, this will be in charge of generating p-tags.
A paragraph starts when a new text block begins, and ends with a line break, or major mode change (such as for a code block or header).
typedef void (*orgparse_pgrph)(void *, int);
orgparse_pgrph pgrph;
op->pgrph = NULL;
void orgparse_set_pgrph(orgparse *op, orgparse_pgrph f);
void orgparse_set_pgrph(orgparse *op, orgparse_pgrph f)
{
op->pgrph = f;
}
A paragraph begins with orgparse_pgrph_begin.
A paragraph ends with orgparse_pgrph_end.
Note that neither of these functions actually check to see
if they are supposed to be beginning or ending. That logic
is done elsewhere.
void orgparse_pgrph_begin(orgparse *op, void *ud);
void orgparse_pgrph_end(orgparse *op, void *ud);
void orgparse_pgrph_begin(orgparse *op, void *ud)
{
if (op->pgrph != NULL) {
op->pgrph(ud, 0);
}
}
void orgparse_pgrph_end(orgparse *op, void *ud)
{
if (op->pgrph != NULL) {
op->pgrph(ud, 1);
}
}
Paragraphs do not end at the end of a file. It will need to
be ended explicitely. This used to be done with a function
called orgparse_wrapup, which worked by checking a return
flag and adding a paragraph. This ended up being too
simplistic and limiting, and has since been removed..
A new version of orgparse_wrapup is used, this time taking
in an orgparse_state variable. We'll call it
orgparse_end.
This was created because the single rc flag (txtmode) alone was giving some false positives, and rogue paragraph ends were happening.
This new function checks both the txtmodeand newline flags. A paragraph end will only happen when
the newline flag is not set.
void orgparse_end(orgparse *op,
void *ud,
orgparse_state *state);
void orgparse_end(orgparse *op,
void *ud,
orgparse_state *state)
{
int rc;
rc =
state->flags->txtmode &&
state->flags->newline == 0;
if (rc) {
orgparse_pgrph_end(op, ud);
}
}
prev | home | next