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

Diff for /docbook2mdoc/docbook2mdoc.c between version 1.141 and 1.146

version 1.141, 2019/04/28 17:10:06 version 1.146, 2019/05/01 15:05:39
Line 31 
Line 31 
  */   */
   
 static void      pnode_print(struct format *, struct pnode *);  static void      pnode_print(struct format *, struct pnode *);
 static void      pnode_printrefentry(struct format *, struct pnode *);  
   
   
 static void  static void
Line 194  static void
Line 193  static void
 pnode_printsection(struct format *f, struct pnode *n)  pnode_printsection(struct format *f, struct pnode *n)
 {  {
         struct pnode    *nc, *ncc;          struct pnode    *nc, *ncc;
         const char      *title;  
         int              flags, level;          int              flags, level;
   
         if (n->parent == NULL) {          if (n->parent == NULL)
                 pnode_printrefentry(f, n);  
                 return;                  return;
         }  
   
         level = ++f->level;          level = ++f->level;
         flags = ARG_SPACE;          flags = ARG_SPACE;
         switch (n->node) {          switch (n->node) {
         case NODE_PREFACE:  
         case NODE_SECTION:          case NODE_SECTION:
         case NODE_APPENDIX:          case NODE_APPENDIX:
                 if (level == 1)                  if (level == 1)
                         flags |= ARG_UPPER;                          flags |= ARG_UPPER;
                 break;                  break;
         case NODE_SIMPLESECT:          case NODE_SIMPLESECT:
         case NODE_LEGALNOTICE:  
                 if (level < 2)                  if (level < 2)
                         level = 2;                          level = 2;
                 break;                  break;
         default:          case NODE_NOTE:
                 if (level < 3)                  if (level < 3)
                         level = 3;                          level = 3;
                 break;                  break;
           default:
                   abort();
         }          }
   
         TAILQ_FOREACH(nc, &n->childq, child)          TAILQ_FOREACH(nc, &n->childq, child)
                 if (nc->node == NODE_TITLE)                  if (nc->node == NODE_TITLE)
                         break;                          break;
   
         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;  
                 }  
         }  
   
         switch (level) {          switch (level) {
         case 1:          case 1:
                 macro_close(f);                  macro_close(f);
Line 272  pnode_printsection(struct format *f, struct pnode *n)
Line 239  pnode_printsection(struct format *f, struct pnode *n)
                 macro_open(f, "Sy");                  macro_open(f, "Sy");
                 break;                  break;
         }          }
           macro_addnode(f, nc, flags);
         if (nc != NULL)  
                 macro_addnode(f, nc, flags);  
         else  
                 macro_addarg(f, title, flags | ARG_QUOTED);  
         macro_close(f);          macro_close(f);
   
         /*          /*
Line 382  pnode_printmath(struct format *f, struct pnode *n)
Line 345  pnode_printmath(struct format *f, struct pnode *n)
 static void  static void
 pnode_printfuncprototype(struct format *f, struct pnode *n)  pnode_printfuncprototype(struct format *f, struct pnode *n)
 {  {
         struct pnode    *fdef, *ftype, *nc, *nn;          struct pnode    *fdef, *fps, *ftype, *nc, *nn;
   
         /*          /*
          * Extract <funcdef> child and ignore <void> child.           * Extract <funcdef> child and ignore <void> child.
Line 436  pnode_printfuncprototype(struct format *f, struct pnod
Line 399  pnode_printfuncprototype(struct format *f, struct pnod
                 return;                  return;
   
         while (nc != NULL) {          while (nc != NULL) {
                 macro_nodeline(f, "Fa", nc, ARG_SINGLE);                  if ((fps = pnode_takefirst(nc, NODE_FUNCPARAMS)) != NULL) {
                           macro_open(f, "Fa \"");
                           macro_addnode(f, nc, ARG_QUOTED);
                           macro_addarg(f, "(", ARG_QUOTED);
                           macro_addnode(f, fps, ARG_QUOTED);
                           macro_addarg(f, ")", ARG_QUOTED);
                           putchar('"');
                           macro_close(f);
                   } else
                           macro_nodeline(f, "Fa", nc, ARG_SINGLE);
                 pnode_unlink(nc);                  pnode_unlink(nc);
                 nc = TAILQ_FIRST(&n->childq);                  nc = TAILQ_FIRST(&n->childq);
         }          }
Line 760  pnode_printprologue(struct format *f, struct pnode *ro
Line 732  pnode_printprologue(struct format *f, struct pnode *ro
         f->parastate = PARA_HAVE;          f->parastate = PARA_HAVE;
 }  }
   
 static void  
 pnode_printrefentry(struct format *f, struct pnode *n)  
 {  
         struct pnode    *info, *meta, *nc, *title;  
         struct pnode    *match, *later;  
   
         /* Collect nodes that remained behind when writing the prologue. */  
   
         meta = NULL;  
         info = pnode_takefirst(n, NODE_BOOKINFO);  
         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;  
                 }  
                 if (info == NULL)  
                         info = pnode_takefirst(n, NODE_INFO);  
                 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;  
   
         /*  
          * Find the best place to put this information.  
          * Use the last existing AUTHORS node, if any.  
          * 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.  
          */  
   
         match = later = NULL;  
         TAILQ_FOREACH(nc, &n->childq, child) {  
                 switch (nc->node) {  
                 case NODE_REFENTRY:  
                 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;  
         }  
   
         /*  
          * If no AUTHORS section was found, create one from scratch,  
          * and insert that at the place selected earlier.  
          */  
   
         if (match == NULL) {  
                 match = xcalloc(1, sizeof(*match));  
                 match->node = NODE_SECTION;  
                 match->flags |= NFLAG_SPC;  
                 match->parent = n;  
                 TAILQ_INIT(&match->childq);  
                 TAILQ_INIT(&match->attrq);  
                 nc = pnode_alloc(match);  
                 nc->node = NODE_TITLE;  
                 nc->flags |= NFLAG_SPC;  
                 nc = pnode_alloc_text(nc, "AUTHORS");  
                 nc->flags |= NFLAG_SPC;  
                 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 can have multiple <term> elements within a <varlistentry>, which
  * we should comma-separate as list headers.   * we should comma-separate as list headers.
Line 1076  pnode_print(struct format *f, struct pnode *n)
Line 930  pnode_print(struct format *f, struct pnode *n)
         if (n == NULL)          if (n == NULL)
                 return;                  return;
   
           if (f->nofill && n->flags & NFLAG_LINE)
                   macro_close(f);
   
         was_impl = f->flags & FMT_IMPL;          was_impl = f->flags & FMT_IMPL;
         if (n->flags & NFLAG_SPC)          if (n->flags & NFLAG_SPC)
                 f->flags &= ~FMT_NOSPC;                  f->flags &= ~FMT_NOSPC;
Line 1261  pnode_print(struct format *f, struct pnode *n)
Line 1118  pnode_print(struct format *f, struct pnode *n)
         case NODE_SYSTEMITEM:          case NODE_SYSTEMITEM:
                 pnode_printsystemitem(f, n);                  pnode_printsystemitem(f, n);
                 break;                  break;
         case NODE_REFENTRY:  
                 pnode_printrefentry(f, n);  
                 break;  
         case NODE_REFNAME:          case NODE_REFNAME:
                 /* More often, these appear inside NODE_REFNAMEDIV. */                  /* More often, these appear inside NODE_REFNAMEDIV. */
                 macro_open(f, "Nm");                  macro_open(f, "Nm");
Line 1277  pnode_print(struct format *f, struct pnode *n)
Line 1131  pnode_print(struct format *f, struct pnode *n)
         case NODE_REFSYNOPSISDIV:          case NODE_REFSYNOPSISDIV:
                 pnode_printrefsynopsisdiv(f, n);                  pnode_printrefsynopsisdiv(f, n);
                 break;                  break;
         case NODE_PREFACE:  
         case NODE_SECTION:          case NODE_SECTION:
         case NODE_SIMPLESECT:          case NODE_SIMPLESECT:
         case NODE_APPENDIX:          case NODE_APPENDIX:
         case NODE_LEGALNOTICE:  
         case NODE_NOTE:          case NODE_NOTE:
         case NODE_TIP:  
         case NODE_CAUTION:  
         case NODE_WARNING:  
                 pnode_printsection(f, n);                  pnode_printsection(f, n);
                 break;                  break;
         case NODE_REPLACEABLE:          case NODE_REPLACEABLE:
Line 1337  pnode_print(struct format *f, struct pnode *n)
Line 1186  pnode_print(struct format *f, struct pnode *n)
         case NODE_XREF:          case NODE_XREF:
                 pnode_printxref(f, n);                  pnode_printxref(f, n);
                 break;                  break;
           case NODE_CAUTION:
           case NODE_LEGALNOTICE:
           case NODE_PREFACE:
           case NODE_TIP:
           case NODE_WARNING:
                   abort();
         default:          default:
                 break;                  break;
         }          }
   
           if (pnode_class(n->node) == CLASS_NOFILL)
                   f->nofill++;
   
         TAILQ_FOREACH(nc, &n->childq, child)          TAILQ_FOREACH(nc, &n->childq, child)
                 pnode_print(f, nc);                  pnode_print(f, nc);
   
Line 1421  pnode_print(struct format *f, struct pnode *n)
Line 1279  pnode_print(struct format *f, struct pnode *n)
                 } else                  } else
                         f->flags &= ~FMT_IMPL;                          f->flags &= ~FMT_IMPL;
                 break;                  break;
         case NODE_PREFACE:  
         case NODE_SECTION:          case NODE_SECTION:
           case NODE_SIMPLESECT:
         case NODE_APPENDIX:          case NODE_APPENDIX:
         case NODE_LEGALNOTICE:  
         case NODE_NOTE:          case NODE_NOTE:
         case NODE_TIP:                  if (n->parent != NULL)
         case NODE_CAUTION:                          f->level--;
         case NODE_WARNING:  
                 f->level--;  
                 break;                  break;
         case NODE_BLOCKQUOTE:          case NODE_BLOCKQUOTE:
         case NODE_LITERALLAYOUT:          case NODE_LITERALLAYOUT:
Line 1444  pnode_print(struct format *f, struct pnode *n)
Line 1299  pnode_print(struct format *f, struct pnode *n)
         case NODE_SUBTITLE:          case NODE_SUBTITLE:
                 f->parastate = PARA_WANT;                  f->parastate = PARA_WANT;
                 break;                  break;
           case NODE_YEAR:
                   if ((nn = TAILQ_NEXT(n, child)) != NULL &&
                       nn->node == NODE_YEAR &&
                       f->linestate == LINE_TEXT) {
                           print_text(f, ",", 0);
                           nn->flags |= NFLAG_SPC;
                           if ((nc = TAILQ_FIRST(&nn->childq)) != NULL)
                                   nc->flags |= NFLAG_SPC;
                   }
         default:          default:
                 break;                  break;
         }          }
         f->flags &= ~FMT_ARG;          f->flags &= ~FMT_ARG;
           if (pnode_class(n->node) == CLASS_NOFILL)
                   f->nofill--;
 }  }
   
 void  void
Line 1455  ptree_print_mdoc(struct ptree *tree)
Line 1321  ptree_print_mdoc(struct ptree *tree)
 {  {
         struct format    formatter;          struct format    formatter;
   
         formatter.level = 0;          formatter.level = formatter.nofill = 0;
         formatter.linestate = LINE_NEW;          formatter.linestate = LINE_NEW;
         formatter.parastate = PARA_HAVE;          formatter.parastate = PARA_HAVE;
         pnode_printprologue(&formatter, tree->root);          pnode_printprologue(&formatter, tree->root);

Legend:
Removed from v.1.141  
changed lines
  Added in v.1.146

CVSweb