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/man.c
          +++ new/usr/src/cmd/mandoc/man.c
   1      -/*      $Id: man.c,v 1.115 2012/01/03 15:16:24 kristaps Exp $ */
        1 +/*      $Id: man.c,v 1.121 2013/11/10 22:54:40 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 ↓ 21 lines elided ↑ open up ↑
  33   33  
  34   34  const   char *const __man_macronames[MAN_MAX] = {                
  35   35          "br",           "TH",           "SH",           "SS",
  36   36          "TP",           "LP",           "PP",           "P",
  37   37          "IP",           "HP",           "SM",           "SB",
  38   38          "BI",           "IB",           "BR",           "RB",
  39   39          "R",            "B",            "I",            "IR",
  40   40          "RI",           "na",           "sp",           "nf",
  41   41          "fi",           "RE",           "RS",           "DT",
  42   42          "UC",           "PD",           "AT",           "in",
  43      -        "ft",           "OP"
       43 +        "ft",           "OP",           "EX",           "EE",
       44 +        "UR",           "UE"
  44   45          };
  45   46  
  46   47  const   char * const *man_macronames = __man_macronames;
  47   48  
  48   49  static  struct man_node *man_node_alloc(struct man *, int, int, 
  49   50                                  enum man_type, enum mant);
  50   51  static  int              man_node_append(struct man *, 
  51   52                                  struct man_node *);
  52   53  static  void             man_node_free(struct man_node *);
  53   54  static  void             man_node_unlink(struct man *, 
  54   55                                  struct man_node *);
  55   56  static  int              man_ptext(struct man *, int, char *, int);
  56   57  static  int              man_pmacro(struct man *, int, char *, int);
  57   58  static  void             man_free1(struct man *);
  58   59  static  void             man_alloc1(struct man *);
  59   60  static  int              man_descope(struct man *, int, int);
  60   61  
  61   62  
  62   63  const struct man_node *
  63      -man_node(const struct man *m)
       64 +man_node(const struct man *man)
  64   65  {
  65   66  
  66      -        assert( ! (MAN_HALT & m->flags));
  67      -        return(m->first);
       67 +        assert( ! (MAN_HALT & man->flags));
       68 +        return(man->first);
  68   69  }
  69   70  
  70   71  
  71   72  const struct man_meta *
  72      -man_meta(const struct man *m)
       73 +man_meta(const struct man *man)
  73   74  {
  74   75  
  75      -        assert( ! (MAN_HALT & m->flags));
  76      -        return(&m->meta);
       76 +        assert( ! (MAN_HALT & man->flags));
       77 +        return(&man->meta);
  77   78  }
  78   79  
  79   80  
  80   81  void
  81   82  man_reset(struct man *man)
  82   83  {
  83   84  
  84   85          man_free1(man);
  85   86          man_alloc1(man);
  86   87  }
↓ open down ↓ 18 lines elided ↑ open up ↑
 105  106          man_hash_init();
 106  107          p->parse = parse;
 107  108          p->roff = roff;
 108  109  
 109  110          man_alloc1(p);
 110  111          return(p);
 111  112  }
 112  113  
 113  114  
 114  115  int
 115      -man_endparse(struct man *m)
      116 +man_endparse(struct man *man)
 116  117  {
 117  118  
 118      -        assert( ! (MAN_HALT & m->flags));
 119      -        if (man_macroend(m))
      119 +        assert( ! (MAN_HALT & man->flags));
      120 +        if (man_macroend(man))
 120  121                  return(1);
 121      -        m->flags |= MAN_HALT;
      122 +        man->flags |= MAN_HALT;
 122  123          return(0);
 123  124  }
 124  125  
 125  126  
 126  127  int
 127      -man_parseln(struct man *m, int ln, char *buf, int offs)
      128 +man_parseln(struct man *man, int ln, char *buf, int offs)
 128  129  {
 129  130  
 130      -        m->flags |= MAN_NEWLINE;
      131 +        man->flags |= MAN_NEWLINE;
 131  132  
 132      -        assert( ! (MAN_HALT & m->flags));
      133 +        assert( ! (MAN_HALT & man->flags));
 133  134  
 134      -        return (mandoc_getcontrol(buf, &offs) ?
 135      -                        man_pmacro(m, ln, buf, offs) : 
 136      -                        man_ptext(m, ln, buf, offs));
      135 +        return (roff_getcontrol(man->roff, buf, &offs) ?
      136 +                        man_pmacro(man, ln, buf, offs) : 
      137 +                        man_ptext(man, ln, buf, offs));
 137  138  }
 138  139  
 139  140  
 140  141  static void
 141  142  man_free1(struct man *man)
 142  143  {
 143  144  
 144  145          if (man->first)
 145  146                  man_node_delete(man, man->first);
 146  147          if (man->meta.title)
↓ open down ↓ 3 lines elided ↑ open up ↑
 150  151          if (man->meta.date)
 151  152                  free(man->meta.date);
 152  153          if (man->meta.vol)
 153  154                  free(man->meta.vol);
 154  155          if (man->meta.msec)
 155  156                  free(man->meta.msec);
 156  157  }
 157  158  
 158  159  
 159  160  static void
 160      -man_alloc1(struct man *m)
      161 +man_alloc1(struct man *man)
 161  162  {
 162  163  
 163      -        memset(&m->meta, 0, sizeof(struct man_meta));
 164      -        m->flags = 0;
 165      -        m->last = mandoc_calloc(1, sizeof(struct man_node));
 166      -        m->first = m->last;
 167      -        m->last->type = MAN_ROOT;
 168      -        m->last->tok = MAN_MAX;
 169      -        m->next = MAN_NEXT_CHILD;
      164 +        memset(&man->meta, 0, sizeof(struct man_meta));
      165 +        man->flags = 0;
      166 +        man->last = mandoc_calloc(1, sizeof(struct man_node));
      167 +        man->first = man->last;
      168 +        man->last->type = MAN_ROOT;
      169 +        man->last->tok = MAN_MAX;
      170 +        man->next = MAN_NEXT_CHILD;
 170  171  }
 171  172  
 172  173  
 173  174  static int
 174  175  man_node_append(struct man *man, struct man_node *p)
 175  176  {
 176  177  
 177  178          assert(man->last);
 178  179          assert(man->first);
 179  180          assert(MAN_ROOT != p->type);
↓ open down ↓ 47 lines elided ↑ open up ↑
 227  228                  break;
 228  229          default:
 229  230                  break;
 230  231          }
 231  232  
 232  233          return(1);
 233  234  }
 234  235  
 235  236  
 236  237  static struct man_node *
 237      -man_node_alloc(struct man *m, int line, int pos, 
      238 +man_node_alloc(struct man *man, int line, int pos, 
 238  239                  enum man_type type, enum mant tok)
 239  240  {
 240  241          struct man_node *p;
 241  242  
 242  243          p = mandoc_calloc(1, sizeof(struct man_node));
 243  244          p->line = line;
 244  245          p->pos = pos;
 245  246          p->type = type;
 246  247          p->tok = tok;
 247  248  
 248      -        if (MAN_NEWLINE & m->flags)
      249 +        if (MAN_NEWLINE & man->flags)
 249  250                  p->flags |= MAN_LINE;
 250      -        m->flags &= ~MAN_NEWLINE;
      251 +        man->flags &= ~MAN_NEWLINE;
 251  252          return(p);
 252  253  }
 253  254  
 254  255  
 255  256  int
 256      -man_elem_alloc(struct man *m, int line, int pos, enum mant tok)
      257 +man_elem_alloc(struct man *man, int line, int pos, enum mant tok)
 257  258  {
 258  259          struct man_node *p;
 259  260  
 260      -        p = man_node_alloc(m, line, pos, MAN_ELEM, tok);
 261      -        if ( ! man_node_append(m, p))
      261 +        p = man_node_alloc(man, line, pos, MAN_ELEM, tok);
      262 +        if ( ! man_node_append(man, p))
 262  263                  return(0);
 263      -        m->next = MAN_NEXT_CHILD;
      264 +        man->next = MAN_NEXT_CHILD;
 264  265          return(1);
 265  266  }
 266  267  
 267  268  
 268  269  int
 269      -man_tail_alloc(struct man *m, int line, int pos, enum mant tok)
      270 +man_tail_alloc(struct man *man, int line, int pos, enum mant tok)
 270  271  {
 271  272          struct man_node *p;
 272  273  
 273      -        p = man_node_alloc(m, line, pos, MAN_TAIL, tok);
 274      -        if ( ! man_node_append(m, p))
      274 +        p = man_node_alloc(man, line, pos, MAN_TAIL, tok);
      275 +        if ( ! man_node_append(man, p))
 275  276                  return(0);
 276      -        m->next = MAN_NEXT_CHILD;
      277 +        man->next = MAN_NEXT_CHILD;
 277  278          return(1);
 278  279  }
 279  280  
 280  281  
 281  282  int
 282      -man_head_alloc(struct man *m, int line, int pos, enum mant tok)
      283 +man_head_alloc(struct man *man, int line, int pos, enum mant tok)
 283  284  {
 284  285          struct man_node *p;
 285  286  
 286      -        p = man_node_alloc(m, line, pos, MAN_HEAD, tok);
 287      -        if ( ! man_node_append(m, p))
      287 +        p = man_node_alloc(man, line, pos, MAN_HEAD, tok);
      288 +        if ( ! man_node_append(man, p))
 288  289                  return(0);
 289      -        m->next = MAN_NEXT_CHILD;
      290 +        man->next = MAN_NEXT_CHILD;
 290  291          return(1);
 291  292  }
 292  293  
 293  294  
 294  295  int
 295      -man_body_alloc(struct man *m, int line, int pos, enum mant tok)
      296 +man_body_alloc(struct man *man, int line, int pos, enum mant tok)
 296  297  {
 297  298          struct man_node *p;
 298  299  
 299      -        p = man_node_alloc(m, line, pos, MAN_BODY, tok);
 300      -        if ( ! man_node_append(m, p))
      300 +        p = man_node_alloc(man, line, pos, MAN_BODY, tok);
      301 +        if ( ! man_node_append(man, p))
 301  302                  return(0);
 302      -        m->next = MAN_NEXT_CHILD;
      303 +        man->next = MAN_NEXT_CHILD;
 303  304          return(1);
 304  305  }
 305  306  
 306  307  
 307  308  int
 308      -man_block_alloc(struct man *m, int line, int pos, enum mant tok)
      309 +man_block_alloc(struct man *man, int line, int pos, enum mant tok)
 309  310  {
 310  311          struct man_node *p;
 311  312  
 312      -        p = man_node_alloc(m, line, pos, MAN_BLOCK, tok);
 313      -        if ( ! man_node_append(m, p))
      313 +        p = man_node_alloc(man, line, pos, MAN_BLOCK, tok);
      314 +        if ( ! man_node_append(man, p))
 314  315                  return(0);
 315      -        m->next = MAN_NEXT_CHILD;
      316 +        man->next = MAN_NEXT_CHILD;
 316  317          return(1);
 317  318  }
 318  319  
 319  320  int
 320      -man_word_alloc(struct man *m, int line, int pos, const char *word)
      321 +man_word_alloc(struct man *man, int line, int pos, const char *word)
 321  322  {
 322  323          struct man_node *n;
 323  324  
 324      -        n = man_node_alloc(m, line, pos, MAN_TEXT, MAN_MAX);
 325      -        n->string = roff_strdup(m->roff, word);
      325 +        n = man_node_alloc(man, line, pos, MAN_TEXT, MAN_MAX);
      326 +        n->string = roff_strdup(man->roff, word);
 326  327  
 327      -        if ( ! man_node_append(m, n))
      328 +        if ( ! man_node_append(man, n))
 328  329                  return(0);
 329  330  
 330      -        m->next = MAN_NEXT_SIBLING;
      331 +        man->next = MAN_NEXT_SIBLING;
 331  332          return(1);
 332  333  }
 333  334  
 334  335  
 335  336  /*
 336  337   * Free all of the resources held by a node.  This does NOT unlink a
 337  338   * node from its context; for that, see man_node_unlink().
 338  339   */
 339  340  static void
 340  341  man_node_free(struct man_node *p)
 341  342  {
 342  343  
 343  344          if (p->string)
 344  345                  free(p->string);
 345  346          free(p);
 346  347  }
 347  348  
 348  349  
 349  350  void
 350      -man_node_delete(struct man *m, struct man_node *p)
      351 +man_node_delete(struct man *man, struct man_node *p)
 351  352  {
 352  353  
 353  354          while (p->child)
 354      -                man_node_delete(m, p->child);
      355 +                man_node_delete(man, p->child);
 355  356  
 356      -        man_node_unlink(m, p);
      357 +        man_node_unlink(man, p);
 357  358          man_node_free(p);
 358  359  }
 359  360  
 360  361  int
 361      -man_addeqn(struct man *m, const struct eqn *ep)
      362 +man_addeqn(struct man *man, const struct eqn *ep)
 362  363  {
 363  364          struct man_node *n;
 364  365  
 365      -        assert( ! (MAN_HALT & m->flags));
      366 +        assert( ! (MAN_HALT & man->flags));
 366  367  
 367      -        n = man_node_alloc(m, ep->ln, ep->pos, MAN_EQN, MAN_MAX);
      368 +        n = man_node_alloc(man, ep->ln, ep->pos, MAN_EQN, MAN_MAX);
 368  369          n->eqn = ep;
 369  370  
 370      -        if ( ! man_node_append(m, n))
      371 +        if ( ! man_node_append(man, n))
 371  372                  return(0);
 372  373  
 373      -        m->next = MAN_NEXT_SIBLING;
 374      -        return(man_descope(m, ep->ln, ep->pos));
      374 +        man->next = MAN_NEXT_SIBLING;
      375 +        return(man_descope(man, ep->ln, ep->pos));
 375  376  }
 376  377  
 377  378  int
 378      -man_addspan(struct man *m, const struct tbl_span *sp)
      379 +man_addspan(struct man *man, const struct tbl_span *sp)
 379  380  {
 380  381          struct man_node *n;
 381  382  
 382      -        assert( ! (MAN_HALT & m->flags));
      383 +        assert( ! (MAN_HALT & man->flags));
 383  384  
 384      -        n = man_node_alloc(m, sp->line, 0, MAN_TBL, MAN_MAX);
      385 +        n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX);
 385  386          n->span = sp;
 386  387  
 387      -        if ( ! man_node_append(m, n))
      388 +        if ( ! man_node_append(man, n))
 388  389                  return(0);
 389  390  
 390      -        m->next = MAN_NEXT_SIBLING;
 391      -        return(man_descope(m, sp->line, 0));
      391 +        man->next = MAN_NEXT_SIBLING;
      392 +        return(man_descope(man, sp->line, 0));
 392  393  }
 393  394  
 394  395  static int
 395      -man_descope(struct man *m, int line, int offs)
      396 +man_descope(struct man *man, int line, int offs)
 396  397  {
 397  398          /*
 398  399           * Co-ordinate what happens with having a next-line scope open:
 399  400           * first close out the element scope (if applicable), then close
 400  401           * out the block scope (also if applicable).
 401  402           */
 402  403  
 403      -        if (MAN_ELINE & m->flags) {
 404      -                m->flags &= ~MAN_ELINE;
 405      -                if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
      404 +        if (MAN_ELINE & man->flags) {
      405 +                man->flags &= ~MAN_ELINE;
      406 +                if ( ! man_unscope(man, man->last->parent, MANDOCERR_MAX))
 406  407                          return(0);
 407  408          }
 408  409  
 409      -        if ( ! (MAN_BLINE & m->flags))
      410 +        if ( ! (MAN_BLINE & man->flags))
 410  411                  return(1);
 411      -        m->flags &= ~MAN_BLINE;
      412 +        man->flags &= ~MAN_BLINE;
 412  413  
 413      -        if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
      414 +        if ( ! man_unscope(man, man->last->parent, MANDOCERR_MAX))
 414  415                  return(0);
 415      -        return(man_body_alloc(m, line, offs, m->last->tok));
      416 +        return(man_body_alloc(man, line, offs, man->last->tok));
 416  417  }
 417  418  
 418  419  static int
 419      -man_ptext(struct man *m, int line, char *buf, int offs)
      420 +man_ptext(struct man *man, int line, char *buf, int offs)
 420  421  {
 421  422          int              i;
 422  423  
 423  424          /* Literal free-form text whitespace is preserved. */
 424  425  
 425      -        if (MAN_LITERAL & m->flags) {
 426      -                if ( ! man_word_alloc(m, line, offs, buf + offs))
      426 +        if (MAN_LITERAL & man->flags) {
      427 +                if ( ! man_word_alloc(man, line, offs, buf + offs))
 427  428                          return(0);
 428      -                return(man_descope(m, line, offs));
      429 +                return(man_descope(man, line, offs));
 429  430          }
 430  431  
 431      -        /* Pump blank lines directly into the backend. */
 432      -
 433  432          for (i = offs; ' ' == buf[i]; i++)
 434  433                  /* Skip leading whitespace. */ ;
 435  434  
      435 +        /*
      436 +         * Blank lines are ignored right after headings
      437 +         * but add a single vertical space elsewhere.
      438 +         */
      439 +
 436  440          if ('\0' == buf[i]) {
 437  441                  /* Allocate a blank entry. */
 438      -                if ( ! man_word_alloc(m, line, offs, ""))
 439      -                        return(0);
 440      -                return(man_descope(m, line, offs));
      442 +                if (MAN_SH != man->last->tok &&
      443 +                    MAN_SS != man->last->tok) {
      444 +                        if ( ! man_elem_alloc(man, line, offs, MAN_sp))
      445 +                                return(0);
      446 +                        man->next = MAN_NEXT_SIBLING;
      447 +                }
      448 +                return(1);
 441  449          }
 442  450  
 443  451          /* 
 444  452           * Warn if the last un-escaped character is whitespace. Then
 445  453           * strip away the remaining spaces (tabs stay!).   
 446  454           */
 447  455  
 448  456          i = (int)strlen(buf);
 449  457          assert(i);
 450  458  
 451  459          if (' ' == buf[i - 1] || '\t' == buf[i - 1]) {
 452  460                  if (i > 1 && '\\' != buf[i - 2])
 453      -                        man_pmsg(m, line, i - 1, MANDOCERR_EOLNSPACE);
      461 +                        man_pmsg(man, line, i - 1, MANDOCERR_EOLNSPACE);
 454  462  
 455  463                  for (--i; i && ' ' == buf[i]; i--)
 456  464                          /* Spin back to non-space. */ ;
 457  465  
 458  466                  /* Jump ahead of escaped whitespace. */
 459  467                  i += '\\' == buf[i] ? 2 : 1;
 460  468  
 461  469                  buf[i] = '\0';
 462  470          }
 463  471  
 464      -        if ( ! man_word_alloc(m, line, offs, buf + offs))
      472 +        if ( ! man_word_alloc(man, line, offs, buf + offs))
 465  473                  return(0);
 466  474  
 467  475          /*
 468  476           * End-of-sentence check.  If the last character is an unescaped
 469  477           * EOS character, then flag the node as being the end of a
 470  478           * sentence.  The front-end will know how to interpret this.
 471  479           */
 472  480  
 473  481          assert(i);
 474  482          if (mandoc_eos(buf, (size_t)i, 0))
 475      -                m->last->flags |= MAN_EOS;
      483 +                man->last->flags |= MAN_EOS;
 476  484  
 477      -        return(man_descope(m, line, offs));
      485 +        return(man_descope(man, line, offs));
 478  486  }
 479  487  
 480  488  static int
 481      -man_pmacro(struct man *m, int ln, char *buf, int offs)
      489 +man_pmacro(struct man *man, int ln, char *buf, int offs)
 482  490  {
 483  491          int              i, ppos;
 484  492          enum mant        tok;
 485  493          char             mac[5];
 486  494          struct man_node *n;
 487  495  
 488  496          if ('"' == buf[offs]) {
 489      -                man_pmsg(m, ln, offs, MANDOCERR_BADCOMMENT);
      497 +                man_pmsg(man, ln, offs, MANDOCERR_BADCOMMENT);
 490  498                  return(1);
 491  499          } else if ('\0' == buf[offs])
 492  500                  return(1);
 493  501  
 494  502          ppos = offs;
 495  503  
 496  504          /*
 497  505           * Copy the first word into a nil-terminated buffer.
 498  506           * Stop copying when a tab, space, or eoln is encountered.
 499  507           */
↓ open down ↓ 1 lines elided ↑ open up ↑
 501  509          i = 0;
 502  510          while (i < 4 && '\0' != buf[offs] && 
 503  511                          ' ' != buf[offs] && '\t' != buf[offs])
 504  512                  mac[i++] = buf[offs++];
 505  513  
 506  514          mac[i] = '\0';
 507  515  
 508  516          tok = (i > 0 && i < 4) ? man_hash_find(mac) : MAN_MAX;
 509  517  
 510  518          if (MAN_MAX == tok) {
 511      -                mandoc_vmsg(MANDOCERR_MACRO, m->parse, ln, 
      519 +                mandoc_vmsg(MANDOCERR_MACRO, man->parse, ln, 
 512  520                                  ppos, "%s", buf + ppos - 1);
 513  521                  return(1);
 514  522          }
 515  523  
 516  524          /* The macro is sane.  Jump to the next word. */
 517  525  
 518  526          while (buf[offs] && ' ' == buf[offs])
 519  527                  offs++;
 520  528  
 521  529          /* 
 522  530           * Trailing whitespace.  Note that tabs are allowed to be passed
 523  531           * into the parser as "text", so we only warn about spaces here.
 524  532           */
 525  533  
 526  534          if ('\0' == buf[offs] && ' ' == buf[offs - 1])
 527      -                man_pmsg(m, ln, offs - 1, MANDOCERR_EOLNSPACE);
      535 +                man_pmsg(man, ln, offs - 1, MANDOCERR_EOLNSPACE);
 528  536  
 529  537          /* 
 530  538           * Remove prior ELINE macro, as it's being clobbered by a new
 531  539           * macro.  Note that NSCOPED macros do not close out ELINE
 532  540           * macros---they don't print text---so we let those slip by.
 533  541           */
 534  542  
 535  543          if ( ! (MAN_NSCOPED & man_macros[tok].flags) &&
 536      -                        m->flags & MAN_ELINE) {
 537      -                n = m->last;
      544 +                        man->flags & MAN_ELINE) {
      545 +                n = man->last;
 538  546                  assert(MAN_TEXT != n->type);
 539  547  
 540  548                  /* Remove repeated NSCOPED macros causing ELINE. */
 541  549  
 542  550                  if (MAN_NSCOPED & man_macros[n->tok].flags)
 543  551                          n = n->parent;
 544  552  
 545      -                mandoc_vmsg(MANDOCERR_LINESCOPE, m->parse, n->line, 
      553 +                mandoc_vmsg(MANDOCERR_LINESCOPE, man->parse, n->line, 
 546  554                      n->pos, "%s breaks %s", man_macronames[tok],
 547  555                      man_macronames[n->tok]);
 548  556  
 549      -                man_node_delete(m, n);
 550      -                m->flags &= ~MAN_ELINE;
      557 +                man_node_delete(man, n);
      558 +                man->flags &= ~MAN_ELINE;
 551  559          }
 552  560  
 553  561          /*
 554  562           * Remove prior BLINE macro that is being clobbered.
 555  563           */
 556      -        if ((m->flags & MAN_BLINE) &&
      564 +        if ((man->flags & MAN_BLINE) &&
 557  565              (MAN_BSCOPE & man_macros[tok].flags)) {
 558      -                n = m->last;
      566 +                n = man->last;
 559  567  
 560  568                  /* Might be a text node like 8 in
 561  569                   * .TP 8
 562  570                   * .SH foo
 563  571                   */
 564  572                  if (MAN_TEXT == n->type)
 565  573                          n = n->parent;
 566  574  
 567  575                  /* Remove element that didn't end BLINE, if any. */
 568  576                  if ( ! (MAN_BSCOPE & man_macros[n->tok].flags))
 569  577                          n = n->parent;
 570  578  
 571  579                  assert(MAN_HEAD == n->type);
 572  580                  n = n->parent;
 573  581                  assert(MAN_BLOCK == n->type);
 574  582                  assert(MAN_SCOPED & man_macros[n->tok].flags);
 575  583  
 576      -                mandoc_vmsg(MANDOCERR_LINESCOPE, m->parse, n->line, 
      584 +                mandoc_vmsg(MANDOCERR_LINESCOPE, man->parse, n->line, 
 577  585                      n->pos, "%s breaks %s", man_macronames[tok],
 578  586                      man_macronames[n->tok]);
 579  587  
 580      -                man_node_delete(m, n);
 581      -                m->flags &= ~MAN_BLINE;
      588 +                man_node_delete(man, n);
      589 +                man->flags &= ~MAN_BLINE;
 582  590          }
 583  591  
 584  592          /*
 585  593           * Save the fact that we're in the next-line for a block.  In
 586  594           * this way, embedded roff instructions can "remember" state
 587  595           * when they exit.
 588  596           */
 589  597  
 590      -        if (MAN_BLINE & m->flags)
 591      -                m->flags |= MAN_BPLINE;
      598 +        if (MAN_BLINE & man->flags)
      599 +                man->flags |= MAN_BPLINE;
 592  600  
 593  601          /* Call to handler... */
 594  602  
 595  603          assert(man_macros[tok].fp);
 596      -        if ( ! (*man_macros[tok].fp)(m, tok, ln, ppos, &offs, buf))
      604 +        if ( ! (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf))
 597  605                  goto err;
 598  606  
 599  607          /* 
 600  608           * We weren't in a block-line scope when entering the
 601  609           * above-parsed macro, so return.
 602  610           */
 603  611  
 604      -        if ( ! (MAN_BPLINE & m->flags)) {
 605      -                m->flags &= ~MAN_ILINE; 
      612 +        if ( ! (MAN_BPLINE & man->flags)) {
      613 +                man->flags &= ~MAN_ILINE; 
 606  614                  return(1);
 607  615          }
 608      -        m->flags &= ~MAN_BPLINE;
      616 +        man->flags &= ~MAN_BPLINE;
 609  617  
 610  618          /*
 611  619           * If we're in a block scope, then allow this macro to slip by
 612  620           * without closing scope around it.
 613  621           */
 614  622  
 615      -        if (MAN_ILINE & m->flags) {
 616      -                m->flags &= ~MAN_ILINE;
      623 +        if (MAN_ILINE & man->flags) {
      624 +                man->flags &= ~MAN_ILINE;
 617  625                  return(1);
 618  626          }
 619  627  
 620  628          /* 
 621  629           * If we've opened a new next-line element scope, then return
 622  630           * now, as the next line will close out the block scope.
 623  631           */
 624  632  
 625      -        if (MAN_ELINE & m->flags)
      633 +        if (MAN_ELINE & man->flags)
 626  634                  return(1);
 627  635  
 628  636          /* Close out the block scope opened in the prior line.  */
 629  637  
 630      -        assert(MAN_BLINE & m->flags);
 631      -        m->flags &= ~MAN_BLINE;
      638 +        assert(MAN_BLINE & man->flags);
      639 +        man->flags &= ~MAN_BLINE;
 632  640  
 633      -        if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
      641 +        if ( ! man_unscope(man, man->last->parent, MANDOCERR_MAX))
 634  642                  return(0);
 635      -        return(man_body_alloc(m, ln, ppos, m->last->tok));
      643 +        return(man_body_alloc(man, ln, ppos, man->last->tok));
 636  644  
 637  645  err:    /* Error out. */
 638  646  
 639      -        m->flags |= MAN_HALT;
      647 +        man->flags |= MAN_HALT;
 640  648          return(0);
 641  649  }
 642  650  
 643  651  /*
 644      - * Unlink a node from its context.  If "m" is provided, the last parse
      652 + * Unlink a node from its context.  If "man" is provided, the last parse
 645  653   * point will also be adjusted accordingly.
 646  654   */
 647  655  static void
 648      -man_node_unlink(struct man *m, struct man_node *n)
      656 +man_node_unlink(struct man *man, struct man_node *n)
 649  657  {
 650  658  
 651  659          /* Adjust siblings. */
 652  660  
 653  661          if (n->prev)
 654  662                  n->prev->next = n->next;
 655  663          if (n->next)
 656  664                  n->next->prev = n->prev;
 657  665  
 658  666          /* Adjust parent. */
 659  667  
 660  668          if (n->parent) {
 661  669                  n->parent->nchild--;
 662  670                  if (n->parent->child == n)
 663  671                          n->parent->child = n->prev ? n->prev : n->next;
 664  672          }
 665  673  
 666  674          /* Adjust parse point, if applicable. */
 667  675  
 668      -        if (m && m->last == n) {
      676 +        if (man && man->last == n) {
 669  677                  /*XXX: this can occur when bailing from validation. */
 670  678                  /*assert(NULL == n->next);*/
 671  679                  if (n->prev) {
 672      -                        m->last = n->prev;
 673      -                        m->next = MAN_NEXT_SIBLING;
      680 +                        man->last = n->prev;
      681 +                        man->next = MAN_NEXT_SIBLING;
 674  682                  } else {
 675      -                        m->last = n->parent;
 676      -                        m->next = MAN_NEXT_CHILD;
      683 +                        man->last = n->parent;
      684 +                        man->next = MAN_NEXT_CHILD;
 677  685                  }
 678  686          }
 679  687  
 680      -        if (m && m->first == n)
 681      -                m->first = NULL;
      688 +        if (man && man->first == n)
      689 +                man->first = NULL;
 682  690  }
 683  691  
 684  692  const struct mparse *
 685      -man_mparse(const struct man *m)
      693 +man_mparse(const struct man *man)
 686  694  {
 687  695  
 688      -        assert(m && m->parse);
 689      -        return(m->parse);
      696 +        assert(man && man->parse);
      697 +        return(man->parse);
 690  698  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX