3. Top Level Struct

3.1. Struct Declaration

<<typedefs>>=
typedef struct weewiki_d weewiki_d;
<<structs>>=
struct weewiki_d {
<<contents>>
};

3.2. Contents

3.2.1. SQLite database

<<contents>>=
sqlite3 *db;
<<init>>=
ww->db = NULL;
<<clean>>=
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.

<<funcdefs>>=
#if defined(SQLITE3_H) || defined(_SQLITE3_H_)
sqlite3* weewiki_db(weewiki_d *ww);
#endif
<<functions>>=
sqlite3* weewiki_db(weewiki_d *ww)
{
    return ww->db;
}

3.2.2. Global filehandle

<<contents>>=
FILE *fp;
<<init>>=
ww->fp = stdout;
<<funcdefs>>=
FILE * weewiki_fp(weewiki_d *ww);
<<functions>>=
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.

<<contents>>=
void *ud;
<<init>>=
ww->ud = NULL;
<<funcdefs>>=
void * weewiki_ud(weewiki_d *ww);
void weewiki_ud_set(weewiki_d *ww, void *ud);
<<functions>>=
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.

<<contents>>=
void (*parse)(weewiki_d *, const char *, unsigned int);
<<init>>=
ww->parse = NULL;

Can be set using weewiki_parse_set.

<<funcdefs>>=
void weewiki_parse_set(weewiki_d *ww,
                       void (*parse)(weewiki_d *,
                                     const char *,
                                     unsigned int));
<<functions>>=
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).

<<contents>>=
void (*print)(weewiki_d *, const char *, unsigned int);
<<init>>=
ww->print = NULL;
<<funcdefs>>=
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));
<<functions>>=
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);
    }
}
<<functions>>=
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.

<<contents>>=
const char *name;
<<init>>=
ww->name = NULL;

Can be retrieved with weewiki_pgname.

<<funcdefs>>=
const char * weewiki_pgname(weewiki_d *ww);
<<functions>>=
const char * weewiki_pgname(weewiki_d *ww)
{
    return ww->name;
}

Set it indirectly with weewiki_pgname_set.

<<funcdefs>>=
void weewiki_pgname_set(weewiki_d *ww, const char *name);
<<functions>>=
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.

<<contents>>=
int is_server;
<<init>>=
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.

<<funcdefs>>=
void weewiki_is_server_set(weewiki_d *ww, int x);
int weewiki_is_server(weewiki_d *ww);
<<functions>>=
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

<<funcdefs>>=
void weewiki_init(weewiki_d *ww);
<<functions>>=
void weewiki_init(weewiki_d *ww)
{
<<init>>
}

3.4. Cleanup

<<funcdefs>>=
void weewiki_clean(weewiki_d *ww);
<<functions>>=
void weewiki_clean(weewiki_d *ww)
{
<<clean>>
}

3.5. Global Data Instance

To make integration with Janet easier, a global weewiki_dpointer is used.

For the janet standalone, a global variable is set and used by default.

<<global_data>>=
static weewiki_d iWeeWiki;
static weewiki_d *WeeWiki = &iWeeWiki;
<<funcdefs>>=
void weewiki_set(weewiki_d *ww);
weewiki_d *weewiki_get(void);
<<functions>>=
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.

<<funcdefs>>=
unsigned long weewiki_sizeof(void);
<<functions>>=
unsigned long weewiki_sizeof(void)
{
    return sizeof(weewiki_d);
}



prev | home | next