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

Diff for /mandoc/Attic/action.c between version 1.48 and 1.49

version 1.48, 2009/03/21 09:48:29 version 1.49, 2009/03/21 21:09:00
Line 32 
Line 32 
  * children have been filled in (post-fix order).   * children have been filled in (post-fix order).
  */   */
   
 enum    merr {  
         ENOWIDTH  
 };  
   
 enum    mwarn {  enum    mwarn {
         WBADSEC,          WBADSEC,
         WNOWIDTH,          WNOWIDTH,
Line 51  struct actions {
Line 47  struct actions {
 };  };
   
 static  int       pwarn(struct mdoc *, int, int, enum mwarn);  static  int       pwarn(struct mdoc *, int, int, enum mwarn);
 static  int       perr(struct mdoc *, int, int, enum merr);  
   
 static  int       post_ar(POST_ARGS);  static  int       post_ar(POST_ARGS);
 static  int       post_bl(POST_ARGS);  static  int       post_bl(POST_ARGS);
Line 69  static int   post_std(POST_ARGS);
Line 64  static int   post_std(POST_ARGS);
 static  int       pre_bd(PRE_ARGS);  static  int       pre_bd(PRE_ARGS);
 static  int       pre_dl(PRE_ARGS);  static  int       pre_dl(PRE_ARGS);
   
 #define merr(m, t) perr((m), (m)->last->line, (m)->last->pos, (t))  
 #define mwarn(m, t) pwarn((m), (m)->last->line, (m)->last->pos, (t))  #define mwarn(m, t) pwarn((m), (m)->last->line, (m)->last->pos, (t))
   
 const   struct actions mdoc_actions[MDOC_MAX] = {  const   struct actions mdoc_actions[MDOC_MAX] = {
Line 236  mdoc_action_post(struct mdoc *m)
Line 230  mdoc_action_post(struct mdoc *m)
   
   
 static int  static int
 perr(struct mdoc *m, int line, int pos, enum merr type)  
 {  
         char            *p;  
   
         p = NULL;  
   
         switch (type) {  
         case (ENOWIDTH):  
                 p = "missing width argument";  
                 break;  
         }  
   
         assert(p);  
         return(mdoc_perr(m, line, pos, p));  
 }  
   
   
 static int  
 pwarn(struct mdoc *m, int line, int pos, enum mwarn type)  pwarn(struct mdoc *m, int line, int pos, enum mwarn type)
 {  {
         char            *p;          char            *p;
Line 471  post_os(POST_ARGS)
Line 447  post_os(POST_ARGS)
 }  }
   
   
   /*
    * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
    * Uses the first head macro.
    */
 static int  static int
 post_bl_tagwidth(struct mdoc *m)  post_bl_tagwidth(struct mdoc *m)
 {  {
Line 479  post_bl_tagwidth(struct mdoc *m)
Line 459  post_bl_tagwidth(struct mdoc *m)
         char               buf[32];          char               buf[32];
   
         /*          /*
          * If -tag has been specified and -width has not been, then try  
          * to intuit our width from the first body element.  
          */  
   
         if (NULL == (n = m->last->body->child))  
                 return(1);  
   
         /*  
          * Use the text width, if a text node, or the default macro           * Use the text width, if a text node, or the default macro
          * width if a macro.           * width if a macro.
          */           */
   
         n = n->head->child;          n = m->last->head->child;
           sz = 10; /* Default size. */
   
         if (n) {          if (n) {
                 if (MDOC_TEXT != n->type) {                  if (MDOC_TEXT != n->type) {
                         if (0 == (sz = (int)mdoc_macro2len(n->tok)))                          if (0 == (sz = (int)mdoc_macro2len(n->tok)))
                                 sz = -1;                                  if ( ! mwarn(m, WNOWIDTH))
                                           return(0);
                 } else                  } else
                         sz = (int)strlen(n->string) + 1;                          sz = (int)strlen(n->string) + 1;
         } else          }
                 sz = -1;  
   
         if (-1 == sz) {  
                 if ( ! mwarn(m, WNOWIDTH))  
                         return(0);  
                 sz = 10;  
         }  
   
         (void)snprintf(buf, sizeof(buf), "%dn", sz);          (void)snprintf(buf, sizeof(buf), "%dn", sz);
   
         /*          /*
Line 514  post_bl_tagwidth(struct mdoc *m)
Line 482  post_bl_tagwidth(struct mdoc *m)
          * We're guaranteed that a MDOC_Width doesn't already exist.           * We're guaranteed that a MDOC_Width doesn't already exist.
          */           */
   
         if (NULL == m->last->args) {  
                 m->last->args = xcalloc  
                         (1, sizeof(struct mdoc_arg));  
                 m->last->args->refcnt = 1;  
         }  
   
         n = m->last;          n = m->last;
         sz = (int)n->args->argc;          assert(n->args);
   
         (n->args->argc)++;  
   
           (n->args->argc)++;
         n->args->argv = xrealloc(n->args->argv,          n->args->argv = xrealloc(n->args->argv,
                         n->args->argc * sizeof(struct mdoc_arg));                          n->args->argc * sizeof(struct mdoc_argv));
   
         n->args->argv[sz - 1].arg = MDOC_Width;          n->args->argv[n->args->argc - 1].arg = MDOC_Width;
         n->args->argv[sz - 1].line = m->last->line;          n->args->argv[n->args->argc - 1].line = m->last->line;
         n->args->argv[sz - 1].pos = m->last->pos;          n->args->argv[n->args->argc - 1].pos = m->last->pos;
         n->args->argv[sz - 1].sz = 1;          n->args->argv[n->args->argc - 1].sz = 1;
         n->args->argv[sz - 1].value = xcalloc(1, sizeof(char *));          n->args->argv[n->args->argc - 1].value = xcalloc(1, sizeof(char *));
         n->args->argv[sz - 1].value[0] = xstrdup(buf);          n->args->argv[n->args->argc - 1].value[0] = xstrdup(buf);
   
         return(1);          return(1);
 }  }
Line 548  post_bl_width(struct mdoc *m)
Line 509  post_bl_width(struct mdoc *m)
         char             *p;          char             *p;
   
         if (NULL == m->last->args)          if (NULL == m->last->args)
                 return(merr(m, ENOWIDTH));                  return(1);
   
         for (i = 0; i < (int)m->last->args->argc; i++)          for (i = 0; i < (int)m->last->args->argc; i++)
                 if (MDOC_Width == m->last->args->argv[i].arg)                  if (MDOC_Width == m->last->args->argv[i].arg)
                         break;                          break;
   
         if (i == (int)m->last->args->argc)          if (i == (int)m->last->args->argc)
                 return(merr(m, ENOWIDTH));                  return(1);
   
         p = m->last->args->argv[i].value[0];          p = m->last->args->argv[i].value[0];
   

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.49

CVSweb