3. Top Level Struct
3.1. Struct Declaration
typedef struct weewiki_d weewiki_d;
struct weewiki_d {
<<contents>>
};
3.2. Contents
3.2.1. SQLite database
sqlite3 *db;
ww->db = NULL;
if (ww->db != NULL) {
weewiki_close(ww);
}
The function weewiki_db
will only be included if the
SQLite header is included as well. The janet interface for
instance, is not using this so why bother including it.
Well now. It would seem that the SQLITE3 header file that
ships with OSX uses the header guard _SQLITE3_H_
. This was
causing some warnings to happen. Wonder which bright spark
at Apple decided that was a good idea.
So now, thanks to Apple, I have to complicate things and add in some extra logic into what was already halfway to becoming a bad idea.
#if defined(SQLITE3_H) || defined(_SQLITE3_H_)
sqlite3* weewiki_db(weewiki_d *ww);
#endif
sqlite3* weewiki_db(weewiki_d *ww)
{
return ww->db;
}
3.2.2. Global filehandle
FILE *fp;
ww->fp = stdout;
FILE * weewiki_fp(weewiki_d *ww);
FILE * weewiki_fp(weewiki_d *ww)
{
if (ww == NULL) return stdout;
else return ww->fp;
}
3.2.3. Global User Data
Used for the exporter org parser now, but will eventually be utilized for the server parser.
void *ud;
ww->ud = NULL;
void * weewiki_ud(weewiki_d *ww);
void weewiki_ud_set(weewiki_d *ww, void *ud);
void * weewiki_ud(weewiki_d *ww)
{
return ww->ud;
}
void weewiki_ud_set(weewiki_d *ww, void *ud)
{
ww->ud = ud;
}
3.2.4. Global Parser Callback
Used in particular by Janet. Takes in weewiki data, text, and text size.
void (*parse)(weewiki_d *, const char *, unsigned int);
ww->parse = NULL;
Can be set using weewiki_parse_set
.
void weewiki_parse_set(weewiki_d *ww,
void (*parse)(weewiki_d *,
const char *,
unsigned int));
void weewiki_parse_set(weewiki_d *ww,
void (*parse)(weewiki_d *,
const char *,
unsigned int))
{
ww->parse = parse;
}
3.2.5. Global Printer Callback
This one is used anytime Janet wishes to print something directly (usually HTML).
void (*print)(weewiki_d *, const char *, unsigned int);
ww->print = NULL;
void weewiki_print(weewiki_d *ww,
const char *str,
unsigned int sz);
void weewiki_print_set(weewiki_d *ww,
void (*print)(weewiki_d *,
const char *,
unsigned int));
void weewiki_print(weewiki_d *ww,
const char *str,
unsigned int sz)
{
if (ww->print == NULL) {
FILE *f;
int i;
f = ww->fp;
for (i = 0; i < sz; ++i) {
putc(str[i], f);
}
f = weewiki_fp(ww);
} else {
ww->print(ww, str, sz);
}
}
void weewiki_print_set(weewiki_d *ww,
void (*print)(weewiki_d *,
const char *,
unsigned int))
{
ww->print = print;
}
3.2.6. Global Page Name
Stores name of current page being parsed.
const char *name;
ww->name = NULL;
Can be retrieved with weewiki_pgname
.
const char * weewiki_pgname(weewiki_d *ww);
const char * weewiki_pgname(weewiki_d *ww)
{
return ww->name;
}
Set it indirectly with weewiki_pgname_set
.
void weewiki_pgname_set(weewiki_d *ww, const char *name);
void weewiki_pgname_set(weewiki_d *ww, const char *name)
{
ww->name = name;
}
3.2.7. Server Flag
The variable is_server
is a boolean variable used
to determine if weewiki is being used as a weewiki server
or not. 1 is true, 0 is false.
int is_server;
weewiki_is_server_set(ww, 0);
It is false by default,
and can be set with weewiki_is_server_set
and
the value is retrieved weewiki_is_server
.
void weewiki_is_server_set(weewiki_d *ww, int x);
int weewiki_is_server(weewiki_d *ww);
void weewiki_is_server_set(weewiki_d *ww, int is_server)
{
ww->is_server = is_server;
}
int weewiki_is_server(weewiki_d *ww)
{
return ww->is_server;
}
3.3. Init
void weewiki_init(weewiki_d *ww);
void weewiki_init(weewiki_d *ww)
{
<<init>>
}
3.4. Cleanup
void weewiki_clean(weewiki_d *ww);
void weewiki_clean(weewiki_d *ww)
{
<<clean>>
}
3.5. Global Data Instance
To make integration with Janet easier, a global weewiki_d
pointer is used.
For the janet standalone, a global variable is set and used by default.
static weewiki_d iWeeWiki;
static weewiki_d *WeeWiki = &iWeeWiki;
void weewiki_set(weewiki_d *ww);
weewiki_d *weewiki_get(void);
void weewiki_set(weewiki_d *ww)
{
WeeWiki = ww;
}
weewiki_d *weewiki_get(void)
{
return WeeWiki;
}
3.6. Struct Size
The struct size can be found with weewiki_sizeof
. Useful
when dealing with weewiki as an opaque struct.
unsigned long weewiki_sizeof(void);
unsigned long weewiki_sizeof(void)
{
return sizeof(weewiki_d);
}
prev | home | next