Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/tool/jhton.c view on Meta::CPAN
// ****************************************************************************
// T A G T Y P E
//
// Given a non-null string that should be an HTML tag type, a pointer to a
// bool_t to return whether this is a closing tag, and a filename and line
// number for error reporting, look up the tag type in g_dntype[] and return
// its index. Error out if not found.
//
// As a special case, if presented with "!---" with any number of dashes, look
// for "!--".
FUNCTION int TagType(
char * Tag, // to look up.
bool_t * Pisclosing, // return flag: is a closing tag.
char * Filename, // for error reporting.
int Linenum) // for error reporting.
{
int dn_type; // to return.
char * mytag; // local variation.
assert( Tag != PCNULL);
assert(*Tag != CHNULL);
// Check for closing tag (yes, even for types that don't really allow it):
if ((*Pisclosing = (*Tag == '/'))) // (()) for gcc.
{
++Tag;
SKIPSPACE(Tag);
if (*Tag == CHNULL)
Error(ERREXIT, NOERRNO, FmtErrLineEnds, Filename, Linenum);
}
// Translate comment tag to known type:
mytag = (strncmp(Tag, "!--", 3) ? Tag : "!--"); // see above.
// Look up tag:
//
// Note: Main code already asserted dnt_type == dn_type for each entry.
for (dn_type = 0; TAG(dn_type) != PCNULL; ++dn_type)
if (strcmp(mytag, TAG(dn_type)) == 0) return(dn_type);
Error(ERREXIT, NOERRNO, FILELINE "Unrecognized HTML tag \"%s\"; "
"see program source file for recognized types; this is a "
"limited, special-purpose translator", Filename, Linenum, Tag);
/*NOTREACHED*/
return(0); // make some compilers happy.
} // TagType()
// ****************************************************************************
// A P P D O C N O D E
//
// Given a current docnode tree node, the input file line number, and
// g_Pdnhead, create a new docnode, append it to the tree in the right place,
// and return a pointer to it, with g_Pdnhead updated if required:
//
// * If empty tree, insert new as head of tree.
//
// * Otherwise if current node nests and is not closed, insert as its child.
//
// * Otherwise insert as a sibling of the current node.
//
// Note: Most HTML tags are non-singletons and hence nest, but if the nesting
// doesn't make sense, too bad, it's not detected, at least not here.
FUNCTION Pdn_t AppDocNode(
Pdn_t Pdn, // current docnode tree node.
int Linenum) // in input file.
{
// No current tree, insert first node:
if (g_Pdnhead == PDNNULL)
return(g_Pdnhead = NewDocNode(PDNNULL, Linenum));
// Insert new node as child, with parent set to current node:
if (NEST(Pdn->dn_type) && (! (Pdn->dn_closed)))
return((Pdn->dn_Pchild) = NewDocNode(Pdn, Linenum));
// Insert new node as sibling with same parent:
(Pdn->dn_Pnext) = NewDocNode(Pdn->dn_Pparent, Linenum);
(Pdn->dn_Pnext->dn_Pprev) = Pdn;
return(Pdn->dn_Pnext);
} // AppDocNode()
// ****************************************************************************
// N E W D O C N O D E
//
// Malloc() a new docnode and initialize its fields except dn_type, with error
// checking. Set its parent to the given value.
FUNCTION Pdn_t NewDocNode(
Pdn_t dn_Pparent, // parent to record.
int Linenum) // in input file.
{
Pdn_t Pdn = (Pdn_t) Malloc(sizeof(struct docnode));
(Pdn -> dn_linenum) = Linenum;
(Pdn -> dn_closed) = FALSE;
(Pdn -> dn_noemit) = FALSE;
(Pdn -> dn_bold) = FALSE;
(Pdn -> dn_text) = PCNULL;
(Pdn -> dn_Pprev) = PDNNULL;
(Pdn -> dn_Pnext) = PDNNULL;
(Pdn -> dn_Pparent) = dn_Pparent;
(Pdn -> dn_Pchild) = PDNNULL;
return(Pdn);
} // NewDocNode()
( run in 0.932 second using v1.01-cache-2.11-cpan-40ba7b3775d )