[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.15 and 1.16

version 1.15, 2009/09/26 18:31:36 version 1.16, 2009/10/03 15:08:09
Line 21 
Line 21 
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
 #include <err.h>  #include <err.h>
   #include <stdarg.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
Line 53  static int    a2width(const char *);
Line 54  static int    a2width(const char *);
 static  int               a2offs(const char *);  static  int               a2offs(const char *);
 static  int               a2list(const struct mdoc_node *);  static  int               a2list(const struct mdoc_node *);
   
   static  void              buffmt_man(struct html *,
                                   const char *, const char *);
   static  void              buffmt(struct html *, const char *, ...);
   static  void              bufcat(struct html *, const char *);
   static  void              bufncat(struct html *, const char *, size_t);
   
   
 static  void              mdoc_root_post(MDOC_ARGS);  static  void              mdoc_root_post(MDOC_ARGS);
 static  int               mdoc_root_pre(MDOC_ARGS);  static  int               mdoc_root_pre(MDOC_ARGS);
 static  int               mdoc_tbl_pre(MDOC_ARGS, int);  static  int               mdoc_tbl_pre(MDOC_ARGS, int);
Line 255  static const struct htmlmdoc mdocs[MDOC_MAX] = {
Line 263  static const struct htmlmdoc mdocs[MDOC_MAX] = {
         {mdoc_sp_pre, NULL}, /* sp */          {mdoc_sp_pre, NULL}, /* sp */
 };  };
   
 static  char              buf[BUFSIZ]; /* XXX */  
   
 #define bufcat(x)         (void)strlcat(buf, (x), BUFSIZ)  
 #define bufinit()         buf[0] = 0  
 #define buffmt(...)       (void)snprintf(buf, BUFSIZ - 1, __VA_ARGS__)  
   
 void  void
 html_mdoc(void *arg, const struct mdoc *m)  html_mdoc(void *arg, const struct mdoc *m)
 {  {
Line 278  html_mdoc(void *arg, const struct mdoc *m)
Line 281  html_mdoc(void *arg, const struct mdoc *m)
 }  }
   
   
   static void
   bufinit(struct html *h)
   {
   
           h->buf[0] = '\0';
           h->buflen = 0;
   }
   
   
   static void
   bufcat(struct html *h, const char *p)
   {
   
           bufncat(h, p, strlen(p));
   }
   
   
   static void
   buffmt(struct html *h, const char *fmt, ...)
   {
           va_list          ap;
   
           va_start(ap, fmt);
           (void)vsnprintf(h->buf + h->buflen,
                           BUFSIZ - h->buflen - 1, fmt, ap);
           va_end(ap);
           h->buflen = strlen(h->buf);
           assert('\0' == h->buf[h->buflen]);
   }
   
   
   static void
   bufncat(struct html *h, const char *p, size_t sz)
   {
   
           if (h->buflen + sz > BUFSIZ - 1)
                   sz = BUFSIZ - 1 - h->buflen;
   
           (void)strncat(h->buf, p, sz);
           h->buflen += sz;
           assert('\0' == h->buf[h->buflen]);
   }
   
   
   static void
   buffmt_man(struct html *h,
                   const char *name, const char *sec)
   {
           const char      *p, *pp;
   
           pp = h->base_man;
   
           /* FIXME: URL-encode contents. */
   
           while ((p = strchr(pp, '%'))) {
                   bufncat(h, pp, p - pp);
                   switch (*(p + 1)) {
                   case('S'):
                           bufcat(h, sec);
                           break;
                   case('N'):
                           buffmt(h, name ? name : "1");
                           break;
                   default:
                           bufncat(h, p, 2);
                           break;
                   }
                   pp = p + 2;
           }
           if (pp)
                   bufcat(h, pp);
   }
   
   
 static int  static int
 a2list(const struct mdoc_node *n)  a2list(const struct mdoc_node *n)
 {  {
Line 427  print_mdoc_node(MDOC_ARGS)
Line 504  print_mdoc_node(MDOC_ARGS)
         child = 1;          child = 1;
         t = SLIST_FIRST(&h->tags);          t = SLIST_FIRST(&h->tags);
   
         bufinit();          bufinit(h);
   
         switch (n->type) {          switch (n->type) {
         case (MDOC_ROOT):          case (MDOC_ROOT):
Line 447  print_mdoc_node(MDOC_ARGS)
Line 524  print_mdoc_node(MDOC_ARGS)
   
         print_stagq(h, t);          print_stagq(h, t);
   
         bufinit();          bufinit(h);
   
         switch (n->type) {          switch (n->type) {
         case (MDOC_ROOT):          case (MDOC_ROOT):
Line 560  mdoc_sh_pre(MDOC_ARGS)
Line 637  mdoc_sh_pre(MDOC_ARGS)
                 print_otag(h, TAG_SPAN, 1, tag);                  print_otag(h, TAG_SPAN, 1, tag);
   
                 for (nn = n->child; nn; nn = nn->next) {                  for (nn = n->child; nn; nn = nn->next) {
                         bufcat(nn->string);                          bufcat(h, nn->string);
                         if (nn->next)                          if (nn->next)
                                 bufcat(" ");                                  bufncat(h, " ", 1);
                 }                  }
                 tag[0].key = ATTR_NAME;                  tag[0].key = ATTR_NAME;
                 tag[0].val = buf;                  tag[0].val = h->buf;
                 print_otag(h, TAG_A, 1, tag);                  print_otag(h, TAG_A, 1, tag);
                 return(1);                  return(1);
         } else if (MDOC_BLOCK == n->type) {          } else if (MDOC_BLOCK == n->type) {
Line 577  mdoc_sh_pre(MDOC_ARGS)
Line 654  mdoc_sh_pre(MDOC_ARGS)
                         return(1);                          return(1);
                 }                  }
   
                 bufcat("margin-top: 1em;");                  bufcat(h, "margin-top: 1em;");
                 if (NULL == n->next)                  if (NULL == n->next)
                         bufcat("margin-bottom: 1em;");                          bufcat(h, "margin-bottom: 1em;");
   
                 tag[1].key = ATTR_STYLE;                  tag[1].key = ATTR_STYLE;
                 tag[1].val = buf;                  tag[1].val = h->buf;
   
                 print_otag(h, TAG_DIV, 2, tag);                  print_otag(h, TAG_DIV, 2, tag);
                 return(1);                  return(1);
         }          }
   
         buffmt("margin-left: %dem;", INDENT);          buffmt(h, "margin-left: %dem;", INDENT);
   
         tag[0].key = ATTR_CLASS;          tag[0].key = ATTR_CLASS;
         tag[0].val = "sec-body";          tag[0].val = "sec-body";
         tag[1].key = ATTR_STYLE;          tag[1].key = ATTR_STYLE;
         tag[1].val = buf;          tag[1].val = h->buf;
   
         print_otag(h, TAG_DIV, 2, tag);          print_otag(h, TAG_DIV, 2, tag);
         return(1);          return(1);
Line 614  mdoc_ss_pre(MDOC_ARGS)
Line 691  mdoc_ss_pre(MDOC_ARGS)
                 tag[i].key = ATTR_CLASS;                  tag[i].key = ATTR_CLASS;
                 tag[i++].val = "ssec-body";                  tag[i++].val = "ssec-body";
                 if (n->parent->next && n->child) {                  if (n->parent->next && n->child) {
                         bufcat("margin-bottom: 1em;");                          bufcat(h, "margin-bottom: 1em;");
                         tag[i].key = ATTR_STYLE;                          tag[i].key = ATTR_STYLE;
                         tag[i++].val = buf;                          tag[i++].val = h->buf;
                 }                  }
                 print_otag(h, TAG_DIV, i, tag);                  print_otag(h, TAG_DIV, i, tag);
                 return(1);                  return(1);
Line 624  mdoc_ss_pre(MDOC_ARGS)
Line 701  mdoc_ss_pre(MDOC_ARGS)
                 tag[i].key = ATTR_CLASS;                  tag[i].key = ATTR_CLASS;
                 tag[i++].val = "ssec-block";                  tag[i++].val = "ssec-block";
                 if (n->prev) {                  if (n->prev) {
                         bufcat("margin-top: 1em;");                          bufcat(h, "margin-top: 1em;");
                         tag[i].key = ATTR_STYLE;                          tag[i].key = ATTR_STYLE;
                         tag[i++].val = buf;                          tag[i++].val = h->buf;
                 }                  }
                 print_otag(h, TAG_DIV, i, tag);                  print_otag(h, TAG_DIV, i, tag);
                 return(1);                  return(1);
         }          }
   
         buffmt("margin-left: -%dem;", INDENT - HALFINDENT);          buffmt(h, "margin-left: -%dem;", INDENT - HALFINDENT);
   
         tag[0].key = ATTR_CLASS;          tag[0].key = ATTR_CLASS;
         tag[0].val = "ssec-head";          tag[0].val = "ssec-head";
         tag[1].key = ATTR_STYLE;          tag[1].key = ATTR_STYLE;
         tag[1].val = buf;          tag[1].val = h->buf;
   
         print_otag(h, TAG_DIV, 2, tag);          print_otag(h, TAG_DIV, 2, tag);
         print_otag(h, TAG_SPAN, 1, tag);          print_otag(h, TAG_SPAN, 1, tag);
   
         bufinit();          bufinit(h);
         for (nn = n->child; nn; nn = nn->next) {          for (nn = n->child; nn; nn = nn->next) {
                 bufcat(nn->string);                  bufcat(h, nn->string);
                 if (nn->next)                  if (nn->next)
                         bufcat(" ");                          bufcat(h, " ");
         }          }
         tag[0].key = ATTR_NAME;          tag[0].key = ATTR_NAME;
         tag[0].val = buf;          tag[0].val = h->buf;
         print_otag(h, TAG_A, 1, tag);          print_otag(h, TAG_A, 1, tag);
   
         return(1);          return(1);
Line 751  static int
Line 828  static int
 mdoc_xr_pre(MDOC_ARGS)  mdoc_xr_pre(MDOC_ARGS)
 {  {
         struct htmlpair          tag[2];          struct htmlpair          tag[2];
         const char              *name, *sec;  
         const struct mdoc_node  *nn;          const struct mdoc_node  *nn;
   
         nn = n->child;          buffmt_man(h, n->child->string,
         name = nn && nn->string ? nn->string : "";                          n->child->next ?
         nn = nn ? nn->next : NULL;                          n->child->next->string : NULL);
         sec = nn && nn->string ? nn->string : "";  
   
         buffmt("%s%s%s.html", name, name && sec ? "." : "", sec);  
   
         tag[0].key = ATTR_CLASS;          tag[0].key = ATTR_CLASS;
         tag[0].val = "link-man";          tag[0].val = "link-man";
         tag[1].key = ATTR_HREF;          tag[1].key = ATTR_HREF;
         tag[1].val = buf;          tag[1].val = h->buf;
         print_otag(h, TAG_A, 2, tag);          print_otag(h, TAG_A, 2, tag);
   
         nn = n->child;          nn = n->child;
         print_text(h, nn->string);          print_text(h, nn->string);
   
         if (NULL == (nn = nn->next))          if (NULL == (nn = nn->next))
                 return(0);                  return(0);
   
Line 882  mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int
Line 956  mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int
         case (MDOC_Item):          case (MDOC_Item):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (MDOC_Ohang):          case (MDOC_Ohang):
                 buffmt("margin-left: %dem; clear: both;", o);                  buffmt(h, "margin-left: %dem; clear: both;", o);
                 break;                  break;
         default:          default:
                 buffmt("margin-left: %dem; clear: both;", w + o);                  buffmt(h, "margin-left: %dem; clear: both;", w + o);
                 break;                  break;
         }          }
   
Line 909  mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int
Line 983  mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int
                         if (NULL == n->prev->body->child)                          if (NULL == n->prev->body->child)
                                 c = 1;                                  c = 1;
                 if ( ! c)                  if ( ! c)
                         bufcat("padding-top: 1em;");                          bufcat(h, "padding-top: 1em;");
         }          }
   
         tag.key = ATTR_STYLE;          tag.key = ATTR_STYLE;
         tag.val = buf;          tag.val = h->buf;
         print_otag(h, TAG_DIV, 1, &tag);          print_otag(h, TAG_DIV, 1, &tag);
         return(1);          return(1);
 }  }
Line 944  mdoc_tbl_head_pre(MDOC_ARGS, int t, int w)
Line 1018  mdoc_tbl_head_pre(MDOC_ARGS, int t, int w)
                 print_otag(h, TAG_DIV, 0, NULL);                  print_otag(h, TAG_DIV, 0, NULL);
                 break;                  break;
         case (MDOC_Column):          case (MDOC_Column):
                 buffmt("min-width: %dem;", w);                  buffmt(h, "min-width: %dem;", w);
                 bufcat("clear: none;");                  bufcat(h, "clear: none;");
                 if (n->next && MDOC_HEAD == n->next->type)                  if (n->next && MDOC_HEAD == n->next->type)
                         bufcat("float: left;");                          bufcat(h, "float: left;");
                 tag.key = ATTR_STYLE;                  tag.key = ATTR_STYLE;
                 tag.val = buf;                  tag.val = h->buf;
                 print_otag(h, TAG_DIV, 1, &tag);                  print_otag(h, TAG_DIV, 1, &tag);
                 break;                  break;
         default:          default:
                 buffmt("margin-left: -%dem; min-width: %dem;",                  buffmt(h, "margin-left: -%dem; min-width: %dem;",
                                 w, w ? w - 1 : 0);                                  w, w ? w - 1 : 0);
                 bufcat("clear: left;");                  bufcat(h, "clear: left;");
                 if (n->next && n->next->child)                  if (n->next && n->next->child)
                         bufcat("float: left;");                          bufcat(h, "float: left;");
                 bufcat("padding-right: 1em;");                  bufcat(h, "padding-right: 1em;");
                 tag.key = ATTR_STYLE;                  tag.key = ATTR_STYLE;
                 tag.val = buf;                  tag.val = h->buf;
                 print_otag(h, TAG_DIV, 1, &tag);                  print_otag(h, TAG_DIV, 1, &tag);
                 break;                  break;
         }          }
Line 1260  mdoc_d1_pre(MDOC_ARGS)
Line 1334  mdoc_d1_pre(MDOC_ARGS)
         if (MDOC_BLOCK != n->type)          if (MDOC_BLOCK != n->type)
                 return(1);                  return(1);
   
         buffmt("margin-left: %dem;", INDENT);          buffmt(h, "margin-left: %dem;", INDENT);
   
         tag[0].key = ATTR_CLASS;          tag[0].key = ATTR_CLASS;
         tag[0].val = "lit";          tag[0].val = "lit";
         tag[1].key = ATTR_STYLE;          tag[1].key = ATTR_STYLE;
         tag[1].val = buf;          tag[1].val = h->buf;
   
         print_otag(h, TAG_DIV, 2, tag);          print_otag(h, TAG_DIV, 2, tag);
         return(1);          return(1);
Line 1279  mdoc_sx_pre(MDOC_ARGS)
Line 1353  mdoc_sx_pre(MDOC_ARGS)
         struct htmlpair          tag[2];          struct htmlpair          tag[2];
         const struct mdoc_node  *nn;          const struct mdoc_node  *nn;
   
         bufcat("#");          bufcat(h, "#");
         for (nn = n->child; nn; nn = nn->next) {          for (nn = n->child; nn; nn = nn->next) {
                 bufcat(nn->string);                  bufcat(h, nn->string);
                 if (nn->next)                  if (nn->next)
                         bufcat(" ");                          bufcat(h, " ");
         }          }
   
         tag[0].key = ATTR_HREF;          tag[0].key = ATTR_HREF;
         tag[0].val = buf;          tag[0].val = h->buf;
         tag[1].key = ATTR_CLASS;          tag[1].key = ATTR_CLASS;
         tag[1].val = "link-sec";          tag[1].val = "link-sec";
   
Line 1360  mdoc_bd_pre(MDOC_ARGS)
Line 1434  mdoc_bd_pre(MDOC_ARGS)
   
         if (MDOC_BLOCK == n->type) {          if (MDOC_BLOCK == n->type) {
                 if (o)                  if (o)
                         buffmt("margin-left: %dem;", o);                          buffmt(h, "margin-left: %dem;", o);
                 if ( ! c) {                  if ( ! c) {
                         for (nn = n; nn; nn = nn->parent) {                          for (nn = n; nn; nn = nn->parent) {
                                 if (MDOC_BLOCK != nn->type)                                  if (MDOC_BLOCK != nn->type)
Line 1378  mdoc_bd_pre(MDOC_ARGS)
Line 1452  mdoc_bd_pre(MDOC_ARGS)
                                         break;                                          break;
                         }                          }
                         if ( ! c)                          if ( ! c)
                                 bufcat("margin-top: 1em;");                                  bufcat(h, "margin-top: 1em;");
                 }                  }
                 tag[0].key = ATTR_STYLE;                  tag[0].key = ATTR_STYLE;
                 tag[0].val = buf;                  tag[0].val = h->buf;
                 print_otag(h, TAG_DIV, 1, tag);                  print_otag(h, TAG_DIV, 1, tag);
                 return(1);                  return(1);
         }          }
Line 1389  mdoc_bd_pre(MDOC_ARGS)
Line 1463  mdoc_bd_pre(MDOC_ARGS)
         if (MDOC_Unfilled != t && MDOC_Literal != t)          if (MDOC_Unfilled != t && MDOC_Literal != t)
                 return(1);                  return(1);
   
         bufcat("white-space: pre;");          bufcat(h, "white-space: pre;");
         tag[0].key = ATTR_STYLE;          tag[0].key = ATTR_STYLE;
         tag[0].val = buf;          tag[0].val = h->buf;
         tag[1].key = ATTR_CLASS;          tag[1].key = ATTR_CLASS;
         tag[1].val = "lit";          tag[1].val = "lit";
   
Line 1610  mdoc_fn_pre(MDOC_ARGS)
Line 1684  mdoc_fn_pre(MDOC_ARGS)
         int                      sz, i;          int                      sz, i;
   
         if (SEC_SYNOPSIS == n->sec) {          if (SEC_SYNOPSIS == n->sec) {
                 bufcat("margin-left: 6em;");                  bufcat(h, "margin-left: 6em;");
                 bufcat("text-indent: -6em;");                  bufcat(h, "text-indent: -6em;");
                 if (n->next)                  if (n->next)
                         bufcat("margin-bottom: 1em;");                          bufcat(h, "margin-bottom: 1em;");
                 tag[0].key = ATTR_STYLE;                  tag[0].key = ATTR_STYLE;
                 tag[0].val = buf;                  tag[0].val = h->buf;
                 print_otag(h, TAG_DIV, 1, tag);                  print_otag(h, TAG_DIV, 1, tag);
         }          }
   
Line 1695  mdoc_sp_pre(MDOC_ARGS)
Line 1769  mdoc_sp_pre(MDOC_ARGS)
                 break;                  break;
         }          }
   
         buffmt("height: %dem", len);          buffmt(h, "height: %dem", len);
         tag.key = ATTR_STYLE;          tag.key = ATTR_STYLE;
         tag.val = buf;          tag.val = h->buf;
         print_otag(h, TAG_DIV, 1, &tag);          print_otag(h, TAG_DIV, 1, &tag);
         return(1);          return(1);
   
Line 1767  mdoc_mt_pre(MDOC_ARGS)
Line 1841  mdoc_mt_pre(MDOC_ARGS)
         tag[0].val = "link-mail";          tag[0].val = "link-mail";
   
         for (nn = n->child; nn; nn = nn->next) {          for (nn = n->child; nn; nn = nn->next) {
                 bufinit();                  bufinit(h);
                 bufcat("mailto:");                  bufcat(h, "mailto:");
                 bufcat(nn->string);                  bufcat(h, nn->string);
   
                 tag[1].key = ATTR_HREF;                  tag[1].key = ATTR_HREF;
                 tag[1].val = buf;                  tag[1].val = h->buf;
   
                 t = print_otag(h, TAG_A, 2, tag);                  t = print_otag(h, TAG_A, 2, tag);
                 print_text(h, nn->string);                  print_text(h, nn->string);

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

CVSweb