[BACK]Return to node.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / docbook2mdoc

Diff for /docbook2mdoc/node.c between version 1.4 and 1.9

version 1.4, 2019/04/07 17:00:56 version 1.9, 2019/04/12 04:39:24
Line 29  static const char *const attrkeys[ATTRKEY__MAX] = {
Line 29  static const char *const attrkeys[ATTRKEY__MAX] = {
         "class",          "class",
         "close",          "close",
         "cols",          "cols",
           "DEFINITION",
         "endterm",          "endterm",
           "href",
         "id",          "id",
         "linkend",          "linkend",
           "NAME",
         "open",          "open",
           "PUBLIC",
         "rep",          "rep",
           "SYSTEM",
         "url",          "url",
         "xlink:href"          "xlink:href"
 };  };
Line 69  attrval_parse(const char *name)
Line 74  attrval_parse(const char *name)
         return val;          return val;
 }  }
   
   struct pnode *
   pnode_alloc(struct pnode *np)
   {
           struct pnode    *n;
   
           if ((n = calloc(1, sizeof(*n))) != NULL) {
                   TAILQ_INIT(&n->childq);
                   TAILQ_INIT(&n->attrq);
                   if ((n->parent = np) != NULL)
                           TAILQ_INSERT_TAIL(&np->childq, n, child);
           }
           return n;
   }
   
 /*  /*
  * Recursively free a node (NULL is ok).   * Recursively free a node (NULL is ok).
  */   */
 static void  static void
 pnode_free(struct pnode *pn)  pnode_free(struct pnode *n)
 {  {
         struct pnode    *pch;          struct pnode    *nc;
         struct pattr    *ap;          struct pattr    *a;
   
         if (pn == NULL)          if (n == NULL)
                 return;                  return;
   
         while ((pch = TAILQ_FIRST(&pn->childq)) != NULL) {          while ((nc = TAILQ_FIRST(&n->childq)) != NULL) {
                 TAILQ_REMOVE(&pn->childq, pch, child);                  TAILQ_REMOVE(&n->childq, nc, child);
                 pnode_free(pch);                  pnode_free(nc);
         }          }
         while ((ap = TAILQ_FIRST(&pn->attrq)) != NULL) {          while ((a = TAILQ_FIRST(&n->attrq)) != NULL) {
                 TAILQ_REMOVE(&pn->attrq, ap, child);                  TAILQ_REMOVE(&n->attrq, a, child);
                 free(ap->rawval);                  free(a->rawval);
                 free(ap);                  free(a);
         }          }
         free(pn->real);          free(n->b);
         free(pn);          free(n);
 }  }
   
 /*  /*
  * Unlink a node from its parent and pnode_free() it.   * Unlink a node from its parent and pnode_free() it.
  */   */
 void  void
 pnode_unlink(struct pnode *pn)  pnode_unlink(struct pnode *n)
 {  {
         if (pn == NULL)          if (n == NULL)
                 return;                  return;
         if (pn->parent != NULL)          if (n->parent != NULL)
                 TAILQ_REMOVE(&pn->parent->childq, pn, child);                  TAILQ_REMOVE(&n->parent->childq, n, child);
         pnode_free(pn);          pnode_free(n);
 }  }
   
 /*  /*
  * Unlink all children of a node and pnode_free() them.   * Unlink all children of a node and pnode_free() them.
  */   */
 void  void
 pnode_unlinksub(struct pnode *pn)  pnode_unlinksub(struct pnode *n)
 {  {
         while (TAILQ_EMPTY(&pn->childq) == 0)          while (TAILQ_EMPTY(&n->childq) == 0)
                 pnode_unlink(TAILQ_FIRST(&pn->childq));                  pnode_unlink(TAILQ_FIRST(&n->childq));
 }  }
   
 /*  /*
Line 122  pnode_unlinksub(struct pnode *pn)
Line 141  pnode_unlinksub(struct pnode *pn)
  * Return ATTRVAL__MAX if the node has no such attribute.   * Return ATTRVAL__MAX if the node has no such attribute.
  */   */
 enum attrval  enum attrval
 pnode_getattr(struct pnode *pn, enum attrkey key)  pnode_getattr(struct pnode *n, enum attrkey key)
 {  {
         struct pattr    *ap;          struct pattr    *a;
   
         if (pn == NULL)          if (n == NULL)
                 return ATTRVAL__MAX;                  return ATTRVAL__MAX;
         TAILQ_FOREACH(ap, &pn->attrq, child)          TAILQ_FOREACH(a, &n->attrq, child)
                 if (ap->key == key)                  if (a->key == key)
                         return ap->val;                          return a->val;
         return ATTRVAL__MAX;          return ATTRVAL__MAX;
 }  }
   
Line 139  pnode_getattr(struct pnode *pn, enum attrkey key)
Line 158  pnode_getattr(struct pnode *pn, enum attrkey key)
  * Return defval if the node has no such attribute.   * Return defval if the node has no such attribute.
  */   */
 const char *  const char *
 pnode_getattr_raw(struct pnode *pn, enum attrkey key, const char *defval)  pnode_getattr_raw(struct pnode *n, enum attrkey key, const char *defval)
 {  {
         struct pattr    *ap;          struct pattr    *a;
   
         if (pn == NULL)          if (n == NULL)
                 return defval;                  return defval;
         TAILQ_FOREACH(ap, &pn->attrq, child)          TAILQ_FOREACH(a, &n->attrq, child)
                 if (ap->key == key)                  if (a->key == key)
                         return ap->val != ATTRVAL__MAX ? attrvals[ap->val] :                          return a->val != ATTRVAL__MAX ? attrvals[a->val] :
                             ap->rawval != NULL ? ap->rawval : defval;                              a->rawval != NULL ? a->rawval : defval;
         return defval;          return defval;
 }  }
   
Line 156  pnode_getattr_raw(struct pnode *pn, enum attrkey key, 
Line 175  pnode_getattr_raw(struct pnode *pn, enum attrkey key, 
  * Recursively search and return the first instance of "node".   * Recursively search and return the first instance of "node".
  */   */
 struct pnode *  struct pnode *
 pnode_findfirst(struct pnode *pn, enum nodeid node)  pnode_findfirst(struct pnode *n, enum nodeid node)
 {  {
         struct pnode    *pch, *res;          struct pnode    *nc, *res;
   
         if (pn->node == node)          if (n->node == node)
                 return pn;                  return n;
         TAILQ_FOREACH(pch, &pn->childq, child)          TAILQ_FOREACH(nc, &n->childq, child)
                 if ((res = pnode_findfirst(pch, node)) != NULL)                  if ((res = pnode_findfirst(nc, node)) != NULL)
                         return res;                          return res;
         return NULL;          return NULL;
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.9

CVSweb