[BACK]Return to man.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Diff for /src/usr.bin/mandoc/man.c between version 1.21 and 1.22

version 1.21, 2010/03/25 23:23:01 version 1.22, 2010/03/26 01:22:05
Line 45 
Line 45 
         "scope open on exit", /* WEXITSCOPE */          "scope open on exit", /* WEXITSCOPE */
         "no scope context", /* WNOSCOPE */          "no scope context", /* WNOSCOPE */
         "literal context already open", /* WOLITERAL */          "literal context already open", /* WOLITERAL */
         "no literal context open" /* WNLITERAL */          "no literal context open", /* WNLITERAL */
           "invalid nesting of roff declarations", /* WROFFNEST */
 };  };
   
 const   char *const __man_macronames[MAN_MAX] = {  const   char *const __man_macronames[MAN_MAX] = {
Line 57 
Line 58 
         "RI",           "na",           "i",            "sp",          "RI",           "na",           "i",            "sp",
         "nf",           "fi",           "r",            "RE",          "nf",           "fi",           "r",            "RE",
         "RS",           "DT",           "UC",           "PD",          "RS",           "DT",           "UC",           "PD",
         "Sp",           "Vb",           "Ve",          "Sp",           "Vb",           "Ve",           "de",
           "dei",          "am",           "ami",          "ig",
           ".",
         };          };
   
 const   char * const *man_macronames = __man_macronames;  const   char * const *man_macronames = __man_macronames;
   
 static  struct man_node *man_node_alloc(int, int,  static  struct man_node *man_node_alloc(int, int,
                                 enum man_type, int);                                  enum man_type, enum mant);
 static  int              man_node_append(struct man *,  static  int              man_node_append(struct man *,
                                 struct man_node *);                                  struct man_node *);
   static  void             man_node_free(struct man_node *);
   static  void             man_node_unlink(struct man *,
                                   struct man_node *);
 static  int              man_ptext(struct man *, int, char *);  static  int              man_ptext(struct man *, int, char *);
 static  int              man_pmacro(struct man *, int, char *);  static  int              man_pmacro(struct man *, int, char *);
 static  void             man_free1(struct man *);  static  void             man_free1(struct man *);
Line 156 
Line 162 
 {  {
   
         if (man->first)          if (man->first)
                 man_node_freelist(man->first);                  man_node_delete(man, man->first);
         if (man->meta.title)          if (man->meta.title)
                 free(man->meta.title);                  free(man->meta.title);
         if (man->meta.source)          if (man->meta.source)
Line 175 
Line 181 
         m->last = mandoc_calloc(1, sizeof(struct man_node));          m->last = mandoc_calloc(1, sizeof(struct man_node));
         m->first = m->last;          m->first = m->last;
         m->last->type = MAN_ROOT;          m->last->type = MAN_ROOT;
           m->last->tok = MAN_MAX;
         m->next = MAN_NEXT_CHILD;          m->next = MAN_NEXT_CHILD;
 }  }
   
Line 202 
Line 209 
                 /* NOTREACHED */                  /* NOTREACHED */
         }          }
   
           assert(p->parent);
         p->parent->nchild++;          p->parent->nchild++;
   
         if ( ! man_valid_pre(man, p))          if ( ! man_valid_pre(man, p))
Line 238 
Line 246 
   
   
 static struct man_node *  static struct man_node *
 man_node_alloc(int line, int pos, enum man_type type, int tok)  man_node_alloc(int line, int pos, enum man_type type, enum mant tok)
 {  {
         struct man_node *p;          struct man_node *p;
   
Line 252 
Line 260 
   
   
 int  int
 man_elem_alloc(struct man *m, int line, int pos, int tok)  man_elem_alloc(struct man *m, int line, int pos, enum mant tok)
 {  {
         struct man_node *p;          struct man_node *p;
   
Line 265 
Line 273 
   
   
 int  int
 man_head_alloc(struct man *m, int line, int pos, int tok)  man_head_alloc(struct man *m, int line, int pos, enum mant tok)
 {  {
         struct man_node *p;          struct man_node *p;
   
Line 278 
Line 286 
   
   
 int  int
 man_body_alloc(struct man *m, int line, int pos, int tok)  man_body_alloc(struct man *m, int line, int pos, enum mant tok)
 {  {
         struct man_node *p;          struct man_node *p;
   
Line 291 
Line 299 
   
   
 int  int
 man_block_alloc(struct man *m, int line, int pos, int tok)  man_block_alloc(struct man *m, int line, int pos, enum mant tok)
 {  {
         struct man_node *p;          struct man_node *p;
   
Line 310 
Line 318 
         struct man_node *n;          struct man_node *n;
         size_t           sv;          size_t           sv;
   
         n = man_node_alloc(line, pos, MAN_TEXT, -1);          n = man_node_alloc(line, pos, MAN_TEXT, MAN_MAX);
         n->string = mandoc_malloc(len + 1);          n->string = mandoc_malloc(len + 1);
         sv = strlcpy(n->string, p, len + 1);          sv = strlcpy(n->string, p, len + 1);
   
Line 332 
Line 340 
 }  }
   
   
 void  /*
    * Free all of the resources held by a node.  This does NOT unlink a
    * node from its context; for that, see man_node_unlink().
    */
   static void
 man_node_free(struct man_node *p)  man_node_free(struct man_node *p)
 {  {
   
         if (p->string)          if (p->string)
                 free(p->string);                  free(p->string);
         if (p->parent)  
                 p->parent->nchild--;  
         free(p);          free(p);
 }  }
   
   
 void  void
 man_node_freelist(struct man_node *p)  man_node_delete(struct man *m, struct man_node *p)
 {  {
         struct man_node *n;  
   
         if (p->child)          while (p->child)
                 man_node_freelist(p->child);                  man_node_delete(m, p->child);
         assert(0 == p->nchild);  
         n = p->next;          man_node_unlink(m, p);
         man_node_free(p);          man_node_free(p);
         if (n)  
                 man_node_freelist(n);  
 }  }
   
   
Line 465 
Line 472 
 int  int
 man_pmacro(struct man *m, int ln, char *buf)  man_pmacro(struct man *m, int ln, char *buf)
 {  {
         int              i, j, c, ppos, fl;          int              i, j, ppos, fl;
           enum mant        tok;
         char             mac[5];          char             mac[5];
         struct man_node *n;          struct man_node *n;
   
Line 515 
Line 523 
                 return(1);                  return(1);
         }          }
   
         if (MAN_MAX == (c = man_hash_find(mac))) {          if (MAN_MAX == (tok = man_hash_find(mac))) {
                 if ( ! macrowarn(m, ln, mac))                  if ( ! macrowarn(m, ln, mac))
                         goto err;                          goto err;
                 return(1);                  return(1);
Line 538 
Line 546 
          * macros---they don't print text---so we let those slip by.           * macros---they don't print text---so we let those slip by.
          */           */
   
         if ( ! (MAN_NSCOPED & man_macros[c].flags) &&          if ( ! (MAN_NSCOPED & man_macros[tok].flags) &&
                         m->flags & MAN_ELINE) {                          m->flags & MAN_ELINE) {
                 assert(MAN_TEXT != m->last->type);                  assert(MAN_TEXT != m->last->type);
   
Line 563 
Line 571 
                 if ( ! man_nwarn(m, n, WLNSCOPE))                  if ( ! man_nwarn(m, n, WLNSCOPE))
                         return(0);                          return(0);
   
                 man_node_unlink(m, n);                  man_node_delete(m, n);
                 man_node_free(n);  
                 m->flags &= ~MAN_ELINE;                  m->flags &= ~MAN_ELINE;
         }          }
   
         /* Begin recursive parse sequence. */          /* Begin recursive parse sequence. */
   
         assert(man_macros[c].fp);          assert(man_macros[tok].fp);
   
         if ( ! (*man_macros[c].fp)(m, c, ln, ppos, &i, buf))          if ( ! (*man_macros[tok].fp)(m, tok, ln, ppos, &i, buf))
                 goto err;                  goto err;
   
 out:  out:
         /*          /*
          * We weren't in a block-line scope when entering the           * We weren't in a block-line scope when entering the
          * above-parsed macro, so return.           * above-parsed macro, so return.
            *
            * FIXME: this prohibits the nesting of blocks (e.g., `de' and
            * family) within BLINE or ELINE systems.  This is annoying.
          */           */
   
         if ( ! (MAN_BLINE & fl)) {          if ( ! (MAN_BLINE & fl)) {
Line 667 
Line 677 
 }  }
   
   
 void  /*
    * Unlink a node from its context.  If "m" is provided, the last parse
    * point will also be adjusted accordingly.
    */
   static void
 man_node_unlink(struct man *m, struct man_node *n)  man_node_unlink(struct man *m, struct man_node *n)
 {  {
   
         if (n->prev) {          /* Adjust siblings. */
   
           if (n->prev)
                 n->prev->next = n->next;                  n->prev->next = n->next;
                 if (m->last == n) {          if (n->next)
                         assert(NULL == n->next);                  n->next->prev = n->prev;
   
           /* Adjust parent. */
   
           if (n->parent) {
                   n->parent->nchild--;
                   if (n->parent->child == n)
                           n->parent->child = n->prev ? n->prev : n->next;
           }
   
           /* Adjust parse point, if applicable. */
   
           if (m && m->last == n) {
                   /*XXX: this can occur when bailing from validation. */
                   /*assert(NULL == n->next);*/
                   if (n->prev) {
                         m->last = n->prev;                          m->last = n->prev;
                         m->next = MAN_NEXT_SIBLING;                          m->next = MAN_NEXT_SIBLING;
                 }                  } else {
         } else {  
                 n->parent->child = n->next;  
                 if (m->last == n) {  
                         assert(NULL == n->next);  
                         m->last = n->parent;                          m->last = n->parent;
                         m->next = MAN_NEXT_CHILD;                          m->next = MAN_NEXT_CHILD;
                 }                  }
         }          }
   
         if (n->next)          if (m && m->first == n)
                 n->next->prev = n->prev;                  m->first = NULL;
 }  }

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22