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

Diff for /mandoc/mdoc_html.c between version 1.238 and 1.246

version 1.238, 2015/10/12 00:08:15 version 1.246, 2017/01/10 23:36:34
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2014, 2015, 2016, 2017 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 71  static void    mdoc_bk_post(MDOC_ARGS);
Line 71  static void    mdoc_bk_post(MDOC_ARGS);
 static  int               mdoc_bk_pre(MDOC_ARGS);  static  int               mdoc_bk_pre(MDOC_ARGS);
 static  int               mdoc_bl_pre(MDOC_ARGS);  static  int               mdoc_bl_pre(MDOC_ARGS);
 static  int               mdoc_bt_pre(MDOC_ARGS);  static  int               mdoc_bt_pre(MDOC_ARGS);
 static  int               mdoc_bx_pre(MDOC_ARGS);  
 static  int               mdoc_cd_pre(MDOC_ARGS);  static  int               mdoc_cd_pre(MDOC_ARGS);
 static  int               mdoc_d1_pre(MDOC_ARGS);  static  int               mdoc_d1_pre(MDOC_ARGS);
 static  int               mdoc_dv_pre(MDOC_ARGS);  static  int               mdoc_dv_pre(MDOC_ARGS);
Line 183  static const struct htmlmdoc mdocs[MDOC_MAX] = {
Line 182  static const struct htmlmdoc mdocs[MDOC_MAX] = {
         {mdoc_quote_pre, mdoc_quote_post}, /* Bo */          {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
         {mdoc_quote_pre, mdoc_quote_post}, /* Bq */          {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
         {mdoc_xx_pre, NULL}, /* Bsx */          {mdoc_xx_pre, NULL}, /* Bsx */
         {mdoc_bx_pre, NULL}, /* Bx */          {mdoc_xx_pre, NULL}, /* Bx */
         {mdoc_skip_pre, NULL}, /* Db */          {mdoc_skip_pre, NULL}, /* Db */
         {NULL, NULL}, /* Dc */          {NULL, NULL}, /* Dc */
         {mdoc_quote_pre, mdoc_quote_post}, /* Do */          {mdoc_quote_pre, mdoc_quote_post}, /* Do */
Line 286  static void
Line 285  static void
 synopsis_pre(struct html *h, const struct roff_node *n)  synopsis_pre(struct html *h, const struct roff_node *n)
 {  {
   
         if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))          if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
                 return;                  return;
   
         if (n->prev->tok == n->tok &&          if (n->prev->tok == n->tok &&
Line 377  print_mdoc_node(MDOC_ARGS)
Line 376  print_mdoc_node(MDOC_ARGS)
         int              child;          int              child;
         struct tag      *t;          struct tag      *t;
   
           if (n->flags & NODE_NOPRT)
                   return;
   
         child = 1;          child = 1;
         t = h->tags.head;          t = h->tags.head;
         n->flags &= ~MDOC_ENDED;          n->flags &= ~NODE_ENDED;
   
         switch (n->type) {          switch (n->type) {
         case ROFFT_TEXT:          case ROFFT_TEXT:
Line 390  print_mdoc_node(MDOC_ARGS)
Line 392  print_mdoc_node(MDOC_ARGS)
                  * Make sure that if we're in a literal mode already                   * Make sure that if we're in a literal mode already
                  * (i.e., within a <PRE>) don't print the newline.                   * (i.e., within a <PRE>) don't print the newline.
                  */                   */
                 if (' ' == *n->string && MDOC_LINE & n->flags)                  if (' ' == *n->string && NODE_LINE & n->flags)
                         if ( ! (HTML_LITERAL & h->flags))                          if ( ! (HTML_LITERAL & h->flags))
                                 print_otag(h, TAG_BR, 0, NULL);                                  print_otag(h, TAG_BR, 0, NULL);
                 if (MDOC_DELIMC & n->flags)                  if (NODE_DELIMC & n->flags)
                         h->flags |= HTML_NOSPACE;                          h->flags |= HTML_NOSPACE;
                 print_text(h, n->string);                  print_text(h, n->string);
                 if (MDOC_DELIMO & n->flags)                  if (NODE_DELIMO & n->flags)
                         h->flags |= HTML_NOSPACE;                          h->flags |= HTML_NOSPACE;
                 return;                  return;
         case ROFFT_EQN:          case ROFFT_EQN:
                 if (n->flags & MDOC_LINE)                  if (n->flags & NODE_LINE)
                         putchar('\n');                          putchar('\n');
                 print_eqn(h, n->eqn);                  print_eqn(h, n->eqn);
                 break;                  break;
Line 428  print_mdoc_node(MDOC_ARGS)
Line 430  print_mdoc_node(MDOC_ARGS)
                 break;                  break;
         }          }
   
         if (h->flags & HTML_KEEP && n->flags & MDOC_LINE) {          if (h->flags & HTML_KEEP && n->flags & NODE_LINE) {
                 h->flags &= ~HTML_KEEP;                  h->flags &= ~HTML_KEEP;
                 h->flags |= HTML_PREKEEP;                  h->flags |= HTML_PREKEEP;
         }          }
Line 442  print_mdoc_node(MDOC_ARGS)
Line 444  print_mdoc_node(MDOC_ARGS)
         case ROFFT_EQN:          case ROFFT_EQN:
                 break;                  break;
         default:          default:
                 if ( ! mdocs[n->tok].post || n->flags & MDOC_ENDED)                  if ( ! mdocs[n->tok].post || n->flags & NODE_ENDED)
                         break;                          break;
                 (*mdocs[n->tok].post)(meta, n, h);                  (*mdocs[n->tok].post)(meta, n, h);
                 if (n->end != ENDBODY_NOT)                  if (n->end != ENDBODY_NOT)
                         n->body->flags |= MDOC_ENDED;                          n->body->flags |= NODE_ENDED;
                 if (n->end == ENDBODY_NOSPACE)                  if (n->end == ENDBODY_NOSPACE)
                         h->flags |= HTML_NOSPACE;                          h->flags |= HTML_NOSPACE;
                 break;                  break;
Line 542  mdoc_sh_pre(MDOC_ARGS)
Line 544  mdoc_sh_pre(MDOC_ARGS)
         }          }
   
         bufinit(h);          bufinit(h);
         bufcat(h, "x");  
   
         for (n = n->child; n != NULL && n->type == ROFFT_TEXT; ) {          for (n = n->child; n != NULL && n->type == ROFFT_TEXT; ) {
                 bufcat_id(h, n->string);                  bufcat_id(h, n->string);
Line 572  mdoc_ss_pre(MDOC_ARGS)
Line 573  mdoc_ss_pre(MDOC_ARGS)
                 return 1;                  return 1;
   
         bufinit(h);          bufinit(h);
         bufcat(h, "x");  
   
         for (n = n->child; n != NULL && n->type == ROFFT_TEXT; ) {          for (n = n->child; n != NULL && n->type == ROFFT_TEXT; ) {
                 bufcat_id(h, n->string);                  bufcat_id(h, n->string);
Line 604  mdoc_fl_pre(MDOC_ARGS)
Line 604  mdoc_fl_pre(MDOC_ARGS)
   
         print_text(h, "\\-");          print_text(h, "\\-");
   
         if ( ! (n->nchild == 0 &&          if (!(n->child == NULL &&
             (n->next == NULL ||              (n->next == NULL ||
              n->next->type == ROFFT_TEXT ||               n->next->type == ROFFT_TEXT ||
              n->next->flags & MDOC_LINE)))               n->next->flags & NODE_LINE)))
                 h->flags |= HTML_NOSPACE;                  h->flags |= HTML_NOSPACE;
   
         return 1;          return 1;
Line 713  static int
Line 713  static int
 mdoc_ns_pre(MDOC_ARGS)  mdoc_ns_pre(MDOC_ARGS)
 {  {
   
         if ( ! (MDOC_LINE & n->flags))          if ( ! (NODE_LINE & n->flags))
                 h->flags |= HTML_NOSPACE;                  h->flags |= HTML_NOSPACE;
         return 1;          return 1;
 }  }
Line 731  mdoc_ar_pre(MDOC_ARGS)
Line 731  mdoc_ar_pre(MDOC_ARGS)
 static int  static int
 mdoc_xx_pre(MDOC_ARGS)  mdoc_xx_pre(MDOC_ARGS)
 {  {
         const char      *pp;  
         struct htmlpair  tag;          struct htmlpair  tag;
         int              flags;  
   
         switch (n->tok) {  
         case MDOC_Bsx:  
                 pp = "BSD/OS";  
                 break;  
         case MDOC_Dx:  
                 pp = "DragonFly";  
                 break;  
         case MDOC_Fx:  
                 pp = "FreeBSD";  
                 break;  
         case MDOC_Nx:  
                 pp = "NetBSD";  
                 break;  
         case MDOC_Ox:  
                 pp = "OpenBSD";  
                 break;  
         case MDOC_Ux:  
                 pp = "UNIX";  
                 break;  
         default:  
                 return 1;  
         }  
   
         PAIR_CLASS_INIT(&tag, "unix");          PAIR_CLASS_INIT(&tag, "unix");
         print_otag(h, TAG_SPAN, 1, &tag);          print_otag(h, TAG_SPAN, 1, &tag);
           return 1;
         print_text(h, pp);  
         if (n->child) {  
                 flags = h->flags;  
                 h->flags |= HTML_KEEP;  
                 print_text(h, n->child->string);  
                 h->flags = flags;  
         }  
         return 0;  
 }  }
   
 static int  static int
 mdoc_bx_pre(MDOC_ARGS)  
 {  
         struct htmlpair  tag;  
   
         PAIR_CLASS_INIT(&tag, "unix");  
         print_otag(h, TAG_SPAN, 1, &tag);  
   
         if (NULL != (n = n->child)) {  
                 print_text(h, n->string);  
                 h->flags |= HTML_NOSPACE;  
                 print_text(h, "BSD");  
         } else {  
                 print_text(h, "BSD");  
                 return 0;  
         }  
   
         if (NULL != (n = n->next)) {  
                 h->flags |= HTML_NOSPACE;  
                 print_text(h, "-");  
                 h->flags |= HTML_NOSPACE;  
                 print_text(h, n->string);  
         }  
   
         return 0;  
 }  
   
 static int  
 mdoc_it_pre(MDOC_ARGS)  mdoc_it_pre(MDOC_ARGS)
 {  {
         struct roffsu    su;          struct roffsu    su;
Line 981  mdoc_bl_pre(MDOC_ARGS)
Line 921  mdoc_bl_pre(MDOC_ARGS)
 static int  static int
 mdoc_ex_pre(MDOC_ARGS)  mdoc_ex_pre(MDOC_ARGS)
 {  {
         struct tag      *t;          struct htmlpair   tag;
         struct htmlpair  tag;          struct tag       *t;
         int              nchild;          struct roff_node *nch;
   
         if (n->prev)          if (n->prev)
                 print_otag(h, TAG_BR, 0, NULL);                  print_otag(h, TAG_BR, 0, NULL);
Line 992  mdoc_ex_pre(MDOC_ARGS)
Line 932  mdoc_ex_pre(MDOC_ARGS)
   
         print_text(h, "The");          print_text(h, "The");
   
         nchild = n->nchild;          for (nch = n->child; nch != NULL; nch = nch->next) {
         for (n = n->child; n; n = n->next) {                  assert(nch->type == ROFFT_TEXT);
                 assert(n->type == ROFFT_TEXT);  
   
                 t = print_otag(h, TAG_B, 1, &tag);                  t = print_otag(h, TAG_B, 1, &tag);
                 print_text(h, n->string);                  print_text(h, nch->string);
                 print_tagq(h, t);                  print_tagq(h, t);
   
                 if (nchild > 2 && n->next) {                  if (nch->next == NULL)
                           continue;
   
                   if (nch->prev != NULL || nch->next->next != NULL) {
                         h->flags |= HTML_NOSPACE;                          h->flags |= HTML_NOSPACE;
                         print_text(h, ",");                          print_text(h, ",");
                 }                  }
   
                 if (n->next && NULL == n->next->next)                  if (nch->next->next == NULL)
                         print_text(h, "and");                          print_text(h, "and");
         }          }
   
         if (nchild > 1)          if (n->child != NULL && n->child->next != NULL)
                 print_text(h, "utilities exit\\~0");                  print_text(h, "utilities exit\\~0");
         else          else
                 print_text(h, "utility exits\\~0");                  print_text(h, "utility exits\\~0");
Line 1063  mdoc_sx_pre(MDOC_ARGS)
Line 1005  mdoc_sx_pre(MDOC_ARGS)
         struct htmlpair  tag[2];          struct htmlpair  tag[2];
   
         bufinit(h);          bufinit(h);
         bufcat(h, "#x");          bufcat(h, "#");
   
         for (n = n->child; n; ) {          for (n = n->child; n; ) {
                 bufcat_id(h, n->string);                  bufcat_id(h, n->string);
Line 1121  mdoc_bd_pre(MDOC_ARGS)
Line 1063  mdoc_bd_pre(MDOC_ARGS)
         bufcat_su(h, "margin-left", &su);          bufcat_su(h, "margin-left", &su);
         PAIR_STYLE_INIT(&tag[0], h);          PAIR_STYLE_INIT(&tag[0], h);
   
         if (DISP_unfilled != n->norm->Bd.type &&          PAIR_CLASS_INIT(&tag[1], "display");
             DISP_literal != n->norm->Bd.type) {          print_otag(h, TAG_DIV, 2, tag);
                 PAIR_CLASS_INIT(&tag[1], "display");  
                 print_otag(h, TAG_DIV, 2, tag);          if (n->norm->Bd.type != DISP_unfilled &&
               n->norm->Bd.type != DISP_literal)
                 return 1;                  return 1;
         }  
   
         PAIR_CLASS_INIT(&tag[1], "lit display");          PAIR_CLASS_INIT(&tag[0], "lit");
         print_otag(h, TAG_PRE, 2, tag);          print_otag(h, TAG_PRE, 1, tag);
   
         /* This can be recursive: save & set our literal state. */          /* This can be recursive: save & set our literal state. */
   
Line 1158  mdoc_bd_pre(MDOC_ARGS)
Line 1100  mdoc_bd_pre(MDOC_ARGS)
                         break;                          break;
                 }                  }
                 if (h->flags & HTML_NONEWLINE ||                  if (h->flags & HTML_NONEWLINE ||
                     (nn->next && ! (nn->next->flags & MDOC_LINE)))                      (nn->next && ! (nn->next->flags & NODE_LINE)))
                         continue;                          continue;
                 else if (nn->next)                  else if (nn->next)
                         print_text(h, "\n");                          print_text(h, "\n");
Line 1397  mdoc_fn_pre(MDOC_ARGS)
Line 1339  mdoc_fn_pre(MDOC_ARGS)
         const char      *sp, *ep;          const char      *sp, *ep;
         int              sz, i, pretty;          int              sz, i, pretty;
   
         pretty = MDOC_SYNPRETTY & n->flags;          pretty = NODE_SYNPRETTY & n->flags;
         synopsis_pre(h, n);          synopsis_pre(h, n);
   
         /* Split apart into type and name. */          /* Split apart into type and name. */
Line 1427  mdoc_fn_pre(MDOC_ARGS)
Line 1369  mdoc_fn_pre(MDOC_ARGS)
          */           */
   
 #if 0  #if 0
         if (MDOC_SYNPRETTY & n->flags) {          if (NODE_SYNPRETTY & n->flags) {
                 nbuf[0] = '\0';                  nbuf[0] = '\0';
                 html_idcat(nbuf, sp, BUFSIZ);                  html_idcat(nbuf, sp, BUFSIZ);
                 PAIR_ID_INIT(&tag[1], nbuf);                  PAIR_ID_INIT(&tag[1], nbuf);
Line 1456  mdoc_fn_pre(MDOC_ARGS)
Line 1398  mdoc_fn_pre(MDOC_ARGS)
   
         for (n = n->child->next; n; n = n->next) {          for (n = n->child->next; n; n = n->next) {
                 i = 1;                  i = 1;
                 if (MDOC_SYNPRETTY & n->flags)                  if (NODE_SYNPRETTY & n->flags)
                         i = 2;                          i = 2;
                 t = print_otag(h, TAG_I, i, tag);                  t = print_otag(h, TAG_I, i, tag);
                 print_text(h, n->string);                  print_text(h, n->string);
Line 1646  mdoc_in_pre(MDOC_ARGS)
Line 1588  mdoc_in_pre(MDOC_ARGS)
          * of no children.           * of no children.
          */           */
   
         if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)          if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags)
                 print_text(h, "#include");                  print_text(h, "#include");
   
         print_text(h, "<");          print_text(h, "<");
Line 1697  mdoc_rv_pre(MDOC_ARGS)
Line 1639  mdoc_rv_pre(MDOC_ARGS)
 {  {
         struct htmlpair  tag;          struct htmlpair  tag;
         struct tag      *t;          struct tag      *t;
         int              nchild;          struct roff_node *nch;
   
         if (n->prev)          if (n->prev)
                 print_otag(h, TAG_BR, 0, NULL);                  print_otag(h, TAG_BR, 0, NULL);
   
         PAIR_CLASS_INIT(&tag, "fname");          PAIR_CLASS_INIT(&tag, "fname");
   
         nchild = n->nchild;          if (n->child != NULL) {
         if (nchild > 0) {  
                 print_text(h, "The");                  print_text(h, "The");
   
                 for (n = n->child; n; n = n->next) {                  for (nch = n->child; nch != NULL; nch = nch->next) {
                         t = print_otag(h, TAG_B, 1, &tag);                          t = print_otag(h, TAG_B, 1, &tag);
                         print_text(h, n->string);                          print_text(h, nch->string);
                         print_tagq(h, t);                          print_tagq(h, t);
   
                         h->flags |= HTML_NOSPACE;                          h->flags |= HTML_NOSPACE;
                         print_text(h, "()");                          print_text(h, "()");
   
                         if (n->next == NULL)                          if (nch->next == NULL)
                                 continue;                                  continue;
   
                         if (nchild > 2) {                          if (nch->prev != NULL || nch->next->next != NULL) {
                                 h->flags |= HTML_NOSPACE;                                  h->flags |= HTML_NOSPACE;
                                 print_text(h, ",");                                  print_text(h, ",");
                         }                          }
                         if (n->next->next == NULL)                          if (nch->next->next == NULL)
                                 print_text(h, "and");                                  print_text(h, "and");
                 }                  }
   
                 if (nchild > 1)                  if (n->child != NULL && n->child->next != NULL)
                         print_text(h, "functions return");                          print_text(h, "functions return");
                 else                  else
                         print_text(h, "function returns");                          print_text(h, "function returns");
Line 1824  static void
Line 1765  static void
 mdoc_pf_post(MDOC_ARGS)  mdoc_pf_post(MDOC_ARGS)
 {  {
   
         if ( ! (n->next == NULL || n->next->flags & MDOC_LINE))          if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
                 h->flags |= HTML_NOSPACE;                  h->flags |= HTML_NOSPACE;
 }  }
   
Line 1850  mdoc_no_pre(MDOC_ARGS)
Line 1791  mdoc_no_pre(MDOC_ARGS)
         struct htmlpair tag;          struct htmlpair tag;
   
         PAIR_CLASS_INIT(&tag, "none");          PAIR_CLASS_INIT(&tag, "none");
         print_otag(h, TAG_CODE, 1, &tag);          print_otag(h, TAG_SPAN, 1, &tag);
         return 1;          return 1;
 }  }
   
Line 1895  mdoc_lb_pre(MDOC_ARGS)
Line 1836  mdoc_lb_pre(MDOC_ARGS)
 {  {
         struct htmlpair tag;          struct htmlpair tag;
   
         if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)          if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags && n->prev)
                 print_otag(h, TAG_BR, 0, NULL);                  print_otag(h, TAG_BR, 0, NULL);
   
         PAIR_CLASS_INIT(&tag, "lib");          PAIR_CLASS_INIT(&tag, "lib");
Line 2003  mdoc_bk_pre(MDOC_ARGS)
Line 1944  mdoc_bk_pre(MDOC_ARGS)
         case ROFFT_HEAD:          case ROFFT_HEAD:
                 return 0;                  return 0;
         case ROFFT_BODY:          case ROFFT_BODY:
                 if (n->parent->args || 0 == n->prev->nchild)                  if (n->parent->args != NULL || n->prev->child == NULL)
                         h->flags |= HTML_PREKEEP;                          h->flags |= HTML_PREKEEP;
                 break;                  break;
         default:          default:
Line 2032  mdoc_quote_pre(MDOC_ARGS)
Line 1973  mdoc_quote_pre(MDOC_ARGS)
         switch (n->tok) {          switch (n->tok) {
         case MDOC_Ao:          case MDOC_Ao:
         case MDOC_Aq:          case MDOC_Aq:
                 print_text(h, n->nchild == 1 &&                  print_text(h, n->child != NULL && n->child->next == NULL &&
                     n->child->tok == MDOC_Mt ?  "<" : "\\(la");                      n->child->tok == MDOC_Mt ?  "<" : "\\(la");
                 break;                  break;
         case MDOC_Bro:          case MDOC_Bro:
Line 2096  mdoc_quote_post(MDOC_ARGS)
Line 2037  mdoc_quote_post(MDOC_ARGS)
         switch (n->tok) {          switch (n->tok) {
         case MDOC_Ao:          case MDOC_Ao:
         case MDOC_Aq:          case MDOC_Aq:
                 print_text(h, n->nchild == 1 &&                  print_text(h, n->child != NULL && n->child->next == NULL &&
                     n->child->tok == MDOC_Mt ?  ">" : "\\(ra");                      n->child->tok == MDOC_Mt ?  ">" : "\\(ra");
                 break;                  break;
         case MDOC_Bro:          case MDOC_Bro:

Legend:
Removed from v.1.238  
changed lines
  Added in v.1.246

CVSweb