[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.35 and 1.40

version 1.35, 2009/08/20 13:22:48 version 1.40, 2009/09/24 15:08:41
Line 32  struct actions {
Line 32  struct actions {
         int     (*post)(POST_ARGS);          int     (*post)(POST_ARGS);
 };  };
   
   static  int       concat(struct mdoc *,
                           const struct mdoc_node *,
                           char *, size_t);
   static  inline int order_rs(int);
   
   #ifdef __linux__
   extern  size_t    strlcat(char *, const char *, size_t);
   #endif
   
 static  int       post_ar(POST_ARGS);  static  int       post_ar(POST_ARGS);
 static  int       post_at(POST_ARGS);  static  int       post_at(POST_ARGS);
 static  int       post_bl(POST_ARGS);  static  int       post_bl(POST_ARGS);
Line 45  static int   post_lb(POST_ARGS);
Line 54  static int   post_lb(POST_ARGS);
 static  int       post_nm(POST_ARGS);  static  int       post_nm(POST_ARGS);
 static  int       post_os(POST_ARGS);  static  int       post_os(POST_ARGS);
 static  int       post_prol(POST_ARGS);  static  int       post_prol(POST_ARGS);
   static  int       post_rs(POST_ARGS);
 static  int       post_sh(POST_ARGS);  static  int       post_sh(POST_ARGS);
 static  int       post_st(POST_ARGS);  static  int       post_st(POST_ARGS);
 static  int       post_std(POST_ARGS);  static  int       post_std(POST_ARGS);
 static  int       post_tilde(POST_ARGS);  static  int       post_tilde(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);
   
 const   struct actions mdoc_actions[MDOC_MAX] = {  static  const struct actions mdoc_actions[MDOC_MAX] = {
         { NULL, NULL }, /* Ap */          { NULL, NULL }, /* Ap */
         { NULL, post_dd }, /* Dd */          { NULL, post_dd }, /* Dd */
         { NULL, post_dt }, /* Dt */          { NULL, post_dt }, /* Dt */
Line 65  const struct actions mdoc_actions[MDOC_MAX] = {
Line 77  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 */
         { NULL, post_bl }, /* Bl */          { pre_bl, post_bl }, /* Bl */
         { NULL, NULL }, /* El */          { NULL, NULL }, /* El */
         { NULL, NULL }, /* It */          { NULL, NULL }, /* It */
         { NULL, NULL }, /* Ad */          { NULL, NULL }, /* Ad */
Line 139  const struct actions mdoc_actions[MDOC_MAX] = {
Line 151  const struct actions mdoc_actions[MDOC_MAX] = {
         { NULL, NULL }, /* Qo */          { NULL, NULL }, /* Qo */
         { NULL, NULL }, /* Qq */          { NULL, NULL }, /* Qq */
         { NULL, NULL }, /* Re */          { NULL, NULL }, /* Re */
         { NULL, NULL }, /* Rs */          { NULL, post_rs }, /* Rs */
         { NULL, NULL }, /* Sc */          { NULL, NULL }, /* Sc */
         { NULL, NULL }, /* So */          { NULL, NULL }, /* So */
         { NULL, NULL }, /* Sq */          { NULL, NULL }, /* Sq */
Line 176  const struct actions mdoc_actions[MDOC_MAX] = {
Line 188  const struct actions mdoc_actions[MDOC_MAX] = {
         { NULL, NULL }, /* sp */          { NULL, NULL }, /* sp */
 };  };
   
 static  int       concat(struct mdoc *, const struct mdoc_node *,  #define RSORD_MAX 13
                         char *, size_t);  
   
 #ifdef __linux__  static  const int rsord[RSORD_MAX] = {
 extern  size_t    strlcat(char *, const char *, size_t);          MDOC__A,
 #endif          MDOC__T,
           MDOC__B,
           MDOC__I,
           MDOC__J,
           MDOC__R,
           MDOC__N,
           MDOC__V,
           MDOC__P,
           MDOC__Q,
           MDOC__D,
           MDOC__O,
           MDOC__C
   };
   
   
 int  int
Line 617  post_bl_width(POST_ARGS)
Line 640  post_bl_width(POST_ARGS)
   
         if (0 == strcmp(p, "Ds"))          if (0 == strcmp(p, "Ds"))
                 width = 6;                  width = 6;
         else if (MDOC_MAX == (tok = mdoc_hash_find(m->htab, p)))          else if (MDOC_MAX == (tok = mdoc_hash_find(p)))
                 return(1);                  return(1);
         else if (0 == (width = mdoc_macro2len(tok)))          else if (0 == (width = mdoc_macro2len(tok)))
                 return(mdoc_nwarn(m, n, ENOWIDTH));                  return(mdoc_nwarn(m, n, ENOWIDTH));
Line 825  pre_dl(PRE_ARGS)
Line 848  pre_dl(PRE_ARGS)
   
   
 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.
            */
   
           assert(n->args);
           for (i = 0; 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].value =
                   calloc(1, sizeof(char *));
                   if (NULL == n->args->argv[i].value)
                           return(mdoc_nerr(m, n, EMALLOC));
                   n->args->argv[i].sz++;
                   n->args->argv[i].value[0] = strdup("8n");
                   if (NULL == n->args->argv[i].value[0])
                           return(mdoc_nerr(m, n, EMALLOC));
                   break;
           }
   
           return(1);
   }
   
   
   static int
   pre_bl(PRE_ARGS)
   {
   
           return(MDOC_BLOCK == n->type ? pre_offset(m, n) : 1);
   }
   
   
   static int
 pre_bd(PRE_ARGS)  pre_bd(PRE_ARGS)
 {  {
         int              i;          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'. */          /* Enter literal context if `Bd -literal' or `-unfilled'. */
   
         /*  
          * TODO: `-offset' without an argument should be the width of  
          * the literal "<string>".  
          */  
   
         for (n = n->parent, i = 0; i < (int)n->args->argc; i++)          for (n = n->parent, i = 0; i < (int)n->args->argc; i++)
                 if (MDOC_Literal == n->args->argv[i].arg)                  if (MDOC_Literal == n->args->argv[i].arg)
                         break;                          m->flags |= MDOC_LITERAL;
                 else if (MDOC_Unfilled == n->args->argv[i].arg)                  else if (MDOC_Unfilled == n->args->argv[i].arg)
                         break;                          m->flags |= MDOC_LITERAL;
   
         if (i < (int)n->args->argc)  
                 m->flags |= MDOC_LITERAL;  
   
         return(1);          return(1);
 }  }
   
Line 862  post_display(POST_ARGS)
Line 920  post_display(POST_ARGS)
 }  }
   
   
   static inline int
   order_rs(int t)
   {
           int             i;
   
           for (i = 0; i < RSORD_MAX; i++)
                   if (rsord[i] == t)
                           return(i);
   
           abort();
           /* NOTREACHED */
   }
   
   
   static int
   post_rs(POST_ARGS)
   {
           struct mdoc_node        *nn, *next, *prev;
           int                      o;
   
           if (MDOC_BLOCK != n->type)
                   return(1);
   
           assert(n->body->child);
           for (next = NULL, nn = n->body->child->next; nn; nn = next) {
                   o = order_rs(nn->tok);
   
                   /* Remove `nn' from the chain. */
                   next = nn->next;
                   if (next)
                           next->prev = nn->prev;
   
                   prev = nn->prev;
                   if (prev)
                           prev->next = nn->next;
   
                   nn->prev = nn->next = NULL;
   
                   /*
                    * Scan back until we reach a node that's ordered before
                    * us, then set ourselves as being the next.
                    */
                   for ( ; prev; prev = prev->prev)
                           if (order_rs(prev->tok) <= o)
                                   break;
   
                   nn->prev = prev;
                   if (prev) {
                           if (prev->next)
                                   prev->next->prev = nn;
                           nn->next = prev->next;
                           prev->next = nn;
                           continue;
                   }
   
                   n->body->child->prev = nn;
                   nn->next = n->body->child;
                   n->body->child = nn;
           }
           return(1);
   }

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.40

CVSweb