Print this page
9718 update mandoc to 1.14.4

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mandoc/man_html.c
          +++ new/usr/src/cmd/mandoc/man_html.c
   1      -/*      $Id: man_html.c,v 1.145 2017/06/25 11:42:02 schwarze Exp $ */
        1 +/*      $Id: man_html.c,v 1.153 2018/07/27 17:49:31 schwarze Exp $ */
   2    2  /*
   3    3   * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
   4      - * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
        4 + * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
   5    5   *
   6    6   * Permission to use, copy, modify, and distribute this software for any
   7    7   * purpose with or without fee is hereby granted, provided that the above
   8    8   * copyright notice and this permission notice appear in all copies.
   9    9   *
  10   10   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
  11   11   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12   12   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
  13   13   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14   14   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
↓ open down ↓ 13 lines elided ↑ open up ↑
  28   28  #include "mandoc_aux.h"
  29   29  #include "mandoc.h"
  30   30  #include "roff.h"
  31   31  #include "man.h"
  32   32  #include "out.h"
  33   33  #include "html.h"
  34   34  #include "main.h"
  35   35  
  36   36  /* FIXME: have PD set the default vspace width. */
  37   37  
  38      -#define INDENT            5
  39      -
  40   38  #define MAN_ARGS          const struct roff_meta *man, \
  41   39                            const struct roff_node *n, \
  42   40                            struct html *h
  43   41  
  44   42  struct  htmlman {
  45   43          int             (*pre)(MAN_ARGS);
  46   44          int             (*post)(MAN_ARGS);
  47   45  };
  48   46  
  49   47  static  void              print_bvspace(struct html *,
  50   48                                  const struct roff_node *);
  51      -static  void              print_man_head(MAN_ARGS);
       49 +static  void              print_man_head(const struct roff_meta *,
       50 +                                struct html *);
  52   51  static  void              print_man_nodelist(MAN_ARGS);
  53   52  static  void              print_man_node(MAN_ARGS);
  54   53  static  int               fillmode(struct html *, int);
  55      -static  int               a2width(const struct roff_node *,
  56      -                                struct roffsu *);
  57   54  static  int               man_B_pre(MAN_ARGS);
  58   55  static  int               man_HP_pre(MAN_ARGS);
  59   56  static  int               man_IP_pre(MAN_ARGS);
  60   57  static  int               man_I_pre(MAN_ARGS);
  61   58  static  int               man_OP_pre(MAN_ARGS);
  62   59  static  int               man_PP_pre(MAN_ARGS);
  63   60  static  int               man_RS_pre(MAN_ARGS);
  64   61  static  int               man_SH_pre(MAN_ARGS);
  65   62  static  int               man_SM_pre(MAN_ARGS);
  66   63  static  int               man_SS_pre(MAN_ARGS);
  67   64  static  int               man_UR_pre(MAN_ARGS);
  68   65  static  int               man_alt_pre(MAN_ARGS);
  69   66  static  int               man_ign_pre(MAN_ARGS);
  70   67  static  int               man_in_pre(MAN_ARGS);
  71      -static  void              man_root_post(MAN_ARGS);
  72      -static  void              man_root_pre(MAN_ARGS);
       68 +static  void              man_root_post(const struct roff_meta *,
       69 +                                struct html *);
       70 +static  void              man_root_pre(const struct roff_meta *,
       71 +                                struct html *);
  73   72  
  74   73  static  const struct htmlman __mans[MAN_MAX - MAN_TH] = {
  75   74          { NULL, NULL }, /* TH */
  76   75          { man_SH_pre, NULL }, /* SH */
  77   76          { man_SS_pre, NULL }, /* SS */
  78   77          { man_IP_pre, NULL }, /* TP */
  79   78          { man_PP_pre, NULL }, /* LP */
  80   79          { man_PP_pre, NULL }, /* PP */
  81   80          { man_PP_pre, NULL }, /* P */
  82   81          { man_IP_pre, NULL }, /* IP */
↓ open down ↓ 48 lines elided ↑ open up ↑
 131  130          if (n->parent->type == ROFFT_ROOT || n->parent->tok != MAN_RS)
 132  131                  if (NULL == n->prev)
 133  132                          return;
 134  133  
 135  134          print_paragraph(h);
 136  135  }
 137  136  
 138  137  void
 139  138  html_man(void *arg, const struct roff_man *man)
 140  139  {
 141      -        struct html     *h;
 142      -        struct tag      *t;
      140 +        struct html             *h;
      141 +        struct roff_node        *n;
      142 +        struct tag              *t;
 143  143  
 144  144          h = (struct html *)arg;
      145 +        n = man->first->child;
 145  146  
 146  147          if ((h->oflags & HTML_FRAGMENT) == 0) {
 147  148                  print_gen_decls(h);
 148  149                  print_otag(h, TAG_HTML, "");
      150 +                if (n->type == ROFFT_COMMENT)
      151 +                        print_gen_comment(h, n);
 149  152                  t = print_otag(h, TAG_HEAD, "");
 150      -                print_man_head(&man->meta, man->first, h);
      153 +                print_man_head(&man->meta, h);
 151  154                  print_tagq(h, t);
 152  155                  print_otag(h, TAG_BODY, "");
 153  156          }
 154  157  
 155      -        man_root_pre(&man->meta, man->first, h);
      158 +        man_root_pre(&man->meta, h);
 156  159          t = print_otag(h, TAG_DIV, "c", "manual-text");
 157      -        print_man_nodelist(&man->meta, man->first->child, h);
      160 +        print_man_nodelist(&man->meta, n, h);
 158  161          print_tagq(h, t);
 159      -        man_root_post(&man->meta, man->first, h);
      162 +        man_root_post(&man->meta, h);
 160  163          print_tagq(h, NULL);
 161  164  }
 162  165  
 163  166  static void
 164      -print_man_head(MAN_ARGS)
      167 +print_man_head(const struct roff_meta *man, struct html *h)
 165  168  {
 166  169          char    *cp;
 167  170  
 168  171          print_gen_head(h);
 169  172          mandoc_asprintf(&cp, "%s(%s)", man->title, man->msec);
 170  173          print_otag(h, TAG_TITLE, "");
 171  174          print_text(h, cp);
 172  175          free(cp);
 173  176  }
 174  177  
↓ open down ↓ 80 lines elided ↑ open up ↑
 255  258          case ROFFT_TEXT:
 256  259                  if (fillmode(h, want_fillmode) == MAN_fi &&
 257  260                      want_fillmode == MAN_fi &&
 258  261                      n->flags & NODE_LINE && *n->string == ' ' &&
 259  262                      (h->flags & HTML_NONEWLINE) == 0)
 260  263                          print_otag(h, TAG_BR, "");
 261  264                  if (*n->string != '\0')
 262  265                          break;
 263  266                  print_paragraph(h);
 264  267                  return;
      268 +        case ROFFT_COMMENT:
      269 +                return;
 265  270          default:
 266  271                  break;
 267  272          }
 268  273  
 269  274          /* Produce output for this node. */
 270  275  
 271  276          child = 1;
 272  277          switch (n->type) {
 273  278          case ROFFT_TEXT:
 274  279                  t = h->tag;
↓ open down ↓ 77 lines elided ↑ open up ↑
 352  357  
 353  358          if (want && want != had) {
 354  359                  if (want == MAN_nf)
 355  360                          print_otag(h, TAG_PRE, "");
 356  361                  else
 357  362                          print_tagq(h, pre);
 358  363          }
 359  364          return had;
 360  365  }
 361  366  
 362      -static int
 363      -a2width(const struct roff_node *n, struct roffsu *su)
 364      -{
 365      -        if (n->type != ROFFT_TEXT)
 366      -                return 0;
 367      -        return a2roffsu(n->string, su, SCALE_EN) != NULL;
 368      -}
 369      -
 370  367  static void
 371      -man_root_pre(MAN_ARGS)
      368 +man_root_pre(const struct roff_meta *man, struct html *h)
 372  369  {
 373  370          struct tag      *t, *tt;
 374  371          char            *title;
 375  372  
 376  373          assert(man->title);
 377  374          assert(man->msec);
 378  375          mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
 379  376  
 380  377          t = print_otag(h, TAG_TABLE, "c", "head");
 381  378          tt = print_otag(h, TAG_TR, "");
↓ open down ↓ 7 lines elided ↑ open up ↑
 389  386                  print_text(h, man->vol);
 390  387          print_stagq(h, tt);
 391  388  
 392  389          print_otag(h, TAG_TD, "c", "head-rtitle");
 393  390          print_text(h, title);
 394  391          print_tagq(h, t);
 395  392          free(title);
 396  393  }
 397  394  
 398  395  static void
 399      -man_root_post(MAN_ARGS)
      396 +man_root_post(const struct roff_meta *man, struct html *h)
 400  397  {
 401  398          struct tag      *t, *tt;
 402  399  
 403  400          t = print_otag(h, TAG_TABLE, "c", "foot");
 404  401          tt = print_otag(h, TAG_TR, "");
 405  402  
 406  403          print_otag(h, TAG_TD, "c", "foot-date");
 407  404          print_text(h, man->date);
 408  405          print_stagq(h, tt);
 409  406  
↓ open down ↓ 2 lines elided ↑ open up ↑
 412  409                  print_text(h, man->os);
 413  410          print_tagq(h, t);
 414  411  }
 415  412  
 416  413  static int
 417  414  man_SH_pre(MAN_ARGS)
 418  415  {
 419  416          char    *id;
 420  417  
 421  418          if (n->type == ROFFT_HEAD) {
 422      -                id = html_make_id(n);
      419 +                id = html_make_id(n, 1);
 423  420                  print_otag(h, TAG_H1, "cTi", "Sh", id);
 424  421                  if (id != NULL)
 425      -                        print_otag(h, TAG_A, "chR", "selflink", id);
 426      -                free(id);
      422 +                        print_otag(h, TAG_A, "chR", "permalink", id);
 427  423          }
 428  424          return 1;
 429  425  }
 430  426  
 431  427  static int
 432  428  man_alt_pre(MAN_ARGS)
 433  429  {
 434  430          const struct roff_node  *nn;
 435  431          int              i;
 436  432          enum htmltag     fp;
↓ open down ↓ 45 lines elided ↑ open up ↑
 482  478                  print_otag(h, TAG_B, "");
 483  479          return 1;
 484  480  }
 485  481  
 486  482  static int
 487  483  man_SS_pre(MAN_ARGS)
 488  484  {
 489  485          char    *id;
 490  486  
 491  487          if (n->type == ROFFT_HEAD) {
 492      -                id = html_make_id(n);
      488 +                id = html_make_id(n, 1);
 493  489                  print_otag(h, TAG_H2, "cTi", "Ss", id);
 494  490                  if (id != NULL)
 495      -                        print_otag(h, TAG_A, "chR", "selflink", id);
 496      -                free(id);
      491 +                        print_otag(h, TAG_A, "chR", "permalink", id);
 497  492          }
 498  493          return 1;
 499  494  }
 500  495  
 501  496  static int
 502  497  man_PP_pre(MAN_ARGS)
 503  498  {
 504  499  
 505  500          if (n->type == ROFFT_HEAD)
 506  501                  return 0;
↓ open down ↓ 2 lines elided ↑ open up ↑
 509  504  
 510  505          return 1;
 511  506  }
 512  507  
 513  508  static int
 514  509  man_IP_pre(MAN_ARGS)
 515  510  {
 516  511          const struct roff_node  *nn;
 517  512  
 518  513          if (n->type == ROFFT_BODY) {
 519      -                print_otag(h, TAG_DD, "c", "It-tag");
      514 +                print_otag(h, TAG_DD, "");
 520  515                  return 1;
 521  516          } else if (n->type != ROFFT_HEAD) {
 522  517                  print_otag(h, TAG_DL, "c", "Bl-tag");
 523  518                  return 1;
 524  519          }
 525  520  
 526  521          /* FIXME: width specification. */
 527  522  
 528      -        print_otag(h, TAG_DT, "c", "It-tag");
      523 +        print_otag(h, TAG_DT, "");
 529  524  
 530  525          /* For IP, only print the first header element. */
 531  526  
 532  527          if (MAN_IP == n->tok && n->child)
 533  528                  print_man_node(man, n->child, h);
 534  529  
 535  530          /* For TP, only print next-line header elements. */
 536  531  
 537  532          if (MAN_TP == n->tok) {
 538  533                  nn = n->child;
↓ open down ↓ 4 lines elided ↑ open up ↑
 543  538                          nn = nn->next;
 544  539                  }
 545  540          }
 546  541  
 547  542          return 0;
 548  543  }
 549  544  
 550  545  static int
 551  546  man_HP_pre(MAN_ARGS)
 552  547  {
 553      -        struct roffsu    sum, sui;
 554      -        const struct roff_node *np;
 555      -
 556  548          if (n->type == ROFFT_HEAD)
 557  549                  return 0;
 558      -        else if (n->type != ROFFT_BLOCK)
 559      -                return 1;
 560  550  
 561      -        np = n->head->child;
 562      -
 563      -        if (np == NULL || !a2width(np, &sum))
 564      -                SCALE_HS_INIT(&sum, INDENT);
 565      -
 566      -        sui.unit = sum.unit;
 567      -        sui.scale = -sum.scale;
 568      -
 569      -        print_bvspace(h, n);
 570      -        print_otag(h, TAG_DIV, "csului", "Pp", &sum, &sui);
      551 +        if (n->type == ROFFT_BLOCK) {
      552 +                print_bvspace(h, n);
      553 +                print_otag(h, TAG_DIV, "c", "HP");
      554 +        }
 571  555          return 1;
 572  556  }
 573  557  
 574  558  static int
 575  559  man_OP_pre(MAN_ARGS)
 576  560  {
 577  561          struct tag      *tt;
 578  562  
 579  563          print_text(h, "[");
 580  564          h->flags |= HTML_NOSPACE;
↓ open down ↓ 41 lines elided ↑ open up ↑
 622  606  static int
 623  607  man_ign_pre(MAN_ARGS)
 624  608  {
 625  609  
 626  610          return 0;
 627  611  }
 628  612  
 629  613  static int
 630  614  man_RS_pre(MAN_ARGS)
 631  615  {
 632      -        struct roffsu    su;
 633      -
 634  616          if (n->type == ROFFT_HEAD)
 635  617                  return 0;
 636      -        else if (n->type == ROFFT_BODY)
 637      -                return 1;
 638      -
 639      -        SCALE_HS_INIT(&su, INDENT);
 640      -        if (n->head->child)
 641      -                a2width(n->head->child, &su);
 642      -
 643      -        print_otag(h, TAG_DIV, "sul", &su);
      618 +        if (n->type == ROFFT_BLOCK)
      619 +                print_otag(h, TAG_DIV, "c", "Bd-indent");
 644  620          return 1;
 645  621  }
 646  622  
 647  623  static int
 648  624  man_UR_pre(MAN_ARGS)
 649  625  {
 650  626          char *cp;
 651  627          n = n->child;
 652  628          assert(n->type == ROFFT_HEAD);
 653  629          if (n->child != NULL) {
↓ open down ↓ 17 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX