3. Sorg Data
All necessary data for sorg is encapsulated in a struct called sorg_d.
typedef struct {
<<sorg_data_contents>>
} sorg_d;
Sorg data is initialized with the function sorg_init.
void sorg_init(sorg_d *sorg) {
int i;
<<initialize_stuff>>
}
The current mode of the state machine is stored in a variable called
mode.
int mode;
By default, it is set to be none, which is the general markdown mode.
sorg->mode = MODE_NONE;
For logic for things such as paragraphs, sorg also keeps track of the
previous mode, called pmode.
int pmode;
Like mode, pmode is initialized to be MODE_NONE.
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
size_t pos;
size_t off;
size_t blksize;
sorg->pos = 0;
sorg->off = 0;
sorg->blksize = 0;
Section position is kept track of in an array of integers known as secpos.
#define SORG_MAXSEC 10
int secpos[SORG_MAXSEC];
Section numbers get all initialized to be zero.
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.
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.
sorg->depth = -1;
sorg->pdepth = -1;
prev | home | next