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

Diff for /mandoc/html.c between version 1.43 and 1.50

version 1.43, 2009/09/21 13:06:13 version 1.50, 2009/09/21 14:40:31
Line 23 
Line 23 
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <unistd.h>
   
 #include "chars.h"  #include "chars.h"
 #include "mdoc.h"  #include "mdoc.h"
Line 166  static void    print_mdoc(MDOC_ARGS);
Line 167  static void    print_mdoc(MDOC_ARGS);
 static  void              print_mdoc_head(MDOC_ARGS);  static  void              print_mdoc_head(MDOC_ARGS);
 static  void              print_mdoc_node(MDOC_ARGS);  static  void              print_mdoc_node(MDOC_ARGS);
 static  void              print_mdoc_nodelist(MDOC_ARGS);  static  void              print_mdoc_nodelist(MDOC_ARGS);
 static  void              print_man(MAN_ARGS);  
 static  void              print_man_head(MAN_ARGS);  
 static  struct tag       *print_otag(struct html *, enum htmltag,  static  struct tag       *print_otag(struct html *, enum htmltag,
                                 int, const struct htmlpair *);                                  int, const struct htmlpair *);
 static  void              print_tagq(struct html *, const struct tag *);  static  void              print_tagq(struct html *, const struct tag *);
Line 219  static int    mdoc_ns_pre(MDOC_ARGS);
Line 218  static int    mdoc_ns_pre(MDOC_ARGS);
 static  void              mdoc_op_post(MDOC_ARGS);  static  void              mdoc_op_post(MDOC_ARGS);
 static  int               mdoc_op_pre(MDOC_ARGS);  static  int               mdoc_op_pre(MDOC_ARGS);
 static  int               mdoc_pa_pre(MDOC_ARGS);  static  int               mdoc_pa_pre(MDOC_ARGS);
 static  int               mdoc_pp_pre(MDOC_ARGS);  
 static  void              mdoc_pq_post(MDOC_ARGS);  static  void              mdoc_pq_post(MDOC_ARGS);
 static  int               mdoc_pq_pre(MDOC_ARGS);  static  int               mdoc_pq_pre(MDOC_ARGS);
 static  void              mdoc_qq_post(MDOC_ARGS);  static  void              mdoc_qq_post(MDOC_ARGS);
 static  int               mdoc_qq_pre(MDOC_ARGS);  static  int               mdoc_qq_pre(MDOC_ARGS);
 static  int               mdoc_sh_pre(MDOC_ARGS);  static  int               mdoc_sh_pre(MDOC_ARGS);
   static  int               mdoc_sp_pre(MDOC_ARGS);
 static  void              mdoc_sq_post(MDOC_ARGS);  static  void              mdoc_sq_post(MDOC_ARGS);
 static  int               mdoc_sq_pre(MDOC_ARGS);  static  int               mdoc_sq_pre(MDOC_ARGS);
 static  int               mdoc_ss_pre(MDOC_ARGS);  static  int               mdoc_ss_pre(MDOC_ARGS);
Line 240  extern size_t      strlcat(char *, const char *, size_
Line 239  extern size_t      strlcat(char *, const char *, size_
 #endif  #endif
   
 static  const struct htmlmdoc mdocs[MDOC_MAX] = {  static  const struct htmlmdoc mdocs[MDOC_MAX] = {
         {mdoc_pp_pre, NULL}, /* Ap */          {NULL, NULL}, /* Ap */
         {NULL, NULL}, /* Dd */          {NULL, NULL}, /* Dd */
         {NULL, NULL}, /* Dt */          {NULL, NULL}, /* Dt */
         {NULL, NULL}, /* Os */          {NULL, NULL}, /* Os */
         {mdoc_sh_pre, NULL }, /* Sh */          {mdoc_sh_pre, NULL }, /* Sh */
         {mdoc_ss_pre, NULL }, /* Ss */          {mdoc_ss_pre, NULL }, /* Ss */
         {mdoc_pp_pre, NULL}, /* Pp */          {mdoc_sp_pre, NULL}, /* Pp */
         {mdoc_d1_pre, NULL}, /* D1 */          {mdoc_d1_pre, NULL}, /* D1 */
         {mdoc_d1_pre, NULL}, /* Dl */          {mdoc_d1_pre, NULL}, /* Dl */
         {mdoc_bd_pre, NULL}, /* Bd */          {mdoc_bd_pre, NULL}, /* Bd */
Line 347  static const struct htmlmdoc mdocs[MDOC_MAX] = {
Line 346  static const struct htmlmdoc mdocs[MDOC_MAX] = {
         {NULL, NULL}, /* Fr */          {NULL, NULL}, /* Fr */
         {NULL, NULL}, /* Ud */          {NULL, NULL}, /* Ud */
         {NULL, NULL}, /* Lb */          {NULL, NULL}, /* Lb */
         {NULL, NULL}, /* Lp */          {mdoc_sp_pre, NULL}, /* Lp */
         {NULL, NULL}, /* Lk */          {NULL, NULL}, /* Lk */
         {NULL, NULL}, /* Mt */          {NULL, NULL}, /* Mt */
         {NULL, NULL}, /* Brq */          {NULL, NULL}, /* Brq */
Line 358  static const struct htmlmdoc mdocs[MDOC_MAX] = {
Line 357  static const struct htmlmdoc mdocs[MDOC_MAX] = {
         {NULL, NULL}, /* En */          {NULL, NULL}, /* En */
         {mdoc_xx_pre, NULL}, /* Dx */          {mdoc_xx_pre, NULL}, /* Dx */
         {NULL, NULL}, /* %Q */          {NULL, NULL}, /* %Q */
         {NULL, NULL}, /* br */          {mdoc_sp_pre, NULL}, /* br */
         {NULL, NULL}, /* sp */          {mdoc_sp_pre, NULL}, /* sp */
 };  };
   
 static  char              buf[BUFSIZ]; /* XXX */  static  char              buf[BUFSIZ]; /* XXX */
Line 385  html_mdoc(void *arg, const struct mdoc *m)
Line 384  html_mdoc(void *arg, const struct mdoc *m)
 }  }
   
   
   /* ARGSUSED */
 void  void
 html_man(void *arg, const struct man *m)  html_man(void *arg, const struct man *m)
 {  {
         struct html     *h;  
         struct tag      *t;  
   
         h = (struct html *)arg;  
   
         print_gen_doctype(h);  
         t = print_otag(h, TAG_HTML, 0, NULL);  
         print_man(man_meta(m), man_node(m), h);  
         print_tagq(h, t);  
   
         printf("\n");  
 }  }
   
   
Line 406  void *
Line 395  void *
 html_alloc(char *outopts)  html_alloc(char *outopts)
 {  {
         struct html     *h;          struct html     *h;
         char            *toks[3], *o, *v;          char            *toks[3], *v;
   
         toks[0] = "style";          toks[0] = "style";
         toks[1] = "base";          toks[1] = "base";
Line 423  html_alloc(char *outopts)
Line 412  html_alloc(char *outopts)
                 return(NULL);                  return(NULL);
         }          }
   
         while (*outopts) {          while (outopts && *outopts)
                 o = outopts;  
                 switch (getsubopt(&outopts, toks, &v)) {                  switch (getsubopt(&outopts, toks, &v)) {
                 case (0):                  case (0):
                         h->style = v;                          h->style = v;
Line 435  html_alloc(char *outopts)
Line 423  html_alloc(char *outopts)
                 default:                  default:
                         break;                          break;
                 }                  }
         }  
   
         return(h);          return(h);
 }  }
Line 559  static void
Line 546  static void
 print_mdoc(MDOC_ARGS)  print_mdoc(MDOC_ARGS)
 {  {
         struct tag      *t;          struct tag      *t;
           struct htmlpair  tag;
   
         t = print_otag(h, TAG_HEAD, 0, NULL);          t = print_otag(h, TAG_HEAD, 0, NULL);
         print_mdoc_head(m, n, h);          print_mdoc_head(m, n, h);
         print_tagq(h, t);          print_tagq(h, t);
   
         t = print_otag(h, TAG_BODY, 0, NULL);          t = print_otag(h, TAG_BODY, 0, NULL);
   
           tag.key = ATTR_CLASS;
           tag.val = "body";
           print_otag(h, TAG_DIV, 1, &tag);
   
         print_mdoc_nodelist(m, n, h);          print_mdoc_nodelist(m, n, h);
         print_tagq(h, t);          print_tagq(h, t);
 }  }
Line 611  print_gen_head(struct html *h)
Line 604  print_gen_head(struct html *h)
 static void  static void
 print_mdoc_head(MDOC_ARGS)  print_mdoc_head(MDOC_ARGS)
 {  {
           char            b[BUFSIZ];
   
         print_gen_head(h);          print_gen_head(h);
   
           (void)snprintf(b, BUFSIZ - 1,
                           "%s(%d)", m->title, m->msec);
   
           if (m->arch) {
                   (void)strlcat(b, " (", BUFSIZ);
                   (void)strlcat(b, m->arch, BUFSIZ);
                   (void)strlcat(b, ")", BUFSIZ);
           }
   
         print_otag(h, TAG_TITLE, 0, NULL);          print_otag(h, TAG_TITLE, 0, NULL);
         print_text(h, m->title);          print_text(h, b);
 }  }
   
   
Line 674  print_mdoc_node(MDOC_ARGS)
Line 678  print_mdoc_node(MDOC_ARGS)
   
   
 static void  static void
 print_man(MAN_ARGS)  
 {  
         struct tag      *t;  
   
         t = print_otag(h, TAG_HEAD, 0, NULL);  
         print_man_head(m, n, h);  
         print_tagq(h, t);  
   
         t = print_otag(h, TAG_BODY, 0, NULL);  
         /*print_man_body(m, n, h);*/  
         print_tagq(h, t);  
 }  
   
   
 /* ARGSUSED */  
 static void  
 print_man_head(MAN_ARGS)  
 {  
   
         print_gen_head(h);  
         print_otag(h, TAG_TITLE, 0, NULL);  
         print_text(h, m->title);  
 }  
   
   
 static void  
 print_spec(struct html *h, const char *p, int len)  print_spec(struct html *h, const char *p, int len)
 {  {
         const char      *rhs;          const char      *rhs;
Line 916  static void
Line 894  static void
 print_gen_doctype(struct html *h)  print_gen_doctype(struct html *h)
 {  {
   
         printf("<!DOCTYPE HTML PUBLIC \"%s\" \"%s\">\n", DOCTYPE, DTD);          printf("<!DOCTYPE HTML PUBLIC \"%s\" \"%s\">", DOCTYPE, DTD);
 }  }
   
   
Line 1060  mdoc_root_pre(MDOC_ARGS)
Line 1038  mdoc_root_pre(MDOC_ARGS)
                         "%s(%d)", m->title, m->msec);                          "%s(%d)", m->title, m->msec);
   
         tag[0].key = ATTR_CLASS;          tag[0].key = ATTR_CLASS;
         tag[0].val = "body";  
         t = print_otag(h, TAG_DIV, 1, tag);  
   
         tag[0].key = ATTR_CLASS;  
         tag[0].val = "header";          tag[0].val = "header";
         tag[1].key = ATTR_STYLE;          tag[1].key = ATTR_STYLE;
         tag[1].val = "width: 100%;";          tag[1].val = "width: 100%;";
         print_otag(h, TAG_TABLE, 2, tag);          t = print_otag(h, TAG_TABLE, 2, tag);
         tt = print_otag(h, TAG_TR, 0, NULL);          tt = print_otag(h, TAG_TR, 0, NULL);
   
         tag[0].key = ATTR_STYLE;          tag[0].key = ATTR_STYLE;
Line 1086  mdoc_root_pre(MDOC_ARGS)
Line 1060  mdoc_root_pre(MDOC_ARGS)
         tag[0].val = "width: 33%; text-align: right;";          tag[0].val = "width: 33%; text-align: right;";
         print_otag(h, TAG_TD, 1, tag);          print_otag(h, TAG_TD, 1, tag);
         print_text(h, b);          print_text(h, b);
         print_stagq(h, t);          print_tagq(h, t);
   
         return(1);          return(1);
 }  }
Line 1222  mdoc_fl_pre(MDOC_ARGS)
Line 1196  mdoc_fl_pre(MDOC_ARGS)
   
 /* ARGSUSED */  /* ARGSUSED */
 static int  static int
 mdoc_pp_pre(MDOC_ARGS)  
 {  
         struct htmlpair tag;  
   
         tag.key = ATTR_STYLE;  
         tag.val = "clear: both; height: 1em;";  
         print_otag(h, TAG_DIV, 1, &tag);  
         return(0);  
 }  
   
   
 /* ARGSUSED */  
 static int  
 mdoc_nd_pre(MDOC_ARGS)  mdoc_nd_pre(MDOC_ARGS)
 {  {
         struct htmlpair  tag;          struct htmlpair  tag;
Line 1262  mdoc_op_pre(MDOC_ARGS)
Line 1223  mdoc_op_pre(MDOC_ARGS)
   
         /* XXX - this can contain block elements! */          /* XXX - this can contain block elements! */
         print_text(h, "\\(lB");          print_text(h, "\\(lB");
           h->flags |= HTML_NOSPACE;
         tag.key = ATTR_CLASS;          tag.key = ATTR_CLASS;
         tag.val = "opt";          tag.val = "opt";
         print_otag(h, TAG_SPAN, 1, &tag);          print_otag(h, TAG_SPAN, 1, &tag);
Line 1423  mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int
Line 1385  mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int
                 break;                  break;
         }          }
   
         if ( ! c && n->prev && n->prev->body->child)          if ( ! c && MDOC_Column != t) {
                 bufcat("padding-top: 1em;");                 if (n->prev && n->prev->body->child)
                          bufcat("padding-top: 1em;");
                  else if (NULL == n->prev)
                          bufcat("padding-top: 1em;");
           }
   
         tag.key = ATTR_STYLE;          tag.key = ATTR_STYLE;
         tag.val = buf;          tag.val = buf;
Line 2165  mdoc_fn_pre(MDOC_ARGS)
Line 2131  mdoc_fn_pre(MDOC_ARGS)
                 print_text(h, ";");                  print_text(h, ";");
   
         return(0);          return(0);
   }
   
   
   /* ARGSUSED */
   static int
   mdoc_sp_pre(MDOC_ARGS)
   {
           int             len;
           struct htmlpair tag;
   
           switch (n->tok) {
           case (MDOC_sp):
                   len = n->child ? atoi(n->child->string) : 1;
                   break;
           case (MDOC_br):
                   len = 0;
                   break;
           default:
                   len = 1;
                   break;
           }
   
           buffmt("height: %dem", len);
           tag.key = ATTR_STYLE;
           tag.val = buf;
           print_otag(h, TAG_DIV, 1, &tag);
           return(1);
   
 }  }

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.50

CVSweb