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

Diff for /docbook2mdoc/docbook2mdoc.c between version 1.14 and 1.121

version 1.14, 2014/03/30 13:18:49 version 1.121, 2019/04/14 18:07:35
Line 1 
Line 1 
 /*      $Id$ */  /* $Id$ */
 /*  /*
  * Copyright (c) 2014 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2014 Kristaps Dzonsons <kristaps@bsd.lv>
    * Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 14 
Line 15 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
 #include <sys/queue.h>  
   
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
 #include <expat.h>  
 #include <fcntl.h>  
 #include <getopt.h>  
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  
   
 #include "extern.h"  #include "node.h"
   #include "macro.h"
   #include "format.h"
   
 /*  /*
  * Global parse state.   * The implementation of the mdoc(7) formatter.
  * Keep this as simple and small as possible.  
  */   */
 struct  parse {  
         XML_Parser       xml;  
         enum nodeid      node; /* current (NODE_ROOT if pre-tree) */  
         const char      *fname; /* filename */  
         int              stop; /* should we stop now? */  
         struct pnode    *root; /* root of parse tree */  
         struct pnode    *cur; /* current node in tree */  
         char            *b; /* nil-terminated buffer for pre-print */  
         size_t           bsz; /* current length of b */  
         size_t           mbsz; /* max bsz allocation */  
         int              newln; /* output: are we on a fresh line */  
 };  
   
 struct  node {  static void      pnode_print(struct format *, struct pnode *);
         const char      *name; /* docbook element name */  static void      pnode_printrefentry(struct format *, struct pnode *);
         unsigned int     flags;  
 #define NODE_IGNTEXT     1 /* ignore all contained text */  
 };  
   
 TAILQ_HEAD(pnodeq, pnode);  
 TAILQ_HEAD(pattrq, pattr);  
   
 struct  pattr {  
         enum attrkey     key;  
         enum attrval     val;  
         char            *rawval;  
         TAILQ_ENTRY(pattr) child;  
 };  
   
 struct  pnode {  
         enum nodeid      node; /* node type */  
         char            *b; /* binary data buffer */  
         size_t           bsz; /* data buffer size */  
         struct pnode    *parent; /* parent (or NULL if top) */  
         struct pnodeq    childq; /* queue of children */  
         struct pattrq    attrq; /* attributes of node */  
         TAILQ_ENTRY(pnode) child;  
 };  
   
 static  const char *attrkeys[ATTRKEY__MAX] = {  
         "choice",  
         "id",  
         "rep"  
 };  
   
 static  const char *attrvals[ATTRVAL__MAX] = {  
         "norepeat",  
         "opt",  
         "plain",  
         "repeat",  
         "req"  
 };  
   
 static  const struct node nodes[NODE__MAX] = {  
         { NULL, 0 },  
         { "arg", 0 },  
         { "citerefentry", NODE_IGNTEXT },  
         { "cmdsynopsis", NODE_IGNTEXT },  
         { "code", 0 },  
         { "command", 0 },  
         { "emphasis", 0 },  
         { "funcdef", 0 },  
         { "funcprototype", NODE_IGNTEXT },  
         { "funcsynopsis", NODE_IGNTEXT },  
         { "funcsynopsisinfo", 0 },  
         { "function", 0 },  
         { "link", 0 },  
         { "listitem", NODE_IGNTEXT },  
         { "manvolnum", 0 },  
         { "option", 0 },  
         { "para", 0 },  
         { "paramdef", 0 },  
         { "parameter", 0 },  
         { "programlisting", 0 },  
         { "refclass", NODE_IGNTEXT },  
         { "refdescriptor", NODE_IGNTEXT },  
         { "refentry", NODE_IGNTEXT },  
         { "refentrytitle", 0 },  
         { "refmeta", NODE_IGNTEXT },  
         { "refmiscinfo", NODE_IGNTEXT },  
         { "refname", 0 },  
         { "refnamediv", NODE_IGNTEXT },  
         { "refpurpose", 0 },  
         { "refsect1", 0 },  
         { "refsynopsisdiv", NODE_IGNTEXT },  
         { "replaceable", 0 },  
         { "structname", 0 },  
         { "synopsis", 0 },  
         { "term", 0 },  
         { NULL, 0 },  
         { "title", 0 },  
         { "ulink", 0 },  
         { "variablelist", NODE_IGNTEXT },  
         { "varlistentry", NODE_IGNTEXT },  
 };  
   
 static void  static void
 pnode_print(struct parse *p, struct pnode *pn);  pnode_printtext(struct format *f, struct pnode *n)
   
 /*  
  * Process a stream of characters.  
  * We store text as nodes in and of themselves.  
  * If a text node is already open, append to it.  
  * If it's not open, open one under the current context.  
  */  
 static void  
 xml_char(void *arg, const XML_Char *p, int sz)  
 {  {
         struct parse    *ps = arg;          struct pnode    *nn;
         struct pnode    *dat;          char            *cp;
         int              i;          int              accept_arg;
   
         /* Stopped or no tree yet. */          cp = n->b;
         if (ps->stop || NODE_ROOT == ps->node)          accept_arg = f->flags & FMT_ARG;
                 return;          if (f->linestate == LINE_MACRO && !n->spc && !accept_arg) {
                   for (;;) {
                           if (*cp == '\0')
                                   return;
                           if (strchr("!),.:;?]", *cp) == NULL)
                                   break;
                           printf(" %c", *cp++);
                   }
                   if (isspace((unsigned char)*cp)) {
                           while (isspace((unsigned char)*cp))
                                   cp++;
                           macro_close(f);
                   } else {
                           fputs(" Ns", stdout);
                           f->flags &= FMT_IMPL;
                           accept_arg = 1;
                   }
           }
           if (f->linestate == LINE_MACRO && !accept_arg &&
               (f->flags & (FMT_CHILD | FMT_IMPL)) == 0)
                   macro_close(f);
   
         /* Not supposed to be collecting text. */  
         assert(NULL != ps->cur);  
         if (NODE_IGNTEXT & nodes[ps->node].flags)  
                 return;  
   
         /*          /*
          * Are we in the midst of processing text?           * Text preceding a macro without intervening whitespace
          * If we're not processing text right now, then create a text           * requires a .Pf macro.
          * node for doing so.           * Set the spacing flag to avoid a redundant .Ns macro.
          * However, don't do so unless we have some non-whitespace to  
          * process: strip out all leading whitespace to be sure.  
          */           */
         if (NODE_TEXT != ps->node) {  
                 for (i = 0; i < sz; i++)          if (f->linestate != LINE_MACRO &&
                         if ( ! isspace((int)p[i]))              (nn = TAILQ_NEXT(n, child)) != NULL && nn->spc == 0) {
                                 break;                  switch (pnode_class(nn->node)) {
                 if (i == sz)                  case CLASS_LINE:
                         return;                  case CLASS_ENCL:
                 p += i;                          macro_open(f, "Pf");
                 sz -= i;                          accept_arg = 1;
                 dat = calloc(1, sizeof(struct pnode));                          f->flags |= FMT_CHILD;
                 if (NULL == dat) {                          nn->spc = 1;
                         perror(NULL);                          break;
                         exit(EXIT_FAILURE);                  default:
                           break;
                 }                  }
           }
   
                 dat->node = ps->node = NODE_TEXT;          switch (f->linestate) {
                 dat->parent = ps->cur;          case LINE_NEW:
                 TAILQ_INIT(&dat->childq);                  break;
                 TAILQ_INIT(&dat->attrq);          case LINE_TEXT:
                 TAILQ_INSERT_TAIL(&ps->cur->childq, dat, child);                  if (n->spc) {
                 ps->cur = dat;                          if (n->node == NODE_TEXT)
                 assert(NULL != ps->root);                                  macro_close(f);
                           else
                                   putchar(' ');
                   }
                   break;
           case LINE_MACRO:
                   if (accept_arg)
                           putchar(' ');
                   else
                           macro_close(f);
                   break;
         }          }
   
         /* Append to current buffer. */          if (n->node == NODE_ESCAPE) {
         assert(sz >= 0);                  fputs(n->b, stdout);
         ps->cur->b = realloc(ps->cur->b,                  if (f->linestate == LINE_NEW)
                 ps->cur->bsz + (size_t)sz);                          f->linestate = LINE_TEXT;
         if (NULL == ps->cur->b) {                  return;
                 perror(NULL);  
                 exit(EXIT_FAILURE);  
         }          }
         memcpy(ps->cur->b + ps->cur->bsz, p, sz);  
         ps->cur->bsz += (size_t)sz;  
 }  
   
 static void          /*
 pnode_trim(struct pnode *pn)           * Remove the prefix '-' from <option> elements
 {           * because the arguments of .Fl macros do not need it.
            */
   
         assert(NODE_TEXT == pn->node);          if (n->parent != NULL && n->parent->node == NODE_OPTION && *cp == '-')
         for ( ; pn->bsz > 0; pn->bsz--)                  cp++;
                 if ( ! isspace((int)pn->b[pn->bsz - 1]))  
                         break;          if (f->linestate == LINE_MACRO)
                   macro_addarg(f, cp, 0);
           else
                   print_text(f, cp, 0);
 }  }
   
 /*  
  * Begin an element.  
  * First, look for the element.  
  * If we don't find it and we're not parsing, keep going.  
  * If we don't find it and we're parsing, puke and exit.  
  * If we find it but we're not parsing yet (i.e., it's not a refentry  
  * and thus out of context), keep going.  
  * If we find it and we're at the root and already have a tree, puke and  
  * exit (FIXME: I don't think this is right?).  
  * If we find it but we're parsing a text node, close out the text node,  
  * return to its parent, and keep going.  
  * Make sure that the element is in the right context.  
  * Lastly, put the node onto our parse tree and continue.  
  */  
 static void  static void
 xml_elem_start(void *arg, const XML_Char *name, const XML_Char **atts)  pnode_printpara(struct format *f, struct pnode *n)
 {  {
         struct parse     *ps = arg;          struct pnode    *np;
         enum nodeid       node;  
         enum attrkey      key;  
         enum attrval      val;  
         struct pnode     *dat;  
         struct pattr     *pattr;  
         const XML_Char  **att;  
   
         if (ps->stop)          if (n->parent == NULL)
                 return;                  return;
   
         /* Close out text node, if applicable... */          if ((np = TAILQ_PREV(n, pnodeq, child)) == NULL)
         if (NODE_TEXT == ps->node) {              np = n->parent;
                 assert(NULL != ps->cur);  
                 pnode_trim(ps->cur);  
                 ps->cur = ps->cur->parent;  
                 assert(NULL != ps->cur);  
                 ps->node = ps->cur->node;  
         }  
   
         for (node = 0; node < NODE__MAX; node++)          f->flags = 0;
                 if (NULL == nodes[node].name)  
                         continue;  
                 else if (0 == strcmp(nodes[node].name, name))  
                         break;  
   
         if (NODE__MAX == node && NODE_ROOT == ps->node) {          switch (np->node) {
           case NODE_ENTRY:
           case NODE_GLOSSTERM:
           case NODE_LISTITEM:
           case NODE_TERM:
                 return;                  return;
         } else if (NODE__MAX == node) {          case NODE_APPENDIX:
                 fprintf(stderr, "%s:%zu:%zu: unknown node \"%s\"\n",          case NODE_LEGALNOTICE:
                         ps->fname, XML_GetCurrentLineNumber(ps->xml),          case NODE_PREFACE:
                         XML_GetCurrentColumnNumber(ps->xml), name);          case NODE_SECTION:
                 ps->stop = 1;                  if (f->level < 3)
                 return;                          return;
         } else if (NODE_ROOT == ps->node && NULL != ps->root) {                  break;
                 fprintf(stderr, "%s:%zu:%zu: multiple refentries\n",          default:
                         ps->fname, XML_GetCurrentLineNumber(ps->xml),                  break;
                         XML_GetCurrentColumnNumber(ps->xml));  
                 ps->stop = 1;  
                 return;  
         } else if (NODE_ROOT == ps->node && NODE_REFENTRY != node) {  
                 return;  
         } else if ( ! isparent(node, ps->node)) {  
                 fprintf(stderr, "%s:%zu:%zu: bad parent \"%s\" "  
                         "of node \"%s\"\n",  
                         ps->fname, XML_GetCurrentLineNumber(ps->xml),  
                         XML_GetCurrentColumnNumber(ps->xml),  
                         NULL == nodes[ps->node].name ?  
                         "(none)" : nodes[ps->node].name,  
                         NULL == nodes[node].name ?  
                         "(none)" : nodes[node].name);  
                 ps->stop = 1;  
                 return;  
         }          }
           macro_line(f, "Pp");
   }
   
         if (NULL == (dat = calloc(1, sizeof(struct pnode)))) {  static void
                 perror(NULL);  pnode_printrefnamediv(struct format *f, struct pnode *n)
                 exit(EXIT_FAILURE);  {
         }          struct pnode    *nc, *nn;
           int              comma;
   
         dat->node = ps->node = node;          macro_line(f, "Sh NAME");
         dat->parent = ps->cur;          comma = 0;
         TAILQ_INIT(&dat->childq);          TAILQ_FOREACH_SAFE(nc, &n->childq, child, nn) {
         TAILQ_INIT(&dat->attrq);                  if (nc->node != NODE_REFNAME)
   
         if (NULL != ps->cur)  
                 TAILQ_INSERT_TAIL(&ps->cur->childq, dat, child);  
   
         ps->cur = dat;  
         if (NULL == ps->root)  
                 ps->root = dat;  
   
         /*  
          * Process attributes.  
          */  
         for (att = atts; NULL != *att; att += 2) {  
                 for (key = 0; key < ATTRKEY__MAX; key++)  
                         if (0 == strcmp(*att, attrkeys[key]))  
                                 break;  
                 if (ATTRKEY__MAX == key) {  
                         fprintf(stderr, "%s:%zu:%zu: unknown "  
                                 "attribute \"%s\"\n", ps->fname,  
                                 XML_GetCurrentLineNumber(ps->xml),  
                                 XML_GetCurrentColumnNumber(ps->xml),  
                                 *att);  
                         continue;                          continue;
                 } else if ( ! isattrkey(node, key)) {                  if (comma)
                         fprintf(stderr, "%s:%zu:%zu: bad "                          macro_addarg(f, ",", ARG_SPACE);
                                 "attribute \"%s\"\n", ps->fname,                  macro_open(f, "Nm");
                                 XML_GetCurrentLineNumber(ps->xml),                  macro_addnode(f, nc, ARG_SPACE);
                                 XML_GetCurrentColumnNumber(ps->xml),                  pnode_unlink(nc);
                                 *att);                  comma = 1;
                         continue;  
                 }  
                 for (val = 0; val < ATTRVAL__MAX; val++)  
                         if (0 == strcmp(*(att + 1), attrvals[val]))  
                                 break;  
                 if (ATTRVAL__MAX != val && ! isattrval(key, val)) {  
                         fprintf(stderr, "%s:%zu:%zu: bad "  
                                 "value \"%s\"\n", ps->fname,  
                                 XML_GetCurrentLineNumber(ps->xml),  
                                 XML_GetCurrentColumnNumber(ps->xml),  
                                 *(att + 1));  
                         continue;  
                 }  
                 pattr = calloc(1, sizeof(struct pattr));  
                 pattr->key = key;  
                 pattr->val = val;  
                 if (ATTRVAL__MAX == val)  
                         pattr->rawval = strdup(*(att + 1));  
                 TAILQ_INSERT_TAIL(&dat->attrq, pattr, child);  
         }          }
           macro_close(f);
 }  }
   
 /*  /*
  * Roll up the parse tree.   * If the SYNOPSIS macro has a superfluous title, kill it.
  * If we're at a text node, roll that one up first.  
  * If we hit the root, then assign ourselves as the NODE_ROOT.  
  */   */
 static void  static void
 xml_elem_end(void *arg, const XML_Char *name)  pnode_printrefsynopsisdiv(struct format *f, struct pnode *n)
 {  {
         struct parse    *ps = arg;          struct pnode    *nc, *nn;
   
         if (ps->stop || NODE_ROOT == ps->node)          TAILQ_FOREACH_SAFE(nc, &n->childq, child, nn)
                 return;                  if (nc->node == NODE_TITLE)
                           pnode_unlink(nc);
   
         /* Close out text node, if applicable... */          macro_line(f, "Sh SYNOPSIS");
         if (NODE_TEXT == ps->node) {  
                 assert(NULL != ps->cur);  
                 pnode_trim(ps->cur);  
                 ps->cur = ps->cur->parent;  
                 assert(NULL != ps->cur);  
                 ps->node = ps->cur->node;  
         }  
   
         if (NULL == (ps->cur = ps->cur->parent))  
                 ps->node = NODE_ROOT;  
         else  
                 ps->node = ps->cur->node;  
 }  }
   
 /*  /*
  * Recursively free a node (NULL is ok).   * Start a hopefully-named `Sh' section.
  */   */
 static void  static void
 pnode_free(struct pnode *pn)  pnode_printsection(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp;          struct pnode    *nc, *ncc;
         struct pattr    *ap;          const char      *title;
           int              flags, level;
   
         if (NULL == pn)          if (n->parent == NULL) {
                   pnode_printrefentry(f, n);
                 return;                  return;
           }
   
         while (NULL != (pp = TAILQ_FIRST(&pn->childq))) {          level = ++f->level;
                 TAILQ_REMOVE(&pn->childq, pp, child);          flags = ARG_SPACE;
                 pnode_free(pp);          switch (n->node) {
           case NODE_PREFACE:
           case NODE_SECTION:
           case NODE_APPENDIX:
                   if (level == 1)
                           flags |= ARG_UPPER;
                   break;
           case NODE_SIMPLESECT:
           case NODE_LEGALNOTICE:
                   if (level < 2)
                           level = 2;
                   break;
           default:
                   if (level < 3)
                           level = 3;
                   break;
         }          }
   
         while (NULL != (ap = TAILQ_FIRST(&pn->attrq))) {          TAILQ_FOREACH(nc, &n->childq, child)
                 TAILQ_REMOVE(&pn->attrq, ap, child);                  if (nc->node == NODE_TITLE)
                 free(ap->rawval);                          break;
                 free(ap);  
           if (nc == NULL) {
                   switch (n->node) {
                   case NODE_PREFACE:
                           title = "Preface";
                           break;
                   case NODE_APPENDIX:
                           title = "Appendix";
                           break;
                   case NODE_LEGALNOTICE:
                           title = "Legal Notice";
                           break;
                   case NODE_CAUTION:
                           title = "Caution";
                           break;
                   case NODE_NOTE:
                           title = "Note";
                           break;
                   case NODE_TIP:
                           title = "Tip";
                           break;
                   case NODE_WARNING:
                           title = "Warning";
                           break;
                   default:
                           title = "Unknown";
                           break;
                   }
         }          }
   
         free(pn->b);          switch (level) {
         free(pn);          case 1:
 }                  macro_close(f);
                   macro_open(f, "Sh");
                   break;
           case 2:
                   macro_close(f);
                   macro_open(f, "Ss");
                   break;
           default:
                   pnode_printpara(f, n);
                   macro_open(f, "Sy");
                   break;
           }
   
 /*          if (nc != NULL)
  * Unlink a node from its parent and pnode_free() it.                  macro_addnode(f, nc, flags);
  */          else
 static void                  macro_addarg(f, title, flags | ARG_QUOTED);
 pnode_unlink(struct pnode *pn)          macro_close(f);
 {  
   
         if (NULL != pn->parent)          /*
                 TAILQ_REMOVE(&pn->parent->childq, pn, child);           * DocBook has no equivalent for -split mode,
         pnode_free(pn);           * so just switch the default in the AUTHORS section.
            */
   
           if (nc != NULL) {
                   ncc = TAILQ_FIRST(&nc->childq);
                   if (ncc != NULL && ncc->node == NODE_TEXT &&
                       strcasecmp(ncc->b, "AUTHORS") == 0)
                           macro_line(f, "An -nosplit");
                   pnode_unlink(nc);
           }
 }  }
   
 /*  /*
  * Unlink all children of a node and pnode_free() them.   * Start a reference, extracting the title and volume.
  */   */
 static void  static void
 pnode_unlinksub(struct pnode *pn)  pnode_printciterefentry(struct format *f, struct pnode *n)
 {  {
           struct pnode    *nc, *title, *manvol;
   
         while ( ! TAILQ_EMPTY(&pn->childq))          title = manvol = NULL;
                 pnode_unlink(TAILQ_FIRST(&pn->childq));          TAILQ_FOREACH(nc, &n->childq, child) {
                   if (nc->node == NODE_MANVOLNUM)
                           manvol = nc;
                   else if (nc->node == NODE_REFENTRYTITLE)
                           title = nc;
           }
           macro_open(f, "Xr");
           if (title == NULL)
                   macro_addarg(f, "unknown", ARG_SPACE);
           else
                   macro_addnode(f, title, ARG_SPACE | ARG_SINGLE);
           if (manvol == NULL)
                   macro_addarg(f, "1", ARG_SPACE);
           else
                   macro_addnode(f, manvol, ARG_SPACE | ARG_SINGLE);
           pnode_unlinksub(n);
 }  }
   
 /*  
  * Reset the lookaside buffer.  
  */  
 static void  static void
 bufclear(struct parse *p)  pnode_printfuncdef(struct format *f, struct pnode *n)
 {  {
           struct pnode    *nc;
   
         p->b[p->bsz = 0] = '\0';          nc = TAILQ_FIRST(&n->childq);
           if (nc != NULL && nc->node == NODE_TEXT) {
                   macro_argline(f, "Ft", nc->b);
                   pnode_unlink(nc);
           }
           macro_nodeline(f, "Fo", n, ARG_SINGLE);
           pnode_unlinksub(n);
 }  }
   
 /*  /*
  * Append NODE_TEXT contents to the current buffer, reallocating its   * The <mml:mfenced> node is a little peculiar.
  * size if necessary.   * First, it can have arbitrary open and closing tokens, which default
  * The buffer is ALWAYS nil-terminated.   * to parentheses.
    * Second, >1 arguments are separated by commas.
  */   */
 static void  static void
 bufappend(struct parse *p, struct pnode *pn)  pnode_printmathfenced(struct format *f, struct pnode *n)
 {  {
           struct pnode    *nc;
   
         assert(NODE_TEXT == pn->node);          printf("left %s ", pnode_getattr_raw(n, ATTRKEY_OPEN, "("));
         if (p->bsz + pn->bsz + 1 > p->mbsz) {  
                 p->mbsz = p->bsz + pn->bsz + 1;          nc = TAILQ_FIRST(&n->childq);
                 if (NULL == (p->b = realloc(p->b, p->mbsz))) {          pnode_print(f, nc);
                         perror(NULL);  
                         exit(EXIT_FAILURE);          while ((nc = TAILQ_NEXT(nc, child)) != NULL) {
                 }                  putchar(',');
                   pnode_print(f, nc);
         }          }
         memcpy(p->b + p->bsz, pn->b, pn->bsz);          printf("right %s ", pnode_getattr_raw(n, ATTRKEY_CLOSE, ")"));
         p->bsz += pn->bsz;          pnode_unlinksub(n);
         p->b[p->bsz] = '\0';  
 }  }
   
 /*  /*
  * Recursively append all NODE_TEXT nodes to the buffer.   * These math nodes require special handling because they have infix
  * This descends into non-text nodes, but doesn't do anything beyond   * syntax, instead of the usual prefix or prefix.
  * them.   * So we need to break up the first and second child node with a
  * In other words, this is a recursive text grok.   * particular eqn(7) word.
  */   */
 static void  static void
 bufappend_r(struct parse *p, struct pnode *pn)  pnode_printmath(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp;          struct pnode    *nc;
   
         if (NODE_TEXT == pn->node)          nc = TAILQ_FIRST(&n->childq);
                 bufappend(p, pn);          pnode_print(f, nc);
         TAILQ_FOREACH(pp, &pn->childq, child)  
                 bufappend_r(p, pp);          switch (n->node) {
           case NODE_MML_MSUP:
                   fputs(" sup ", stdout);
                   break;
           case NODE_MML_MFRAC:
                   fputs(" over ", stdout);
                   break;
           case NODE_MML_MSUB:
                   fputs(" sub ", stdout);
                   break;
           default:
                   break;
           }
   
           nc = TAILQ_NEXT(nc, child);
           pnode_print(f, nc);
           pnode_unlinksub(n);
 }  }
   
 #define MACROLINE_NORM  0  
 #define MACROLINE_UPPER 1  
 /*  
  * Recursively print text presumably on a macro line.  
  * Convert all whitespace to regular spaces.  
  */  
 static void  static void
 pnode_printmacrolinetext(struct parse *p, struct pnode *pn, int fl)  pnode_printfuncprototype(struct format *f, struct pnode *n)
 {  {
         char            *cp;          struct pnode    *nc, *fdef;
   
         if (0 == p->newln)          TAILQ_FOREACH(fdef, &n->childq, child)
                 putchar(' ');                  if (fdef->node == NODE_FUNCDEF)
                           break;
   
         bufclear(p);          if (fdef != NULL) {
         bufappend_r(p, pn);                  pnode_printfuncdef(f, fdef);
                   pnode_unlink(fdef);
           } else
                   macro_line(f, "Fo UNKNOWN");
   
         /* Convert all space to spaces. */          TAILQ_FOREACH(nc, &n->childq, child)
         for (cp = p->b; '\0' != *cp; cp++)                  macro_nodeline(f, "Fa", nc, ARG_SINGLE);
                 if (isspace((int)*cp))  
                         *cp = ' ';  
   
         for (cp = p->b; isspace((int)*cp); cp++)          macro_line(f, "Fc");
                 /* Spin past whitespace (XXX: necessary?) */ ;          pnode_unlinksub(n);
         for ( ; '\0' != *cp; cp++) {  
                 /* Escape us if we look like a macro. */  
                 if ((cp == p->b || ' ' == *(cp - 1)) &&  
                         isupper((int)*cp) &&  
                         '\0' != *(cp + 1) &&  
                         islower((int)*(cp + 1)) &&  
                         ('\0' == *(cp + 2) ||  
                          ' ' == *(cp + 2) ||  
                          (islower((int)*(cp + 2)) &&  
                           ('\0' == *(cp + 3) ||  
                            ' ' == *(cp + 3)))))  
                         fputs("\\&", stdout);  
                 if (MACROLINE_UPPER & fl)  
                         putchar(toupper((int)*cp));  
                 else  
                         putchar((int)*cp);  
                 /* If we're a character escape, escape us. */  
                 if ('\\' == *cp)  
                         putchar('e');  
         }  
 }  }
   
   /*
    * The <arg> element is more complicated than it should be because text
    * nodes are treated like ".Ar foo", but non-text nodes need to be
    * re-sent into the printer (i.e., without the preceding ".Ar").
    * This also handles the case of "repetition" (or in other words, the
    * ellipsis following an argument) and optionality.
    */
 static void  static void
 pnode_printmacrolinepart(struct parse *p, struct pnode *pn)  pnode_printarg(struct format *f, struct pnode *n)
 {  {
           struct pnode    *nc;
           struct pattr    *a;
           int              isop, isrep, was_impl;
   
         pnode_printmacrolinetext(p, pn, 0);          isop = 1;
           isrep = was_impl = 0;
           TAILQ_FOREACH(a, &n->attrq, child) {
                   if (a->key == ATTRKEY_CHOICE &&
                       (a->val == ATTRVAL_PLAIN || a->val == ATTRVAL_REQ))
                           isop = 0;
                   else if (a->key == ATTRKEY_REP && a->val == ATTRVAL_REPEAT)
                           isrep = 1;
           }
           if (isop) {
                   if (f->flags & FMT_IMPL) {
                           was_impl = 1;
                           macro_open(f, "Oo");
                   } else {
                           macro_open(f, "Op");
                           f->flags |= FMT_IMPL;
                   }
           }
           TAILQ_FOREACH(nc, &n->childq, child) {
                   if (nc->node == NODE_TEXT)
                           macro_open(f, "Ar");
                   pnode_print(f, nc);
           }
           if (isrep && f->linestate == LINE_MACRO)
                   macro_addarg(f, "...", ARG_SPACE);
           if (isop) {
                   if (was_impl)
                           macro_open(f, "Oc");
                   else
                           f->flags &= ~FMT_IMPL;
           }
           pnode_unlinksub(n);
 }  }
   
 /*  
  * Just pnode_printmacrolinepart() but with a newline.  
  * If no text, just the newline.  
  */  
 static void  static void
 pnode_printmacroline(struct parse *p, struct pnode *pn)  pnode_printgroup(struct format *f, struct pnode *n)
 {  {
           struct pnode    *nc;
           struct pattr    *a;
           int              bar, isop, isrep, was_impl;
   
         assert(0 == p->newln);          isop = 1;
         pnode_printmacrolinetext(p, pn, 0);          isrep = was_impl = 0;
         putchar('\n');          TAILQ_FOREACH(a, &n->attrq, child) {
         p->newln = 1;                  if (a->key == ATTRKEY_CHOICE &&
                       (a->val == ATTRVAL_PLAIN || a->val == ATTRVAL_REQ))
                           isop = 0;
                   else if (a->key == ATTRKEY_REP && a->val == ATTRVAL_REPEAT)
                           isrep = 1;
           }
           if (isop) {
                   if (f->flags & FMT_IMPL) {
                           was_impl = 1;
                           macro_open(f, "Oo");
                   } else {
                           macro_open(f, "Op");
                           f->flags |= FMT_IMPL;
                   }
           } else if (isrep) {
                   if (f->flags & FMT_IMPL) {
                           was_impl = 1;
                           macro_open(f, "Bro");
                   } else {
                           macro_open(f, "Brq");
                           f->flags |= FMT_IMPL;
                   }
           }
           bar = 0;
           TAILQ_FOREACH(nc, &n->childq, child) {
                   if (bar && f->linestate == LINE_MACRO)
                           macro_addarg(f, "|", ARG_SPACE);
                   pnode_print(f, nc);
                   bar = 1;
           }
           if (isop) {
                   if (was_impl)
                           macro_open(f, "Oc");
                   else
                           f->flags &= ~FMT_IMPL;
           } else if (isrep) {
                   if (was_impl)
                           macro_open(f, "Brc");
                   else
                           f->flags &= ~FMT_IMPL;
           }
           if (isrep && f->linestate == LINE_MACRO)
                   macro_addarg(f, "...", ARG_SPACE);
           pnode_unlinksub(n);
 }  }
   
 static void  static void
 pnode_printmopen(struct parse *p)  pnode_printsystemitem(struct format *f, struct pnode *n)
 {  {
         if (p->newln) {          switch (pnode_getattr(n, ATTRKEY_CLASS)) {
                 putchar('.');          case ATTRVAL_IPADDRESS:
                 p->newln = 0;                  break;
         } else          case ATTRVAL_SYSTEMNAME:
                 putchar(' ');                  macro_open(f, "Pa");
                   break;
           case ATTRVAL_EVENT:
           default:
                   macro_open(f, "Sy");
                   break;
           }
 }  }
   
 static void  static void
 pnode_printmclose(struct parse *p, int sv)  pnode_printauthor(struct format *f, struct pnode *n)
 {  {
           struct pnode    *nc, *nn;
           int              have_contrib, have_name;
   
         if (sv && ! p->newln) {          /*
                 putchar('\n');           * Print <contrib> children up front, before the .An scope,
                 p->newln = 1;           * and figure out whether we a name of a person.
            */
   
           have_contrib = have_name = 0;
           TAILQ_FOREACH_SAFE(nc, &n->childq, child, nn) {
                   switch (nc->node) {
                   case NODE_CONTRIB:
                           if (have_contrib)
                                   print_text(f, ",", 0);
                           print_textnode(f, nc);
                           pnode_unlink(nc);
                           have_contrib = 1;
                           break;
                   case NODE_PERSONNAME:
                           have_name = 1;
                           break;
                   default:
                           break;
                   }
         }          }
           if (TAILQ_FIRST(&n->childq) == NULL)
                   return;
   
           if (have_contrib)
                   print_text(f, ":", 0);
   
           /*
            * If we have a name, print it in the .An scope and leave
            * all other content for child handlers, to print after the
            * scope.  Otherwise, print everything in the scope.
            */
   
           macro_open(f, "An");
           TAILQ_FOREACH_SAFE(nc, &n->childq, child, nn) {
                   if (nc->node == NODE_PERSONNAME || have_name == 0) {
                           macro_addnode(f, nc, ARG_SPACE);
                           pnode_unlink(nc);
                   }
           }
   
           /*
            * If there is an email address,
            * print it on the same macro line.
            */
   
           if ((nc = pnode_findfirst(n, NODE_EMAIL)) != NULL) {
                   f->flags |= FMT_CHILD;
                   macro_open(f, "Aq Mt");
                   macro_addnode(f, nc, ARG_SPACE);
                   pnode_unlink(nc);
           }
   
           /*
            * If there are still unprinted children, end the scope
            * with a comma.  Otherwise, leave the scope open in case
            * a text node follows that starts with closing punctuation.
            */
   
           if (TAILQ_FIRST(&n->childq) != NULL) {
                   macro_addarg(f, ",", ARG_SPACE);
                   macro_close(f);
           }
 }  }
   
 /*  
  * If the SYNOPSIS macro has a superfluous title, kill it.  
  */  
 static void  static void
 pnode_printrefsynopsisdiv(struct parse *p, struct pnode *pn)  pnode_printlink(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp;          struct pnode    *nc;
           const char      *uri, *text;
   
         TAILQ_FOREACH(pp, &pn->childq, child)          uri = pnode_getattr_raw(n, ATTRKEY_LINKEND, NULL);
                 if (NODE_TITLE == pp->node) {          if (uri != NULL) {
                         pnode_unlink(pp);                  if (TAILQ_FIRST(&n->childq) != NULL) {
                         return;                          TAILQ_FOREACH(nc, &n->childq, child)
                                   pnode_print(f, nc);
                           text = "";
                   } else if ((text = pnode_getattr_raw(n,
                       ATTRKEY_ENDTERM, NULL)) != NULL) {
                           if (f->linestate == LINE_MACRO && f->flags & FMT_ARG)
                                   macro_addarg(f, text, ARG_SPACE);
                           else
                                   print_text(f, text, ARG_SPACE);
                 }                  }
                   if (text != NULL) {
                           if (f->flags & FMT_IMPL)
                                   macro_open(f, "Po");
                           else {
                                   macro_open(f, "Pq");
                                   f->flags |= FMT_CHILD;
                           }
                   }
                   macro_open(f, "Sx");
                   macro_addarg(f, uri, ARG_SPACE);
                   if (text != NULL && f->flags & FMT_IMPL)
                           macro_open(f, "Pc");
                   pnode_unlinksub(n);
                   return;
           }
           uri = pnode_getattr_raw(n, ATTRKEY_XLINK_HREF, NULL);
           if (uri == NULL)
                   uri = pnode_getattr_raw(n, ATTRKEY_URL, NULL);
           if (uri != NULL) {
                   macro_open(f, "Lk");
                   macro_addarg(f, uri, ARG_SPACE | ARG_SINGLE);
                   if (TAILQ_FIRST(&n->childq) != NULL)
                           macro_addnode(f, n, ARG_SPACE | ARG_SINGLE);
                   pnode_unlinksub(n);
                   return;
           }
 }  }
   
 /*  
  * Start a hopefully-named `Sh' section.  
  */  
 static void  static void
 pnode_printrefsect(struct parse *p, struct pnode *pn)  pnode_printprologue(struct format *f, struct pnode *root)
 {  {
         struct pnode    *pp;          struct pnode    *date, *refmeta, *name, *vol, *descr, *nc, *nn;
           const char      *sname;
   
         TAILQ_FOREACH(pp, &pn->childq, child)          /* Collect information. */
                 if (NODE_TITLE == pp->node)  
                         break;  
   
         fputs(".Sh", stdout);          if ((date = pnode_takefirst(root, NODE_PUBDATE)) == NULL)
         p->newln = 0;                  date = pnode_takefirst(root, NODE_DATE);
   
         if (NULL != pp) {          name = vol = NULL;
                 pnode_printmacroline(p, pp);          if ((refmeta = pnode_findfirst(root, NODE_REFMETA)) != NULL) {
                 pnode_unlink(pp);                  TAILQ_FOREACH_SAFE(nc, &refmeta->childq, child, nn) {
         } else {                          switch (nc->node) {
                 puts("UNKNOWN");                          case NODE_REFENTRYTITLE:
                 p->newln = 1;                                  name = nc;
                                   break;
                           case NODE_MANVOLNUM:
                                   vol = nc;
                                   break;
                           default:
                                   continue;
                           }
                           TAILQ_REMOVE(&refmeta->childq, nc, child);
                   }
         }          }
 }  
   
 /*          if (pnode_findfirst(root, NODE_REFNAMEDIV) == NULL &&
  * Start a reference, extracting the title and volume.              ((nc = pnode_findfirst(root, NODE_BOOKINFO)) != NULL ||
  */               (nc = pnode_findfirst(root, NODE_REFENTRYINFO)) != NULL))
 static void                  descr = pnode_takefirst(nc, NODE_TITLE);
 pnode_printciterefentry(struct parse *p, struct pnode *pn)          else
 {                  descr = NULL;
         struct pnode    *pp, *title, *manvol;  
   
         title = manvol = NULL;          /* Print prologue. */
         assert(p->newln);  
         TAILQ_FOREACH(pp, &pn->childq, child)  
                 if (NODE_MANVOLNUM == pp->node)  
                         manvol = pp;  
                 else if (NODE_REFENTRYTITLE == pp->node)  
                         title = pp;  
   
         fputs(".Xr", stdout);          if (date == NULL)
         p->newln = 0;                  macro_line(f, "Dd $Mdocdate" "$");
           else
                   macro_nodeline(f, "Dd", date, 0);
   
         if (NULL != title) {          macro_open(f, "Dt");
                 pnode_printmacrolinepart(p, title);          if (name == NULL) {
                   sname = pnode_getattr_raw(root, ATTRKEY_ID, "UNKNOWN");
                   macro_addarg(f, sname, ARG_SPACE | ARG_SINGLE | ARG_UPPER);
         } else          } else
                 fputs(" unknown ", stdout);                  macro_addnode(f, name, ARG_SPACE | ARG_SINGLE | ARG_UPPER);
           if (vol == NULL)
                   macro_addarg(f, "1", ARG_SPACE);
           else
                   macro_addnode(f, vol, ARG_SPACE | ARG_SINGLE);
   
         if (NULL == manvol) {          macro_line(f, "Os");
                 puts(" 1");  
                 p->newln = 1;          if (descr != NULL) {
         } else                  macro_line(f, "Sh NAME");
                 pnode_printmacroline(p, manvol);                  if (name == NULL)
                           macro_argline(f, "Nm", sname);
                   else
                           macro_nodeline(f, "Nm", name, ARG_SINGLE);
                   macro_nodeline(f, "Nd", descr, 0);
           }
   
           /* Clean up. */
   
           pnode_unlink(date);
           pnode_unlink(name);
           pnode_unlink(vol);
           pnode_unlink(descr);
 }  }
   
 static void  static void
 pnode_printrefmeta(struct parse *p, struct pnode *pn)  pnode_printrefentry(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp, *title, *manvol;          struct pnode    *info, *meta, *nc, *title;
           struct pnode    *match, *later;
   
         title = manvol = NULL;          /* Collect nodes that remained behind when writing the prologue. */
         assert(p->newln);  
         TAILQ_FOREACH(pp, &pn->childq, child)  
                 if (NODE_MANVOLNUM == pp->node)  
                         manvol = pp;  
                 else if (NODE_REFENTRYTITLE == pp->node)  
                         title = pp;  
   
         puts(".Dd $Mdocdate" "$");          meta = NULL;
         fputs(".Dt", stdout);          info = pnode_takefirst(n, NODE_BOOKINFO);
         p->newln = 0;          if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) {
                   pnode_unlink(info);
                   info = NULL;
           }
           if (info == NULL) {
                   info = pnode_takefirst(n, NODE_REFENTRYINFO);
                   if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) {
                           pnode_unlink(info);
                           info = NULL;
                   }
                   meta = pnode_takefirst(n, NODE_REFMETA);
                   if (meta != NULL && TAILQ_FIRST(&meta->childq) == NULL) {
                           pnode_unlink(meta);
                           meta = NULL;
                   }
           }
           if (info == NULL && meta == NULL)
                   return;
   
         if (NULL != title)          /*
                 pnode_printmacrolinetext(p, title, MACROLINE_UPPER);           * Find the best place to put this information.
         else           * Use the last existing AUTHORS node, if any.
                 fputs(" UNKNOWN ", stdout);           * Otherwise, put it behind all standard sections that
            * conventionally precede AUTHORS, and also behind any
            * non-standard sections that follow the last of these,
            * but before the next standard section.
            */
   
         if (NULL == manvol) {          match = later = NULL;
                 puts(" 1");          TAILQ_FOREACH(nc, &n->childq, child) {
                 p->newln = 1;                  switch (nc->node) {
         } else                  case NODE_REFENTRY:
                 pnode_printmacroline(p, manvol);                  case NODE_REFNAMEDIV:
                   case NODE_REFSYNOPSISDIV:
                   case NODE_PREFACE:
                           later = NULL;
                           continue;
                   case NODE_APPENDIX:
                   case NODE_INDEX:
                           if (later == NULL)
                                   later = nc;
                           continue;
                   default:
                           break;
                   }
                   if ((title = pnode_findfirst(nc, NODE_TITLE)) == NULL ||
                       (title = TAILQ_FIRST(&title->childq)) == NULL ||
                       title->node != NODE_TEXT)
                           continue;
                   if (strcasecmp(title->b, "AUTHORS") == 0 ||
                       strcasecmp(title->b, "AUTHOR") == 0)
                           match = nc;
                   else if (strcasecmp(title->b, "NAME") == 0 ||
                       strcasecmp(title->b, "SYNOPSIS") == 0 ||
                       strcasecmp(title->b, "DESCRIPTION") == 0 ||
                       strcasecmp(title->b, "RETURN VALUES") == 0 ||
                       strcasecmp(title->b, "ENVIRONMENT") == 0 ||
                       strcasecmp(title->b, "FILES") == 0 ||
                       strcasecmp(title->b, "EXIT STATUS") == 0 ||
                       strcasecmp(title->b, "EXAMPLES") == 0 ||
                       strcasecmp(title->b, "DIAGNOSTICS") == 0 ||
                       strcasecmp(title->b, "ERRORS") == 0 ||
                       strcasecmp(title->b, "SEE ALSO") == 0 ||
                       strcasecmp(title->b, "STANDARDS") == 0 ||
                       strcasecmp(title->b, "HISTORY") == 0)
                           later = NULL;
                   else if ((strcasecmp(title->b, "CAVEATS") == 0 ||
                       strcasecmp(title->b, "BUGS") == 0) &&
                       later == NULL)
                           later = nc;
           }
   
         puts(".Os");          /*
            * If no AUTHORS section was found, create one from scratch,
            * and insert that at the place selected earlier.
            */
   
           if (match == NULL) {
                   if ((match = calloc(1, sizeof(*match))) == NULL) {
                           perror(NULL);
                           exit(1);
                   }
                   match->node = NODE_SECTION;
                   match->spc = 1;
                   match->parent = n;
                   TAILQ_INIT(&match->childq);
                   TAILQ_INIT(&match->attrq);
                   if ((nc = pnode_alloc(match)) == NULL) {
                           perror(NULL);
                           exit(1);
                   }
                   nc->node = NODE_TITLE;
                   nc->spc = 1;
                   if ((nc = pnode_alloc(nc)) == NULL) {
                           perror(NULL);
                           exit(1);
                   }
                   nc->node = NODE_TEXT;
                   if ((nc->b = strdup("AUTHORS")) == NULL) {
                           perror(NULL);
                           exit(1);
                   }
                   nc->spc = 1;
                   if (later == NULL)
                           TAILQ_INSERT_TAIL(&n->childq, match, child);
                   else
                           TAILQ_INSERT_BEFORE(later, match, child);
           }
   
           /*
            * Dump the stuff excised at the beginning
            * into this AUTHORS section.
            */
   
           if (info != NULL)
                   TAILQ_INSERT_TAIL(&match->childq, info, child);
           if (meta != NULL)
                   TAILQ_INSERT_TAIL(&match->childq, meta, child);
 }  }
   
   /*
    * We can have multiple <term> elements within a <varlistentry>, which
    * we should comma-separate as list headers.
    */
 static void  static void
 pnode_printfuncdef(struct parse *p, struct pnode *pn)  pnode_printvarlistentry(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp, *ftype, *func;          struct pnode    *nc, *nn;
           int              first = 1;
   
         assert(p->newln);          macro_open(f, "It");
         ftype = func = NULL;          f->flags |= FMT_IMPL;
         TAILQ_FOREACH(pp, &pn->childq, child)          TAILQ_FOREACH_SAFE(nc, &n->childq, child, nn) {
                 if (NODE_TEXT == pp->node)                  if (nc->node != NODE_TERM && nc->node != NODE_GLOSSTERM)
                         ftype = pp;                          continue;
                 else if (NODE_FUNCTION == pp->node)                  if (first == 0) {
                         func = pp;                          switch (f->linestate) {
                           case LINE_NEW:
         if (NULL != ftype) {                                  break;
                 fputs(".Ft", stdout);                          case LINE_TEXT:
                 p->newln = 0;                                  print_text(f, ",", 0);
                 pnode_printmacroline(p, ftype);                                  break;
                           case LINE_MACRO:
                                   macro_addarg(f, ",", 0);
                                   break;
                           }
                   }
                   pnode_print(f, nc);
                   pnode_unlink(nc);
                   first = 0;
         }          }
           macro_close(f);
         if (NULL != func) {          while ((nc = TAILQ_FIRST(&n->childq)) != NULL) {
                 fputs(".Fo", stdout);                  pnode_print(f, nc);
                 p->newln = 0;                  pnode_unlink(nc);
                 pnode_printmacroline(p, func);  
         } else {  
                 puts(".Fo UNKNOWN");  
                 p->newln = 1;  
         }          }
           macro_close(f);
 }  }
   
 static void  static void
 pnode_printparamdef(struct parse *p, struct pnode *pn)  pnode_printtitle(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp, *ptype, *param;          struct pnode    *nc, *nn;
   
         assert(p->newln);          TAILQ_FOREACH_SAFE(nc, &n->childq, child, nn) {
         ptype = param = NULL;                  if (nc->node == NODE_TITLE) {
         TAILQ_FOREACH(pp, &pn->childq, child)                          pnode_printpara(f, nc);
                 if (NODE_TEXT == pp->node)                          pnode_print(f, nc);
                         ptype = pp;                          pnode_unlink(nc);
                 else if (NODE_PARAMETER == pp->node)                  }
                         param = pp;  
   
         fputs(".Fa \"", stdout);  
         p->newln = 0;  
         if (NULL != ptype) {  
                 pnode_printmacrolinepart(p, ptype);  
                 putchar(' ');  
         }          }
   
         if (NULL != param)  
                 pnode_printmacrolinepart(p, param);  
   
         puts("\"");  
         p->newln = 1;  
 }  }
   
 static void  static void
 pnode_printfuncprototype(struct parse *p, struct pnode *pn)  pnode_printrow(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp, *fdef;          struct pnode    *nc;
   
         assert(p->newln);          macro_line(f, "Bl -dash -compact");
         TAILQ_FOREACH(fdef, &pn->childq, child)          TAILQ_FOREACH(nc, &n->childq, child) {
                 if (NODE_FUNCDEF == fdef->node)                  macro_line(f, "It");
                         break;                  pnode_print(f, nc);
           }
         if (NULL != fdef)          macro_line(f, "El");
                 pnode_printfuncdef(p, fdef);          pnode_unlink(n);
         else  
                 puts(".Fo UNKNOWN");  
   
         TAILQ_FOREACH(pp, &pn->childq, child)  
                 if (NODE_PARAMDEF == pp->node)  
                         pnode_printparamdef(p, pp);  
   
         puts(".Fc");  
         p->newln = 1;  
 }  }
   
 /*  
  * The <arg> element is more complicated than it should be because text  
  * nodes are treated like ".Ar foo", but non-text nodes need to be  
  * re-sent into the printer (i.e., without the preceding ".Ar").  
  * This also handles the case of "repetition" (or in other words, the  
  * ellipsis following an argument) and optionality.  
  */  
 static void  static void
 pnode_printarg(struct parse *p, struct pnode *pn)  pnode_printtgroup1(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp;          struct pnode    *nc;
         struct pattr    *ap;  
         int              isop, isrep;  
   
         isop = 1;          macro_line(f, "Bl -bullet -compact");
         isrep = 0;          while ((nc = pnode_findfirst(n, NODE_ENTRY)) != NULL) {
         TAILQ_FOREACH(ap, &pn->attrq, child)                  macro_line(f, "It");
                 if (ATTRKEY_CHOICE == ap->key &&                  pnode_print(f, nc);
                         (ATTRVAL_PLAIN == ap->val ||                  pnode_unlink(nc);
                          ATTRVAL_REQ == ap->val))  
                         isop = 0;  
                 else if (ATTRKEY_REP == ap->key &&  
                         (ATTRVAL_REPEAT == ap->val))  
                         isrep = 1;  
   
         if (isop) {  
                 pnode_printmopen(p);  
                 fputs("Op", stdout);  
         }          }
           macro_line(f, "El");
         TAILQ_FOREACH(pp, &pn->childq, child) {          pnode_unlinksub(n);
                 if (NODE_TEXT == pp->node) {  
                         pnode_printmopen(p);  
                         fputs("Ar", stdout);  
                 }  
                 pnode_print(p, pp);  
                 if (NODE_TEXT == pp->node && isrep)  
                         fputs("...", stdout);  
         }  
 }  }
   
 /*  static void
  * Recursively search and return the first instance of "node".  pnode_printtgroup2(struct format *f, struct pnode *n)
  */  
 static struct pnode *  
 pnode_findfirst(struct pnode *pn, enum nodeid node)  
 {  {
         struct pnode    *pp, *res;          struct pnode    *nr, *ne;
   
         res = NULL;          macro_line(f, "Bl -tag -width Ds");
         TAILQ_FOREACH(pp, &pn->childq, child) {          while ((nr = pnode_findfirst(n, NODE_ROW)) != NULL) {
                 res = pp->node == node ? pp :                  if ((ne = pnode_findfirst(n, NODE_ENTRY)) == NULL)
                         pnode_findfirst(pp, node);  
                 if (NULL != res)  
                         break;                          break;
                   macro_open(f, "It");
                   f->flags |= FMT_IMPL;
                   pnode_print(f, ne);
                   macro_close(f);
                   pnode_unlink(ne);
                   pnode_print(f, nr);
                   pnode_unlink(nr);
         }          }
           macro_line(f, "El");
         return(res);          pnode_unlinksub(n);
 }  }
   
 static void  static void
 pnode_printprologue(struct parse *p, struct pnode *pn)  pnode_printtgroup(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp;          struct pnode    *nc;
   
         pp = NULL == p->root ? NULL :          switch (atoi(pnode_getattr_raw(n, ATTRKEY_COLS, "0"))) {
                 pnode_findfirst(p->root, NODE_REFMETA);          case 1:
                   pnode_printtgroup1(f, n);
                   return;
           case 2:
                   pnode_printtgroup2(f, n);
                   return;
           default:
                   break;
           }
   
         if (NULL != pp) {          macro_line(f, "Bl -ohang");
                 pnode_printrefmeta(p, pp);          while ((nc = pnode_findfirst(n, NODE_ROW)) != NULL) {
                 pnode_unlink(pp);                  macro_line(f, "It Table Row");
         } else {                  pnode_printrow(f, nc);
                 puts(".\\\" Supplying bogus prologue...");  
                 puts(".Dd $Mdocdate" "$");  
                 puts(".Dt UNKNOWN 1");  
                 puts(".Os");  
         }          }
           macro_line(f, "El");
           pnode_unlinksub(n);
 }  }
   
 static void  static void
 pnode_printvarlistentry(struct parse *p, struct pnode *pn)  pnode_printlist(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp;          struct pnode    *nc;
   
         assert(p->newln);          pnode_printtitle(f, n);
         TAILQ_FOREACH(pp, &pn->childq, child)          macro_argline(f, "Bl",
                 if (NODE_TERM == pp->node) {              n->node == NODE_ORDEREDLIST ? "-enum" : "-bullet");
                         fputs(".It", stdout);          TAILQ_FOREACH(nc, &n->childq, child) {
                         p->newln = 0;                  macro_line(f, "It");
                         pnode_print(p, pp);                  pnode_print(f, nc);
                         pnode_unlink(pp);          }
                         putchar('\n');          macro_line(f, "El");
                         p->newln = 1;          pnode_unlinksub(n);
                         return;  
                 }  
   
         puts(".It");  
         p->newln = 1;  
 }  }
   
 static void  static void
 pnode_printvariablelist(struct parse *p, struct pnode *pn)  pnode_printvariablelist(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp;          struct pnode    *nc;
   
         assert(p->newln);          pnode_printtitle(f, n);
         TAILQ_FOREACH(pp, &pn->childq, child)          macro_line(f, "Bl -tag -width Ds");
                 if (NODE_TITLE == pp->node) {          TAILQ_FOREACH(nc, &n->childq, child) {
                         puts(".Pp");                  if (nc->node == NODE_VARLISTENTRY)
                         pnode_print(p, pp);                          pnode_printvarlistentry(f, nc);
                         pnode_unlink(pp);                  else
                 }                          macro_nodeline(f, "It", nc, 0);
           }
         assert(p->newln);          macro_line(f, "El");
         puts(".Bl -tag -width Ds");          pnode_unlinksub(n);
         TAILQ_FOREACH(pp, &pn->childq, child)  
                 if (NODE_VARLISTENTRY != pp->node) {  
                         assert(p->newln);  
                         fputs(".It", stdout);  
                         pnode_printmacroline(p, pp);  
                 } else {  
                         assert(p->newln);  
                         pnode_print(p, pp);  
                 }  
         assert(p->newln);  
         puts(".El");  
 }  }
   
 /*  /*
  * Print a parsed node (or ignore it--whatever).   * Print a parsed node (or ignore it--whatever).
  * This is a recursive function.   * This is a recursive function.
  * FIXME: macro line continuation?   * FIXME: if we're in a literal context (<screen> or <programlisting> or
    * whatever), don't print inline macros.
  */   */
 static void  static void
 pnode_print(struct parse *p, struct pnode *pn)  pnode_print(struct format *f, struct pnode *n)
 {  {
         struct pnode    *pp;          struct pnode    *nc, *nn;
         char            *cp;          int              was_impl;
         int              last, sv;  
   
         if (NULL == pn)          if (n == NULL)
                 return;                  return;
   
         sv = p->newln;          was_impl = f->flags & FMT_IMPL;
           if (n->spc)
                   f->flags &= ~FMT_NOSPC;
           else
                   f->flags |= FMT_NOSPC;
   
         switch (pn->node) {          switch (n->node) {
         case (NODE_ARG):          case NODE_ARG:
                 pnode_printarg(p, pn);                  pnode_printarg(f, n);
                 pnode_unlinksub(pn);  
                 break;                  break;
         case (NODE_CITEREFENTRY):          case NODE_AUTHOR:
                 assert(p->newln);                  pnode_printauthor(f, n);
                 pnode_printciterefentry(p, pn);  
                 pnode_unlinksub(pn);  
                 break;                  break;
         case (NODE_CODE):          case NODE_AUTHORGROUP:
                 pnode_printmopen(p);                  macro_line(f, "An -split");
                 fputs("Li", stdout);  
                 break;                  break;
         case (NODE_COMMAND):          case NODE_BLOCKQUOTE:
                 pnode_printmopen(p);                  macro_line(f, "Bd -ragged -offset indent");
                 fputs("Nm", stdout);  
                 break;                  break;
         case (NODE_EMPHASIS):          case NODE_CITEREFENTRY:
                 pnode_printmopen(p);                  pnode_printciterefentry(f, n);
                 fputs("Em", stdout);  
                 break;                  break;
         case (NODE_FUNCTION):          case NODE_CITETITLE:
                 pnode_printmopen(p);                  macro_open(f, "%T");
                 fputs("Fn", stdout);  
                 break;                  break;
         case (NODE_FUNCPROTOTYPE):          case NODE_COMMAND:
                 assert(p->newln);                  macro_open(f, "Nm");
                 pnode_printfuncprototype(p, pn);  
                 pnode_unlinksub(pn);  
                 break;                  break;
         case (NODE_FUNCSYNOPSISINFO):          case NODE_CONSTANT:
                 pnode_printmopen(p);                  macro_open(f, "Dv");
                 fputs("Fd", stdout);  
                 break;                  break;
         case (NODE_OPTION):          case NODE_COPYRIGHT:
                 pnode_printmopen(p);                  print_text(f, "Copyright", ARG_SPACE);
                 fputs("Fl", stdout);                  fputs(" \\(co", stdout);
                 /* FIXME: bogus leading '-'? */  
                 break;                  break;
         case (NODE_PARA):          case NODE_EDITOR:
                 assert(p->newln);                  print_text(f, "editor:", ARG_SPACE);
                 if (NULL != pn->parent &&                  pnode_printauthor(f, n);
                         NODE_LISTITEM == pn->parent->node)  
                         break;  
                 puts(".Pp");  
                 break;                  break;
         case (NODE_PARAMETER):          case NODE_EMAIL:
                 /* Suppress non-text children... */                  if (was_impl)
                 pnode_printmopen(p);                          macro_open(f, "Ao Mt");
                 fputs("Fa \"", stdout);                  else {
                 pnode_printmacrolinepart(p, pn);                          macro_open(f, "Aq Mt");
                 puts("\"");                          f->flags |= FMT_IMPL;
                 pnode_unlinksub(pn);                  }
                 break;                  break;
         case (NODE_PROGRAMLISTING):          case NODE_EMPHASIS:
                 assert(p->newln);          case NODE_FIRSTTERM:
                 puts(".Bd -literal");          case NODE_GLOSSTERM:
                   macro_open(f, "Em");
                 break;                  break;
         case (NODE_REFMETA):          case NODE_ENVAR:
                 abort();                  macro_open(f, "Ev");
                 break;                  break;
         case (NODE_REFNAME):          case NODE_ERRORNAME:
                 /* Suppress non-text children... */                  macro_open(f, "Er");
                 pnode_printmopen(p);  
                 fputs("Nm", stdout);  
                 p->newln = 0;  
                 pnode_printmacrolinepart(p, pn);  
                 pnode_unlinksub(pn);  
                 break;                  break;
         case (NODE_REFNAMEDIV):          case NODE_FILENAME:
                 assert(p->newln);                  macro_open(f, "Pa");
                 puts(".Sh NAME");  
                 break;                  break;
         case (NODE_REFPURPOSE):          case NODE_FUNCTION:
                 assert(p->newln);                  macro_open(f, "Fn");
                 pnode_printmopen(p);  
                 fputs("Nd", stdout);  
                 break;                  break;
         case (NODE_REFSYNOPSISDIV):          case NODE_FUNCPROTOTYPE:
                 assert(p->newln);                  pnode_printfuncprototype(f, n);
                 pnode_printrefsynopsisdiv(p, pn);  
                 puts(".Sh SYNOPSIS");  
                 break;                  break;
         case (NODE_REFSECT1):          case NODE_FUNCSYNOPSISINFO:
                 assert(p->newln);                  macro_open(f, "Fd");
                 pnode_printrefsect(p, pn);  
                 break;                  break;
         case (NODE_REPLACEABLE):          case NODE_INFORMALEQUATION:
                 pnode_printmopen(p);                  macro_line(f, "Bd -ragged -offset indent");
                 fputs("Ar", stdout);                  /* FALLTHROUGH */
           case NODE_INLINEEQUATION:
                   macro_line(f, "EQ");
                 break;                  break;
         case (NODE_STRUCTNAME):          case NODE_ITEMIZEDLIST:
                 pnode_printmopen(p);                  pnode_printlist(f, n);
                 fputs("Vt", stdout);  
                 break;                  break;
         case (NODE_TEXT):          case NODE_GROUP:
                 if (0 == p->newln)                  pnode_printgroup(f, n);
                         putchar(' ');                  break;
                 bufclear(p);          case NODE_KEYSYM:
                 bufappend(p, pn);                  macro_open(f, "Sy");
                 /*                  break;
                  * Output all characters, squeezing out whitespace          case NODE_LINK:
                  * between newlines.                  pnode_printlink(f, n);
                  * XXX: all whitespace, including tabs (?).                  break;
                  * Remember to escape control characters and escapes.          case NODE_LITERAL:
                  */                  if (was_impl)
                 assert(p->bsz);                          macro_open(f, "So");
                 for (last = '\n', cp = p->b; '\0' != *cp; ) {                  else {
                         if ('\n' == last) {                          macro_open(f, "Ql");
                                 /* Consume all whitespace. */                          f->flags |= FMT_IMPL;
                                 if (isspace((int)*cp)) {  
                                         while (isspace((int)*cp))  
                                                 cp++;  
                                         continue;  
                                 } else if ('\'' == *cp || '.' == *cp)  
                                         fputs("\\&", stdout);  
                         }  
                         putchar(last = *cp++);  
                         /* If we're a character escape, escape us. */  
                         if ('\\' == last)  
                                 putchar('e');  
                 }                  }
                 p->newln = 0;  
                 break;                  break;
         case (NODE_VARIABLELIST):          case NODE_LITERALLAYOUT:
                 assert(p->newln);                  macro_close(f);
                 pnode_printvariablelist(p, pn);                  macro_argline(f, "Bd", pnode_getattr(n, ATTRKEY_CLASS) ==
                 pnode_unlinksub(pn);                      ATTRVAL_MONOSPACED ? "-literal" : "-unfilled");
                 break;                  break;
         case (NODE_VARLISTENTRY):          case NODE_MARKUP:
                 assert(p->newln);                  macro_open(f, "Ic");
                 pnode_printvarlistentry(p, pn);  
                 break;                  break;
           case NODE_MML_MFENCED:
                   pnode_printmathfenced(f, n);
                   break;
           case NODE_MML_MROW:
           case NODE_MML_MI:
           case NODE_MML_MN:
           case NODE_MML_MO:
                   if (TAILQ_EMPTY(&n->childq))
                           break;
                   fputs(" { ", stdout);
                   break;
           case NODE_MML_MFRAC:
           case NODE_MML_MSUB:
           case NODE_MML_MSUP:
                   pnode_printmath(f, n);
                   break;
           case NODE_OPTION:
                   macro_open(f, "Fl");
                   break;
           case NODE_ORDEREDLIST:
                   pnode_printlist(f, n);
                   break;
           case NODE_PARA:
                   pnode_printpara(f, n);
                   break;
           case NODE_PARAMDEF:
           case NODE_PARAMETER:
                   /* More often, these appear inside NODE_FUNCPROTOTYPE. */
                   macro_open(f, "Fa");
                   macro_addnode(f, n, ARG_SPACE | ARG_SINGLE);
                   pnode_unlinksub(n);
                   break;
           case NODE_QUOTE:
                   if (was_impl)
                           macro_open(f, "Do");
                   else {
                           macro_open(f, "Dq");
                           f->flags |= FMT_IMPL;
                   }
                   break;
           case NODE_PROGRAMLISTING:
           case NODE_SCREEN:
           case NODE_SYNOPSIS:
                   macro_line(f, "Bd -literal");
                   break;
           case NODE_SYSTEMITEM:
                   pnode_printsystemitem(f, n);
                   break;
           case NODE_REFENTRY:
                   pnode_printrefentry(f, n);
                   break;
           case NODE_REFNAME:
                   /* More often, these appear inside NODE_REFNAMEDIV. */
                   macro_open(f, "Nm");
                   break;
           case NODE_REFNAMEDIV:
                   pnode_printrefnamediv(f, n);
                   break;
           case NODE_REFPURPOSE:
                   macro_open(f, "Nd");
                   break;
           case NODE_REFSYNOPSISDIV:
                   pnode_printrefsynopsisdiv(f, n);
                   break;
           case NODE_PREFACE:
           case NODE_SECTION:
           case NODE_SIMPLESECT:
           case NODE_APPENDIX:
           case NODE_LEGALNOTICE:
           case NODE_NOTE:
           case NODE_TIP:
           case NODE_CAUTION:
           case NODE_WARNING:
                   pnode_printsection(f, n);
                   break;
           case NODE_REPLACEABLE:
                   macro_open(f, "Ar");
                   break;
           case NODE_SBR:
                   macro_line(f, "br");
                   break;
           case NODE_TEXT:
           case NODE_ESCAPE:
                   pnode_printtext(f, n);
                   break;
           case NODE_TGROUP:
                   pnode_printtgroup(f, n);
                   break;
           case NODE_TITLE:
           case NODE_SUBTITLE:
                   pnode_printpara(f, n);
                   macro_nodeline(f, "Sy", n, 0);
                   pnode_unlinksub(n);
                   break;
           case NODE_TYPE:
                   macro_open(f, "Vt");
                   break;
           case NODE_VARIABLELIST:
                   pnode_printvariablelist(f, n);
                   break;
           case NODE_VARNAME:
                   macro_open(f, "Va");
                   break;
         default:          default:
                 break;                  break;
         }          }
   
         TAILQ_FOREACH(pp, &pn->childq, child)          TAILQ_FOREACH(nc, &n->childq, child)
                 pnode_print(p, pp);                  pnode_print(f, nc);
   
         switch (pn->node) {          switch (n->node) {
         case (NODE_ARG):          case NODE_EMAIL:
         case (NODE_CODE):                  if (was_impl) {
         case (NODE_COMMAND):                          f->flags &= ~FMT_NOSPC;
         case (NODE_EMPHASIS):                          macro_open(f, "Ac");
         case (NODE_FUNCTION):                  } else
         case (NODE_FUNCSYNOPSISINFO):                          f->flags &= ~FMT_IMPL;
         case (NODE_OPTION):  
         case (NODE_PARAMETER):  
         case (NODE_REPLACEABLE):  
         case (NODE_REFPURPOSE):  
         case (NODE_STRUCTNAME):  
         case (NODE_TEXT):  
                 pnode_printmclose(p, sv);  
                 break;                  break;
         case (NODE_REFNAME):          case NODE_ESCAPE:
                 /*          case NODE_TERM:
                  * If we're in the NAME macro and we have multiple          case NODE_TEXT:
                  * <refname> macros in sequence, then print out a                  /* Accept more arguments to the previous macro. */
                  * trailing comma before the newline.                  return;
                  */          case NODE_INFORMALEQUATION:
                 if (NULL != pn->parent &&                  macro_line(f, "EN");
                         NODE_REFNAMEDIV == pn->parent->node &&                  macro_line(f, "Ed");
                         NULL != TAILQ_NEXT(pn, child) &&  
                         NODE_REFNAME == TAILQ_NEXT(pn, child)->node)  
                         fputs(" ,", stdout);  
                 pnode_printmclose(p, sv);  
                 break;                  break;
         case (NODE_PROGRAMLISTING):          case NODE_INLINEEQUATION:
                 assert(p->newln);                  macro_line(f, "EN");
                 puts(".Ed");  
                 p->newln = 1;  
                 break;                  break;
           case NODE_LITERAL:
                   if (was_impl) {
                           f->flags &= ~FMT_NOSPC;
                           macro_open(f, "Sc");
                   } else
                           f->flags &= ~FMT_IMPL;
                   break;
           case NODE_MEMBER:
                   if ((nn = TAILQ_NEXT(n, child)) != NULL &&
                       nn->node != NODE_MEMBER)
                           nn = NULL;
                   switch (f->linestate) {
                   case LINE_TEXT:
                           if (nn != NULL)
                                   print_text(f, ",", 0);
                           break;
                   case LINE_MACRO:
                           if (nn != NULL)
                                   macro_addarg(f, ",", ARG_SPACE);
                           macro_close(f);
                           break;
                   case LINE_NEW:
                           break;
                   }
                   break;
           case NODE_MML_MROW:
           case NODE_MML_MI:
           case NODE_MML_MN:
           case NODE_MML_MO:
                   if (TAILQ_EMPTY(&n->childq))
                           break;
                   fputs(" } ", stdout);
                   break;
           case NODE_QUOTE:
                   if (was_impl) {
                           f->flags &= ~FMT_NOSPC;
                           macro_open(f, "Dc");
                   } else
                           f->flags &= ~FMT_IMPL;
                   break;
           case NODE_PREFACE:
           case NODE_SECTION:
           case NODE_APPENDIX:
           case NODE_LEGALNOTICE:
           case NODE_NOTE:
           case NODE_TIP:
           case NODE_CAUTION:
           case NODE_WARNING:
                   f->level--;
                   break;
           case NODE_BLOCKQUOTE:
           case NODE_LITERALLAYOUT:
           case NODE_PROGRAMLISTING:
           case NODE_SCREEN:
           case NODE_SYNOPSIS:
                   macro_line(f, "Ed");
                   break;
         default:          default:
                 break;                  break;
         }          }
           f->flags &= ~FMT_ARG;
 }  }
   
 /*  void
  * Loop around the read buffer until we've drained it of all data.  ptree_print_mdoc(struct ptree *tree)
  * Invoke the parser context with each buffer fill.  
  */  
 static int  
 readfile(XML_Parser xp, int fd,  
         char *b, size_t bsz, const char *fn)  
 {  {
         struct parse     p;          struct format    formatter;
         int              rc;  
         ssize_t          ssz;  
   
         memset(&p, 0, sizeof(struct parse));          formatter.level = 0;
           formatter.linestate = LINE_NEW;
         p.b = malloc(p.bsz = p.mbsz = 1024);          pnode_printprologue(&formatter, tree->root);
         p.fname = fn;          pnode_print(&formatter, tree->root);
         p.xml = xp;          if (formatter.linestate != LINE_NEW)
                   putchar('\n');
         XML_SetCharacterDataHandler(xp, xml_char);  
         XML_SetElementHandler(xp, xml_elem_start, xml_elem_end);  
         XML_SetUserData(xp, &p);  
   
         while ((ssz = read(fd, b, bsz)) >= 0) {  
                 if (0 == (rc = XML_Parse(xp, b, ssz, 0 == ssz)))  
                         fprintf(stderr, "%s: %s\n", fn,  
                                 XML_ErrorString  
                                 (XML_GetErrorCode(xp)));  
                 else if ( ! p.stop && ssz > 0)  
                         continue;  
                 /*  
                  * Exit when we've read all or errors have occured  
                  * during the parse sequence.  
                  */  
                 p.newln = 1;  
                 pnode_printprologue(&p, p.root);  
                 pnode_print(&p, p.root);  
                 pnode_free(p.root);  
                 free(p.b);  
                 return(0 != rc && ! p.stop);  
         }  
   
         /* Read error has occured. */  
         perror(fn);  
         pnode_free(p.root);  
         free(p.b);  
         return(0);  
 }  
   
 int  
 main(int argc, char *argv[])  
 {  
         XML_Parser       xp;  
         const char      *fname;  
         char            *buf;  
         int              fd, rc;  
   
         fname = "-";  
         xp = NULL;  
         buf = NULL;  
         rc = 0;  
   
         if (-1 != getopt(argc, argv, ""))  
                 return(EXIT_FAILURE);  
   
         argc -= optind;  
         argv += optind;  
   
         if (argc > 1)  
                 return(EXIT_FAILURE);  
         else if (argc > 0)  
                 fname = argv[0];  
   
         /* Read from stdin or a file. */  
         fd = 0 == strcmp(fname, "-") ?  
                 STDIN_FILENO : open(fname, O_RDONLY, 0);  
   
         /*  
          * Open file for reading.  
          * Allocate a read buffer.  
          * Create the parser context.  
          * Dive directly into the parse.  
          */  
         if (-1 == fd)  
                 perror(fname);  
         else if (NULL == (buf = malloc(4096)))  
                 perror(NULL);  
         else if (NULL == (xp = XML_ParserCreate(NULL)))  
                 perror(NULL);  
         else if ( ! readfile(xp, fd, buf, 4096, fname))  
                 rc = 1;  
   
         XML_ParserFree(xp);  
         free(buf);  
         if (STDIN_FILENO != fd)  
                 close(fd);  
         return(rc ? EXIT_SUCCESS : EXIT_FAILURE);  
 }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.121

CVSweb