Print this page
5051 import mdocml-1.12.3
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Approved by: TBD

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mandoc/mdoc_html.c
          +++ new/usr/src/cmd/mandoc/mdoc_html.c
   1      -/*      $Id: mdoc_html.c,v 1.182 2011/11/03 20:37:00 schwarze Exp $ */
        1 +/*      $Id: mdoc_html.c,v 1.186 2013/12/24 20:45:27 schwarze Exp $ */
   2    2  /*
   3    3   * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
   4    4   *
   5    5   * Permission to use, copy, modify, and distribute this software for any
   6    6   * purpose with or without fee is hereby granted, provided that the above
   7    7   * copyright notice and this permission notice appear in all copies.
   8    8   *
   9    9   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10   10   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11   11   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
↓ open down ↓ 16 lines elided ↑ open up ↑
  28   28  #include <unistd.h>
  29   29  
  30   30  #include "mandoc.h"
  31   31  #include "out.h"
  32   32  #include "html.h"
  33   33  #include "mdoc.h"
  34   34  #include "main.h"
  35   35  
  36   36  #define INDENT           5
  37   37  
  38      -#define MDOC_ARGS         const struct mdoc_meta *m, \
       38 +#define MDOC_ARGS         const struct mdoc_meta *meta, \
  39   39                            const struct mdoc_node *n, \
  40   40                            struct html *h
  41   41  
  42   42  #ifndef MIN
  43   43  #define MIN(a,b)        ((/*CONSTCOND*/(a)<(b))?(a):(b))
  44   44  #endif
  45   45  
  46   46  struct  htmlmdoc {
  47   47          int             (*pre)(MDOC_ARGS);
  48   48          void            (*post)(MDOC_ARGS);
↓ open down ↓ 204 lines elided ↑ open up ↑
 253  253          "list-enum",
 254  254          "list-hang",
 255  255          "list-hyph",
 256  256          "list-inset",
 257  257          "list-item",
 258  258          "list-ohang",
 259  259          "list-tag"
 260  260  };
 261  261  
 262  262  void
 263      -html_mdoc(void *arg, const struct mdoc *m)
      263 +html_mdoc(void *arg, const struct mdoc *mdoc)
 264  264  {
 265  265  
 266      -        print_mdoc(mdoc_meta(m), mdoc_node(m), (struct html *)arg);
      266 +        print_mdoc(mdoc_meta(mdoc), mdoc_node(mdoc),
      267 +                        (struct html *)arg);
 267  268          putchar('\n');
 268  269  }
 269  270  
 270  271  
 271  272  /*
 272  273   * Calculate the scaling unit passed in a `-width' argument.  This uses
 273  274   * either a native scaling unit (e.g., 1i, 2m) or the string length of
 274  275   * the value.
 275  276   */
 276  277  static void
↓ open down ↓ 77 lines elided ↑ open up ↑
 354  355  {
 355  356          struct tag      *t, *tt;
 356  357          struct htmlpair  tag;
 357  358  
 358  359          PAIR_CLASS_INIT(&tag, "mandoc");
 359  360  
 360  361          if ( ! (HTML_FRAGMENT & h->oflags)) {
 361  362                  print_gen_decls(h);
 362  363                  t = print_otag(h, TAG_HTML, 0, NULL);
 363  364                  tt = print_otag(h, TAG_HEAD, 0, NULL);
 364      -                print_mdoc_head(m, n, h);
      365 +                print_mdoc_head(meta, n, h);
 365  366                  print_tagq(h, tt);
 366  367                  print_otag(h, TAG_BODY, 0, NULL);
 367  368                  print_otag(h, TAG_DIV, 1, &tag);
 368  369          } else 
 369  370                  t = print_otag(h, TAG_DIV, 1, &tag);
 370  371  
 371      -        print_mdoc_nodelist(m, n, h);
      372 +        print_mdoc_nodelist(meta, n, h);
 372  373          print_tagq(h, t);
 373  374  }
 374  375  
 375  376  
 376  377  /* ARGSUSED */
 377  378  static void
 378  379  print_mdoc_head(MDOC_ARGS)
 379  380  {
 380  381  
 381  382          print_gen_head(h);
 382  383          bufinit(h);
 383      -        bufcat_fmt(h, "%s(%s)", m->title, m->msec);
      384 +        bufcat_fmt(h, "%s(%s)", meta->title, meta->msec);
 384  385  
 385      -        if (m->arch)
 386      -                bufcat_fmt(h, " (%s)", m->arch);
      386 +        if (meta->arch)
      387 +                bufcat_fmt(h, " (%s)", meta->arch);
 387  388  
 388  389          print_otag(h, TAG_TITLE, 0, NULL);
 389  390          print_text(h, h->buf);
 390  391  }
 391  392  
 392  393  
 393  394  static void
 394  395  print_mdoc_nodelist(MDOC_ARGS)
 395  396  {
 396  397  
 397      -        print_mdoc_node(m, n, h);
      398 +        print_mdoc_node(meta, n, h);
 398  399          if (n->next)
 399      -                print_mdoc_nodelist(m, n->next, h);
      400 +                print_mdoc_nodelist(meta, n->next, h);
 400  401  }
 401  402  
 402  403  
 403  404  static void
 404  405  print_mdoc_node(MDOC_ARGS)
 405  406  {
 406  407          int              child;
 407  408          struct tag      *t;
 408  409  
 409  410          child = 1;
 410  411          t = h->tags.head;
 411  412  
 412  413          switch (n->type) {
 413  414          case (MDOC_ROOT):
 414      -                child = mdoc_root_pre(m, n, h);
      415 +                child = mdoc_root_pre(meta, n, h);
 415  416                  break;
 416  417          case (MDOC_TEXT):
 417  418                  /* No tables in this mode... */
 418  419                  assert(NULL == h->tblt);
 419  420  
 420  421                  /*
 421  422                   * Make sure that if we're in a literal mode already
 422  423                   * (i.e., within a <PRE>) don't print the newline.
 423  424                   */
 424  425                  if (' ' == *n->string && MDOC_LINE & n->flags)
↓ open down ↓ 22 lines elided ↑ open up ↑
 447  448                   * the "meta" table state.  This will be reopened on the
 448  449                   * next table element.
 449  450                   */
 450  451                  if (h->tblt) {
 451  452                          print_tblclose(h);
 452  453                          t = h->tags.head;
 453  454                  }
 454  455  
 455  456                  assert(NULL == h->tblt);
 456  457                  if (mdocs[n->tok].pre && ENDBODY_NOT == n->end)
 457      -                        child = (*mdocs[n->tok].pre)(m, n, h);
      458 +                        child = (*mdocs[n->tok].pre)(meta, n, h);
 458  459                  break;
 459  460          }
 460  461  
 461  462          if (HTML_KEEP & h->flags) {
 462      -                if (n->prev && n->prev->line != n->line) {
      463 +                if (n->prev ? (n->prev->lastline != n->line) :
      464 +                    (n->parent && n->parent->line != n->line)) {
 463  465                          h->flags &= ~HTML_KEEP;
 464  466                          h->flags |= HTML_PREKEEP;
 465      -                } else if (NULL == n->prev) {
 466      -                        if (n->parent && n->parent->line != n->line) {
 467      -                                h->flags &= ~HTML_KEEP;
 468      -                                h->flags |= HTML_PREKEEP;
 469      -                        }
 470  467                  }
 471  468          }
 472  469  
 473  470          if (child && n->child)
 474      -                print_mdoc_nodelist(m, n->child, h);
      471 +                print_mdoc_nodelist(meta, n->child, h);
 475  472  
 476  473          print_stagq(h, t);
 477  474  
 478  475          switch (n->type) {
 479  476          case (MDOC_ROOT):
 480      -                mdoc_root_post(m, n, h);
      477 +                mdoc_root_post(meta, n, h);
 481  478                  break;
 482  479          case (MDOC_EQN):
 483  480                  break;
 484  481          default:
 485  482                  if (mdocs[n->tok].post && ENDBODY_NOT == n->end)
 486      -                        (*mdocs[n->tok].post)(m, n, h);
      483 +                        (*mdocs[n->tok].post)(meta, n, h);
 487  484                  break;
 488  485          }
 489  486  }
 490  487  
 491  488  /* ARGSUSED */
 492  489  static void
 493  490  mdoc_root_post(MDOC_ARGS)
 494  491  {
 495  492          struct htmlpair  tag[3];
 496  493          struct tag      *t, *tt;
↓ open down ↓ 5 lines elided ↑ open up ↑
 502  499          PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
 503  500          print_otag(h, TAG_COL, 1, tag);
 504  501          print_otag(h, TAG_COL, 1, tag);
 505  502  
 506  503          print_otag(h, TAG_TBODY, 0, NULL);
 507  504  
 508  505          tt = print_otag(h, TAG_TR, 0, NULL);
 509  506  
 510  507          PAIR_CLASS_INIT(&tag[0], "foot-date");
 511  508          print_otag(h, TAG_TD, 1, tag);
 512      -        print_text(h, m->date);
      509 +        print_text(h, meta->date);
 513  510          print_stagq(h, tt);
 514  511  
 515  512          PAIR_CLASS_INIT(&tag[0], "foot-os");
 516  513          PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
 517  514          print_otag(h, TAG_TD, 2, tag);
 518      -        print_text(h, m->os);
      515 +        print_text(h, meta->os);
 519  516          print_tagq(h, t);
 520  517  }
 521  518  
 522  519  
 523  520  /* ARGSUSED */
 524  521  static int
 525  522  mdoc_root_pre(MDOC_ARGS)
 526  523  {
 527  524          struct htmlpair  tag[3];
 528  525          struct tag      *t, *tt;
 529  526          char             b[BUFSIZ], title[BUFSIZ];
 530  527  
 531      -        strlcpy(b, m->vol, BUFSIZ);
      528 +        strlcpy(b, meta->vol, BUFSIZ);
 532  529  
 533      -        if (m->arch) {
      530 +        if (meta->arch) {
 534  531                  strlcat(b, " (", BUFSIZ);
 535      -                strlcat(b, m->arch, BUFSIZ);
      532 +                strlcat(b, meta->arch, BUFSIZ);
 536  533                  strlcat(b, ")", BUFSIZ);
 537  534          }
 538  535  
 539      -        snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
      536 +        snprintf(title, BUFSIZ - 1, "%s(%s)", meta->title, meta->msec);
 540  537  
 541  538          PAIR_SUMMARY_INIT(&tag[0], "Document Header");
 542  539          PAIR_CLASS_INIT(&tag[1], "head");
 543  540          PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
 544  541          t = print_otag(h, TAG_TABLE, 3, tag);
 545  542          PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
 546  543          print_otag(h, TAG_COL, 1, tag);
 547  544          print_otag(h, TAG_COL, 1, tag);
 548  545          print_otag(h, TAG_COL, 1, tag);
 549  546  
↓ open down ↓ 132 lines elided ↑ open up ↑
 682  679  {
 683  680          struct htmlpair  tag;
 684  681          struct roffsu    su;
 685  682          int              len;
 686  683  
 687  684          switch (n->type) {
 688  685          case (MDOC_ELEM):
 689  686                  synopsis_pre(h, n);
 690  687                  PAIR_CLASS_INIT(&tag, "name");
 691  688                  print_otag(h, TAG_B, 1, &tag);
 692      -                if (NULL == n->child && m->name)
 693      -                        print_text(h, m->name);
      689 +                if (NULL == n->child && meta->name)
      690 +                        print_text(h, meta->name);
 694  691                  return(1);
 695  692          case (MDOC_HEAD):
 696  693                  print_otag(h, TAG_TD, 0, NULL);
 697      -                if (NULL == n->child && m->name)
 698      -                        print_text(h, m->name);
      694 +                if (NULL == n->child && meta->name)
      695 +                        print_text(h, meta->name);
 699  696                  return(1);
 700  697          case (MDOC_BODY):
 701  698                  print_otag(h, TAG_TD, 0, NULL);
 702  699                  return(1);
 703  700          default:
 704  701                  break;
 705  702          }
 706  703  
 707  704          synopsis_pre(h, n);
 708  705          PAIR_CLASS_INIT(&tag, "synopsis");
 709  706          print_otag(h, TAG_TABLE, 1, &tag);
 710  707  
 711  708          for (len = 0, n = n->child; n; n = n->next)
 712  709                  if (MDOC_TEXT == n->type)
 713  710                          len += html_strlen(n->string);
 714  711  
 715      -        if (0 == len && m->name)
 716      -                len = html_strlen(m->name);
      712 +        if (0 == len && meta->name)
      713 +                len = html_strlen(meta->name);
 717  714  
 718  715          SCALE_HS_INIT(&su, (double)len);
 719  716          bufinit(h);
 720  717          bufcat_su(h, "width", &su);
 721  718          PAIR_STYLE_INIT(&tag, h);
 722  719          print_otag(h, TAG_COL, 1, &tag);
 723  720          print_otag(h, TAG_COL, 0, NULL);
 724  721          print_otag(h, TAG_TBODY, 0, NULL);
 725  722          print_otag(h, TAG_TR, 0, NULL);
 726  723          return(1);
↓ open down ↓ 247 lines elided ↑ open up ↑
 974  971  
 975  972  /* ARGSUSED */
 976  973  static int
 977  974  mdoc_bl_pre(MDOC_ARGS)
 978  975  {
 979  976          int              i;
 980  977          struct htmlpair  tag[3];
 981  978          struct roffsu    su;
 982  979          char             buf[BUFSIZ];
 983  980  
 984      -        bufinit(h);
 985      -
 986  981          if (MDOC_BODY == n->type) {
 987  982                  if (LIST_column == n->norm->Bl.type)
 988  983                          print_otag(h, TAG_TBODY, 0, NULL);
 989  984                  return(1);
 990  985          }
 991  986  
 992  987          if (MDOC_HEAD == n->type) {
 993  988                  if (LIST_column != n->norm->Bl.type)
 994  989                          return(0);
 995  990  
 996  991                  /*
 997  992                   * For each column, print out the <COL> tag with our
 998  993                   * suggested width.  The last column gets min-width, as
 999  994                   * in terminal mode it auto-sizes to the width of the
1000  995                   * screen and we want to preserve that behaviour.
1001  996                   */
1002  997  
1003  998                  for (i = 0; i < (int)n->norm->Bl.ncols; i++) {
      999 +                        bufinit(h);
1004 1000                          a2width(n->norm->Bl.cols[i], &su);
1005 1001                          if (i < (int)n->norm->Bl.ncols - 1)
1006 1002                                  bufcat_su(h, "width", &su);
1007 1003                          else
1008 1004                                  bufcat_su(h, "min-width", &su);
1009 1005                          PAIR_STYLE_INIT(&tag[0], h);
1010 1006                          print_otag(h, TAG_COL, 1, tag);
1011 1007                  }
1012 1008  
1013 1009                  return(0);
1014 1010          }
1015 1011  
1016 1012          SCALE_VS_INIT(&su, 0);
     1013 +        bufinit(h);
1017 1014          bufcat_su(h, "margin-top", &su);
1018 1015          bufcat_su(h, "margin-bottom", &su);
1019 1016          PAIR_STYLE_INIT(&tag[0], h);
1020 1017  
1021 1018          assert(lists[n->norm->Bl.type]);
1022 1019          strlcpy(buf, "list ", BUFSIZ);
1023 1020          strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
1024 1021          PAIR_INIT(&tag[1], ATTR_CLASS, buf);
1025 1022  
1026 1023          /* Set the block's left-hand margin. */
↓ open down ↓ 191 lines elided ↑ open up ↑
1218 1215  
1219 1216          PAIR_CLASS_INIT(&tag[1], "lit display");
1220 1217          print_otag(h, TAG_PRE, 2, tag);
1221 1218  
1222 1219          /* This can be recursive: save & set our literal state. */
1223 1220  
1224 1221          sv = h->flags & HTML_LITERAL;
1225 1222          h->flags |= HTML_LITERAL;
1226 1223  
1227 1224          for (nn = n->child; nn; nn = nn->next) {
1228      -                print_mdoc_node(m, nn, h);
     1225 +                print_mdoc_node(meta, nn, h);
1229 1226                  /*
1230 1227                   * If the printed node flushes its own line, then we
1231 1228                   * needn't do it here as well.  This is hacky, but the
1232 1229                   * notion of selective eoln whitespace is pretty dumb
1233 1230                   * anyway, so don't sweat it.
1234 1231                   */
1235 1232                  switch (nn->tok) {
1236 1233                  case (MDOC_Sm):
1237 1234                          /* FALLTHROUGH */
1238 1235                  case (MDOC_br):
↓ open down ↓ 1027 lines elided ↑ open up ↑
2266 2263          case (MDOC_Po):
2267 2264                  /* FALLTHROUGH */
2268 2265          case (MDOC_Pq):
2269 2266                  print_text(h, ")");
2270 2267                  break;
2271 2268          case (MDOC_Ql):
2272 2269                  /* FALLTHROUGH */
2273 2270          case (MDOC_So):
2274 2271                  /* FALLTHROUGH */
2275 2272          case (MDOC_Sq):
2276      -                print_text(h, "\\(aq");
     2273 +                print_text(h, "\\(cq");
2277 2274                  break;
2278 2275          default:
2279 2276                  abort();
2280 2277                  /* NOTREACHED */
2281 2278          }
2282 2279  }
2283 2280  
2284 2281  
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX