Print this page
Update to 1.12.3.

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.86 2012/01/03 15:16:24 kristaps Exp $ */
        1 +/*      $Id: man_html.c,v 1.90 2013/10/17 20:54:58 schwarze Exp $ */
   2    2  /*
   3      - * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
        3 + * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
        4 + * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
   4    5   *
   5    6   * Permission to use, copy, modify, and distribute this software for any
   6    7   * purpose with or without fee is hereby granted, provided that the above
   7    8   * copyright notice and this permission notice appear in all copies.
   8    9   *
   9   10   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10   11   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11   12   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12   13   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13   14   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
↓ open down ↓ 16 lines elided ↑ open up ↑
  30   31  #include "out.h"
  31   32  #include "html.h"
  32   33  #include "man.h"
  33   34  #include "main.h"
  34   35  
  35   36  /* TODO: preserve ident widths. */
  36   37  /* FIXME: have PD set the default vspace width. */
  37   38  
  38   39  #define INDENT            5
  39   40  
  40      -#define MAN_ARGS          const struct man_meta *m, \
       41 +#define MAN_ARGS          const struct man_meta *man, \
  41   42                            const struct man_node *n, \
  42   43                            struct mhtml *mh, \
  43   44                            struct html *h
  44   45  
  45   46  struct  mhtml {
  46   47          int               fl;
  47   48  #define MANH_LITERAL     (1 << 0) /* literal context */
  48   49  };
  49   50  
  50   51  struct  htmlman {
↓ open down ↓ 12 lines elided ↑ open up ↑
  63   64  static  int               man_B_pre(MAN_ARGS);
  64   65  static  int               man_HP_pre(MAN_ARGS);
  65   66  static  int               man_IP_pre(MAN_ARGS);
  66   67  static  int               man_I_pre(MAN_ARGS);
  67   68  static  int               man_OP_pre(MAN_ARGS);
  68   69  static  int               man_PP_pre(MAN_ARGS);
  69   70  static  int               man_RS_pre(MAN_ARGS);
  70   71  static  int               man_SH_pre(MAN_ARGS);
  71   72  static  int               man_SM_pre(MAN_ARGS);
  72   73  static  int               man_SS_pre(MAN_ARGS);
       74 +static  int               man_UR_pre(MAN_ARGS);
  73   75  static  int               man_alt_pre(MAN_ARGS);
  74   76  static  int               man_br_pre(MAN_ARGS);
  75   77  static  int               man_ign_pre(MAN_ARGS);
  76   78  static  int               man_in_pre(MAN_ARGS);
  77   79  static  int               man_literal_pre(MAN_ARGS);
  78   80  static  void              man_root_post(MAN_ARGS);
  79   81  static  void              man_root_pre(MAN_ARGS);
  80   82  
  81   83  static  const struct htmlman mans[MAN_MAX] = {
  82   84          { man_br_pre, NULL }, /* br */
↓ open down ↓ 23 lines elided ↑ open up ↑
 106  108          { man_literal_pre, NULL }, /* fi */
 107  109          { NULL, NULL }, /* RE */
 108  110          { man_RS_pre, NULL }, /* RS */
 109  111          { man_ign_pre, NULL }, /* DT */
 110  112          { man_ign_pre, NULL }, /* UC */
 111  113          { man_ign_pre, NULL }, /* PD */
 112  114          { man_ign_pre, NULL }, /* AT */
 113  115          { man_in_pre, NULL }, /* in */
 114  116          { man_ign_pre, NULL }, /* ft */
 115  117          { man_OP_pre, NULL }, /* OP */
      118 +        { man_literal_pre, NULL }, /* EX */
      119 +        { man_literal_pre, NULL }, /* EE */
      120 +        { man_UR_pre, NULL }, /* UR */
      121 +        { NULL, NULL }, /* UE */
 116  122  };
 117  123  
 118  124  /*
 119  125   * Printing leading vertical space before a block.
 120  126   * This is used for the paragraph macros.
 121  127   * The rules are pretty simple, since there's very little nesting going
 122  128   * on here.  Basically, if we're the first within another block (SS/SH),
 123  129   * then don't emit vertical space.  If we are (RS), then do.  If not the
 124  130   * first, print it.
 125  131   */
↓ open down ↓ 6 lines elided ↑ open up ↑
 132  138                          return;
 133  139  
 134  140          if (MAN_ROOT == n->parent->type || MAN_RS != n->parent->tok)
 135  141                  if (NULL == n->prev)
 136  142                          return;
 137  143  
 138  144          print_otag(h, TAG_P, 0, NULL);
 139  145  }
 140  146  
 141  147  void
 142      -html_man(void *arg, const struct man *m)
      148 +html_man(void *arg, const struct man *man)
 143  149  {
 144  150          struct mhtml     mh;
 145  151  
 146  152          memset(&mh, 0, sizeof(struct mhtml));
 147      -        print_man(man_meta(m), man_node(m), &mh, (struct html *)arg);
      153 +        print_man(man_meta(man), man_node(man), &mh, (struct html *)arg);
 148  154          putchar('\n');
 149  155  }
 150  156  
 151  157  static void
 152  158  print_man(MAN_ARGS) 
 153  159  {
 154  160          struct tag      *t, *tt;
 155  161          struct htmlpair  tag;
 156  162  
 157  163          PAIR_CLASS_INIT(&tag, "mandoc");
 158  164  
 159  165          if ( ! (HTML_FRAGMENT & h->oflags)) {
 160  166                  print_gen_decls(h);
 161  167                  t = print_otag(h, TAG_HTML, 0, NULL);
 162  168                  tt = print_otag(h, TAG_HEAD, 0, NULL);
 163      -                print_man_head(m, n, mh, h);
      169 +                print_man_head(man, n, mh, h);
 164  170                  print_tagq(h, tt);
 165  171                  print_otag(h, TAG_BODY, 0, NULL);
 166  172                  print_otag(h, TAG_DIV, 1, &tag);
 167  173          } else 
 168  174                  t = print_otag(h, TAG_DIV, 1, &tag);
 169  175  
 170      -        print_man_nodelist(m, n, mh, h);
      176 +        print_man_nodelist(man, n, mh, h);
 171  177          print_tagq(h, t);
 172  178  }
 173  179  
 174  180  
 175  181  /* ARGSUSED */
 176  182  static void
 177  183  print_man_head(MAN_ARGS)
 178  184  {
 179  185  
 180  186          print_gen_head(h);
 181      -        assert(m->title);
 182      -        assert(m->msec);
 183      -        bufcat_fmt(h, "%s(%s)", m->title, m->msec);
      187 +        assert(man->title);
      188 +        assert(man->msec);
      189 +        bufcat_fmt(h, "%s(%s)", man->title, man->msec);
 184  190          print_otag(h, TAG_TITLE, 0, NULL);
 185  191          print_text(h, h->buf);
 186  192  }
 187  193  
 188  194  
 189  195  static void
 190  196  print_man_nodelist(MAN_ARGS)
 191  197  {
 192  198  
 193      -        print_man_node(m, n, mh, h);
      199 +        print_man_node(man, n, mh, h);
 194  200          if (n->next)
 195      -                print_man_nodelist(m, n->next, mh, h);
      201 +                print_man_nodelist(man, n->next, mh, h);
 196  202  }
 197  203  
 198  204  
 199  205  static void
 200  206  print_man_node(MAN_ARGS)
 201  207  {
 202  208          int              child;
 203  209          struct tag      *t;
 204  210  
 205  211          child = 1;
 206  212          t = h->tags.head;
 207  213  
 208  214          switch (n->type) {
 209  215          case (MAN_ROOT):
 210      -                man_root_pre(m, n, mh, h);
      216 +                man_root_pre(man, n, mh, h);
 211  217                  break;
 212  218          case (MAN_TEXT):
 213  219                  /*
 214  220                   * If we have a blank line, output a vertical space.
 215  221                   * If we have a space as the first character, break
 216  222                   * before printing the line's data.
 217  223                   */
 218  224                  if ('\0' == *n->string) {
 219  225                          print_otag(h, TAG_P, 0, NULL);
 220  226                          return;
↓ open down ↓ 30 lines elided ↑ open up ↑
 251  257                  /*
 252  258                   * Close out the current table, if it's open, and unset
 253  259                   * the "meta" table state.  This will be reopened on the
 254  260                   * next table element.
 255  261                   */
 256  262                  if (h->tblt) {
 257  263                          print_tblclose(h);
 258  264                          t = h->tags.head;
 259  265                  }
 260  266                  if (mans[n->tok].pre)
 261      -                        child = (*mans[n->tok].pre)(m, n, mh, h);
      267 +                        child = (*mans[n->tok].pre)(man, n, mh, h);
 262  268                  break;
 263  269          }
 264  270  
 265  271          if (child && n->child)
 266      -                print_man_nodelist(m, n->child, mh, h);
      272 +                print_man_nodelist(man, n->child, mh, h);
 267  273  
 268  274          /* This will automatically close out any font scope. */
 269  275          print_stagq(h, t);
 270  276  
 271  277          switch (n->type) {
 272  278          case (MAN_ROOT):
 273      -                man_root_post(m, n, mh, h);
      279 +                man_root_post(man, n, mh, h);
 274  280                  break;
 275  281          case (MAN_EQN):
 276  282                  break;
 277  283          default:
 278  284                  if (mans[n->tok].post)
 279      -                        (*mans[n->tok].post)(m, n, mh, h);
      285 +                        (*mans[n->tok].post)(man, n, mh, h);
 280  286                  break;
 281  287          }
 282  288  }
 283  289  
 284  290  
 285  291  static int
 286  292  a2width(const struct man_node *n, struct roffsu *su)
 287  293  {
 288  294  
 289  295          if (MAN_TEXT != n->type)
↓ open down ↓ 7 lines elided ↑ open up ↑
 297  303  
 298  304  /* ARGSUSED */
 299  305  static void
 300  306  man_root_pre(MAN_ARGS)
 301  307  {
 302  308          struct htmlpair  tag[3];
 303  309          struct tag      *t, *tt;
 304  310          char             b[BUFSIZ], title[BUFSIZ];
 305  311  
 306  312          b[0] = 0;
 307      -        if (m->vol)
 308      -                (void)strlcat(b, m->vol, BUFSIZ);
      313 +        if (man->vol)
      314 +                (void)strlcat(b, man->vol, BUFSIZ);
 309  315  
 310      -        assert(m->title);
 311      -        assert(m->msec);
 312      -        snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
      316 +        assert(man->title);
      317 +        assert(man->msec);
      318 +        snprintf(title, BUFSIZ - 1, "%s(%s)", man->title, man->msec);
 313  319  
 314  320          PAIR_SUMMARY_INIT(&tag[0], "Document Header");
 315  321          PAIR_CLASS_INIT(&tag[1], "head");
 316  322          PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
 317  323          t = print_otag(h, TAG_TABLE, 3, tag);
 318  324          PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
 319  325          print_otag(h, TAG_COL, 1, tag);
 320  326          print_otag(h, TAG_COL, 1, tag);
 321  327          print_otag(h, TAG_COL, 1, tag);
 322  328  
↓ open down ↓ 33 lines elided ↑ open up ↑
 356  362          t = print_otag(h, TAG_TABLE, 3, tag);
 357  363          PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
 358  364          print_otag(h, TAG_COL, 1, tag);
 359  365          print_otag(h, TAG_COL, 1, tag);
 360  366  
 361  367          tt = print_otag(h, TAG_TR, 0, NULL);
 362  368  
 363  369          PAIR_CLASS_INIT(&tag[0], "foot-date");
 364  370          print_otag(h, TAG_TD, 1, tag);
 365  371  
 366      -        assert(m->date);
 367      -        print_text(h, m->date);
      372 +        assert(man->date);
      373 +        print_text(h, man->date);
 368  374          print_stagq(h, tt);
 369  375  
 370  376          PAIR_CLASS_INIT(&tag[0], "foot-os");
 371  377          PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
 372  378          print_otag(h, TAG_TD, 2, tag);
 373  379  
 374      -        if (m->source)
 375      -                print_text(h, m->source);
      380 +        if (man->source)
      381 +                print_text(h, man->source);
 376  382          print_tagq(h, t);
 377  383  }
 378  384  
 379  385  
 380  386  /* ARGSUSED */
 381  387  static int
 382  388  man_br_pre(MAN_ARGS)
 383  389  {
 384  390          struct roffsu    su;
 385  391          struct htmlpair  tag;
↓ open down ↓ 75 lines elided ↑ open up ↑
 461  467                          abort();
 462  468                          /* NOTREACHED */
 463  469                  }
 464  470  
 465  471                  if (i)
 466  472                          h->flags |= HTML_NOSPACE;
 467  473  
 468  474                  if (TAG_MAX != fp)
 469  475                          t = print_otag(h, fp, 0, NULL);
 470  476  
 471      -                print_man_node(m, nn, mh, h);
      477 +                print_man_node(man, nn, mh, h);
 472  478  
 473  479                  if (t)
 474  480                          print_tagq(h, t);
 475  481          }
 476  482  
 477  483          if (savelit)
 478  484                  mh->fl |= MANH_LITERAL;
 479  485  
 480  486          return(0);
 481  487  }
↓ open down ↓ 54 lines elided ↑ open up ↑
 536  542                  return(1);
 537  543          }
 538  544  
 539  545          /* FIXME: width specification. */
 540  546  
 541  547          print_otag(h, TAG_DT, 0, NULL);
 542  548  
 543  549          /* For IP, only print the first header element. */
 544  550  
 545  551          if (MAN_IP == n->tok && n->child)
 546      -                print_man_node(m, n->child, mh, h);
      552 +                print_man_node(man, n->child, mh, h);
 547  553  
 548  554          /* For TP, only print next-line header elements. */
 549  555  
 550  556          if (MAN_TP == n->tok)
 551  557                  for (nn = n->child; nn; nn = nn->next)
 552  558                          if (nn->line > n->line)
 553      -                                print_man_node(m, nn, mh, h);
      559 +                                print_man_node(man, nn, mh, h);
 554  560  
 555  561          return(0);
 556  562  }
 557  563  
 558  564  /* ARGSUSED */
 559  565  static int
 560  566  man_HP_pre(MAN_ARGS)
 561  567  {
 562  568          struct htmlpair  tag;
 563  569          struct roffsu    su;
↓ open down ↓ 67 lines elided ↑ open up ↑
 631  637          
 632  638          print_otag(h, TAG_I, 0, NULL);
 633  639          return(1);
 634  640  }
 635  641  
 636  642  /* ARGSUSED */
 637  643  static int
 638  644  man_literal_pre(MAN_ARGS)
 639  645  {
 640  646  
 641      -        if (MAN_nf != n->tok) {
      647 +        if (MAN_fi == n->tok || MAN_EE == n->tok) {
 642  648                  print_otag(h, TAG_BR, 0, NULL);
 643  649                  mh->fl &= ~MANH_LITERAL;
 644  650          } else
 645  651                  mh->fl |= MANH_LITERAL;
 646  652  
 647  653          return(0);
 648  654  }
 649  655  
 650  656  /* ARGSUSED */
 651  657  static int
↓ open down ↓ 26 lines elided ↑ open up ↑
 678  684  
 679  685          SCALE_HS_INIT(&su, INDENT);
 680  686          if (n->head->child)
 681  687                  a2width(n->head->child, &su);
 682  688  
 683  689          bufinit(h);
 684  690          bufcat_su(h, "margin-left", &su);
 685  691          PAIR_STYLE_INIT(&tag, h);
 686  692          print_otag(h, TAG_DIV, 1, &tag);
 687  693          return(1);
      694 +}
      695 +
      696 +/* ARGSUSED */
      697 +static int
      698 +man_UR_pre(MAN_ARGS)
      699 +{
      700 +        struct htmlpair          tag[2];
      701 +
      702 +        n = n->child;
      703 +        assert(MAN_HEAD == n->type);
      704 +        if (n->nchild) {
      705 +                assert(MAN_TEXT == n->child->type);
      706 +                PAIR_CLASS_INIT(&tag[0], "link-ext");
      707 +                PAIR_HREF_INIT(&tag[1], n->child->string);
      708 +                print_otag(h, TAG_A, 2, tag);
      709 +        }
      710 +
      711 +        assert(MAN_BODY == n->next->type);
      712 +        if (n->next->nchild)
      713 +                n = n->next;
      714 +
      715 +        print_man_nodelist(man, n->child, mh, h);
      716 +
      717 +        return(0);
 688  718  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX