[BACK]Return to mdoc_action.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/Attic/mdoc_action.c between version 1.65 and 1.69

version 1.65, 2010/06/03 13:44:36 version 1.69, 2010/06/13 20:05:12
Line 52  static int   post_at(POST_ARGS);
Line 52  static int   post_at(POST_ARGS);
 static  int       post_bl(POST_ARGS);  static  int       post_bl(POST_ARGS);
 static  int       post_bl_head(POST_ARGS);  static  int       post_bl_head(POST_ARGS);
 static  int       post_bl_tagwidth(POST_ARGS);  static  int       post_bl_tagwidth(POST_ARGS);
 static  int       post_bl_width(POST_ARGS);  static  int       post_bl_width(struct mdoc *,
                           struct mdoc_node *, int);
 static  int       post_dd(POST_ARGS);  static  int       post_dd(POST_ARGS);
 static  int       post_display(POST_ARGS);  static  int       post_display(POST_ARGS);
 static  int       post_dt(POST_ARGS);  static  int       post_dt(POST_ARGS);
Line 68  static int   post_st(POST_ARGS);
Line 69  static int   post_st(POST_ARGS);
 static  int       post_std(POST_ARGS);  static  int       post_std(POST_ARGS);
   
 static  int       pre_bd(PRE_ARGS);  static  int       pre_bd(PRE_ARGS);
 static  int       pre_bl(PRE_ARGS);  
 static  int       pre_dl(PRE_ARGS);  static  int       pre_dl(PRE_ARGS);
 static  int       pre_offset(PRE_ARGS);  
   
 static  const struct actions mdoc_actions[MDOC_MAX] = {  static  const struct actions mdoc_actions[MDOC_MAX] = {
         { NULL, NULL }, /* Ap */          { NULL, NULL }, /* Ap */
Line 84  static const struct actions mdoc_actions[MDOC_MAX] = {
Line 83  static const struct actions mdoc_actions[MDOC_MAX] = {
         { pre_dl, post_display }, /* Dl */          { pre_dl, post_display }, /* Dl */
         { pre_bd, post_display }, /* Bd */          { pre_bd, post_display }, /* Bd */
         { NULL, NULL }, /* Ed */          { NULL, NULL }, /* Ed */
         { pre_bl, post_bl }, /* Bl */          { NULL, post_bl }, /* Bl */
         { NULL, NULL }, /* El */          { NULL, NULL }, /* El */
         { NULL, NULL }, /* It */          { NULL, NULL }, /* It */
         { NULL, NULL }, /* Ad */          { NULL, NULL }, /* Ad */
Line 633  static int
Line 632  static int
 post_bl_tagwidth(POST_ARGS)  post_bl_tagwidth(POST_ARGS)
 {  {
         struct mdoc_node *nn;          struct mdoc_node *nn;
         size_t            sz;          size_t            sz, ssz;
         int               i;          int               i;
         char              buf[NUMSIZ];          char              buf[NUMSIZ];
   
         /* Defaults to ten ens. */          sz = 10;
   
         sz = 10; /* XXX: make this a macro value. */  
   
         for (nn = n->body->child; nn; nn = nn->next) {          for (nn = n->body->child; nn; nn = nn->next) {
                 if (MDOC_It == nn->tok)                  if (MDOC_It != nn->tok)
                         break;                          continue;
         }  
   
         if (nn) {  
                 assert(MDOC_BLOCK == nn->type);                  assert(MDOC_BLOCK == nn->type);
                 nn = nn->head->child;                  nn = nn->head->child;
                 if (MDOC_TEXT != nn->type) {  
                         sz = mdoc_macro2len(nn->tok);                  if (MDOC_TEXT == nn->type) {
                         if (sz == 0) {  
                                 if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG))  
                                         return(0);  
                                 sz = 10;  
                         }  
                 } else  
                         sz = strlen(nn->string) + 1;                          sz = strlen(nn->string) + 1;
                           break;
                   }
   
                   if (0 != (ssz = mdoc_macro2len(nn->tok)))
                           sz = ssz;
                   else if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG))
                           return(0);
   
                   break;
         }          }
   
           /* Defaults to ten ens. */
   
         snprintf(buf, NUMSIZ, "%zun", sz);          snprintf(buf, NUMSIZ, "%zun", sz);
   
         /*          /*
Line 690  post_bl_tagwidth(POST_ARGS)
Line 690  post_bl_tagwidth(POST_ARGS)
  * scaling width.   * scaling width.
  */   */
 static int  static int
 post_bl_width(POST_ARGS)  post_bl_width(struct mdoc *m, struct mdoc_node *n, int pos)
 {  {
         size_t            width;          size_t            width;
         int               i;  
         enum mdoct        tok;          enum mdoct        tok;
         char              buf[NUMSIZ];          char              buf[NUMSIZ];
         char             *p;          char             *p;
   
         if (NULL == n->args)          assert(n->args);
                 return(1);          p = n->args->argv[pos].value[0];
   
         for (i = 0; i < (int)n->args->argc; i++)  
                 if (MDOC_Width == n->args->argv[i].arg)  
                         break;  
   
         if (i == (int)n->args->argc)  
                 return(1);  
         p = n->args->argv[i].value[0];  
   
         /*          /*
          * If the value to -width is a macro, then we re-write it to be           * If the value to -width is a macro, then we re-write it to be
          * the macro's width as set in share/tmac/mdoc/doc-common.           * the macro's width as set in share/tmac/mdoc/doc-common.
Line 724  post_bl_width(POST_ARGS)
Line 715  post_bl_width(POST_ARGS)
         /* The value already exists: free and reallocate it. */          /* The value already exists: free and reallocate it. */
   
         snprintf(buf, NUMSIZ, "%zun", width);          snprintf(buf, NUMSIZ, "%zun", width);
         free(n->args->argv[i].value[0]);          free(n->args->argv[pos].value[0]);
         n->args->argv[i].value[0] = mandoc_strdup(buf);          n->args->argv[pos].value[0] = mandoc_strdup(buf);
         return(1);          return(1);
 }  }
   
Line 741  post_bl_head(POST_ARGS)
Line 732  post_bl_head(POST_ARGS)
         int                      i, c;          int                      i, c;
         struct mdoc_node        *np, *nn, *nnp;          struct mdoc_node        *np, *nn, *nnp;
   
         if (NULL == n->child)          if (LIST_column != n->data.Bl.type)
                 return(1);                  return(1);
           else if (NULL == n->child)
                   return(1);
   
         np = n->parent;          np = n->parent;
         assert(np->args);          assert(np->args);
Line 751  post_bl_head(POST_ARGS)
Line 744  post_bl_head(POST_ARGS)
                 if (MDOC_Column == np->args->argv[c].arg)                  if (MDOC_Column == np->args->argv[c].arg)
                         break;                          break;
   
         if (c == (int)np->args->argc)          assert(c < (int)np->args->argc);
                 return(1);  
         assert(0 == np->args->argv[c].sz);          assert(0 == np->args->argv[c].sz);
   
         /*          /*
Line 782  post_bl_head(POST_ARGS)
Line 774  post_bl_head(POST_ARGS)
 static int  static int
 post_bl(POST_ARGS)  post_bl(POST_ARGS)
 {  {
         int               i, r, len;          int               i, r, len, width;
   
         if (MDOC_HEAD == n->type)          if (MDOC_HEAD == n->type)
                 return(post_bl_head(m, n));                  return(post_bl_head(m, n));
Line 799  post_bl(POST_ARGS)
Line 791  post_bl(POST_ARGS)
   
         len = (int)(n->args ? n->args->argc : 0);          len = (int)(n->args ? n->args->argc : 0);
   
           width = -1;
   
         for (r = i = 0; i < len; i++) {          for (r = i = 0; i < len; i++) {
                 if (MDOC_Tag == n->args->argv[i].arg)                  if (MDOC_Tag == n->args->argv[i].arg)
                         r |= 1 << 0;                          r |= 1 << 0;
                 if (MDOC_Width == n->args->argv[i].arg)                  if (MDOC_Width == n->args->argv[i].arg) {
                           width = i;
                         r |= 1 << 1;                          r |= 1 << 1;
                   }
         }          }
   
         if (r & (1 << 0) && ! (r & (1 << 1))) {          if (r & (1 << 0) && ! (r & (1 << 1))) {
                 if ( ! post_bl_tagwidth(m, n))                  if ( ! post_bl_tagwidth(m, n))
                         return(0);                          return(0);
         } else if (r & (1 << 1))          } else if (r & (1 << 1))
                 if ( ! post_bl_width(m, n))                  if ( ! post_bl_width(m, n, width))
                         return(0);                          return(0);
   
         return(1);          return(1);
Line 937  pre_dl(PRE_ARGS)
Line 933  pre_dl(PRE_ARGS)
 }  }
   
   
 /* ARGSUSED */  
 static int  static int
 pre_offset(PRE_ARGS)  
 {  
         int              i;  
   
         /*  
          * Make sure that an empty offset produces an 8n length space as  
          * stipulated by mdoc.samples.  
          */  
   
         for (i = 0; n->args && i < (int)n->args->argc; i++) {  
                 if (MDOC_Offset != n->args->argv[i].arg)  
                         continue;  
                 if (n->args->argv[i].sz)  
                         break;  
                 assert(1 == n->args->refcnt);  
                 /* If no value set, length of <string>. */  
                 n->args->argv[i].sz++;  
                 n->args->argv[i].value = mandoc_malloc(sizeof(char *));  
                 n->args->argv[i].value[0] = mandoc_strdup("8n");  
                 break;  
         }  
   
         return(1);  
 }  
   
   
 static int  
 pre_bl(PRE_ARGS)  
 {  
   
         if (MDOC_BLOCK == n->type)  
                 return(pre_offset(m, n));  
         return(1);  
 }  
   
   
 static int  
 pre_bd(PRE_ARGS)  pre_bd(PRE_ARGS)
 {  {
         int              i;  
   
         if (MDOC_BLOCK == n->type)  
                 return(pre_offset(m, n));  
         if (MDOC_BODY != n->type)          if (MDOC_BODY != n->type)
                 return(1);                  return(1);
   
         /* Enter literal context if `Bd -literal' or `-unfilled'. */          if (DISP_literal == n->data.Bd.type)
                   m->flags |= MDOC_LITERAL;
         for (n = n->parent, i = 0; i < (int)n->args->argc; i++)          if (DISP_unfilled == n->data.Bd.type)
                 if (MDOC_Literal == n->args->argv[i].arg)                  m->flags |= MDOC_LITERAL;
                         m->flags |= MDOC_LITERAL;  
                 else if (MDOC_Unfilled == n->args->argv[i].arg)  
                         m->flags |= MDOC_LITERAL;  
   
         return(1);          return(1);
 }  }

Legend:
Removed from v.1.65  
changed lines
  Added in v.1.69

CVSweb