2009-05-11 14:15:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999-2002, Darren Hiebert
|
2011-01-19 19:39:09 +00:00
|
|
|
* Copyright 2009-2011 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2009-05-11 14:15:00 +00:00
|
|
|
*
|
|
|
|
* This source code is released for free distribution under the terms of the
|
|
|
|
* GNU General Public License.
|
|
|
|
*
|
|
|
|
* Defines external interface to scope nesting levels for tags.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* INCLUDE FILES
|
|
|
|
*/
|
|
|
|
#include "general.h" /* must always come first */
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "nestlevel.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION DEFINITIONS
|
|
|
|
*/
|
|
|
|
|
2009-05-12 15:16:23 +00:00
|
|
|
extern NestingLevels *nestingLevelsNew(void)
|
2009-05-11 14:15:00 +00:00
|
|
|
{
|
|
|
|
NestingLevels *nls = xCalloc (1, NestingLevels);
|
|
|
|
return nls;
|
|
|
|
}
|
|
|
|
|
2009-05-12 15:16:23 +00:00
|
|
|
extern void nestingLevelsFree(NestingLevels *nls)
|
2009-05-11 14:15:00 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < nls->allocated; i++)
|
|
|
|
vStringDelete(nls->levels[i].name);
|
|
|
|
if (nls->levels) eFree(nls->levels);
|
|
|
|
eFree(nls);
|
|
|
|
}
|
|
|
|
|
2009-05-11 15:36:46 +00:00
|
|
|
extern void nestingLevelsPush(NestingLevels *nls,
|
|
|
|
const vString *name, int type)
|
|
|
|
{
|
|
|
|
NestingLevel *nl = NULL;
|
|
|
|
|
|
|
|
if (nls->n >= nls->allocated)
|
|
|
|
{
|
|
|
|
nls->allocated++;
|
|
|
|
nls->levels = xRealloc(nls->levels,
|
|
|
|
nls->allocated, NestingLevel);
|
|
|
|
nls->levels[nls->n].name = vStringNew();
|
|
|
|
}
|
|
|
|
nl = &nls->levels[nls->n];
|
|
|
|
nls->n++;
|
|
|
|
|
|
|
|
vStringCopy(nl->name, name);
|
|
|
|
nl->type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void nestingLevelsPop(NestingLevels *nls)
|
|
|
|
{
|
|
|
|
const NestingLevel *nl = nestingLevelsGetCurrent(nls);
|
|
|
|
|
|
|
|
Assert (nl != NULL);
|
|
|
|
vStringClear(nl->name);
|
|
|
|
nls->n--;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern NestingLevel *nestingLevelsGetCurrent(NestingLevels *nls)
|
|
|
|
{
|
|
|
|
Assert (nls != NULL);
|
|
|
|
|
|
|
|
if (nls->n < 1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return &nls->levels[nls->n - 1];
|
|
|
|
}
|
|
|
|
|
2009-05-11 14:15:00 +00:00
|
|
|
/* vi:set tabstop=4 shiftwidth=4: */
|