3. Sorg Data

All necessary data for sorg is encapsulated in a struct called sorg_d.

<<sorg_data>>=
typedef struct {
<<sorg_data_contents>>
} sorg_d;

Sorg data is initialized with the function sorg_init.

<<functions>>=
void sorg_init(sorg_d *sorg) {
    int i;
<<initialize_stuff>>
}

The current mode of the state machine is stored in a variable called mode.

<<sorg_data_contents>>=
int mode;

By default, it is set to be none, which is the general markdown mode.

<<initialize_stuff>>=
sorg->mode = MODE_NONE;

For logic for things such as paragraphs, sorg also keeps track of the previous mode, called pmode.

<<sorg_data_contents>>=
int pmode;

Like mode, pmode is initialized to be MODE_NONE.

<<initialize_stuff>>=
sorg->pmode = MODE_NONE;

Sorg internally keeps track of the current position (pos) in the line.

TODO: better words here. off: starting offset blksize: text block size

<<sorg_data_contents>>=
size_t pos;
size_t off;
size_t blksize;
<<initialize_stuff>>=
sorg->pos = 0;
sorg->off = 0;
sorg->blksize = 0;

Section position is kept track of in an array of integers known as secpos.

<<sorg_data_contents>>=
#define SORG_MAXSEC 10
int secpos[SORG_MAXSEC];

Section numbers get all initialized to be zero.

<<initialize_stuff>>=
for(i = 0; i < SORG_MAXSEC; i++) sorg->secpos[i] = 0;

The current section depth is kept track in an integer called depth. The previous depth is also recorded. This is needed for generating the table of contents with indentation.

<<sorg_data_contents>>=
int depth;
int pdepth;

depth and pdepth is set to be an initial value of -1. Functions aiming to read this value should do a bounds check before using this variable. Depth corresponds to array position in secpos, so be sure that the depth is in between 0 and SORG_MAXSEC.

<<initialize_stuff>>=
sorg->depth = -1;
sorg->pdepth = -1;



prev | home | next