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

Diff for /mandoc/term.c between version 1.43 and 1.44

version 1.43, 2009/03/06 14:13:47 version 1.44, 2009/03/08 13:52:29
Line 83  const int ttypes[TTYPE_NMAX] = {
Line 83  const int ttypes[TTYPE_NMAX] = {
         TERMP_BOLD              /* TTYPE_DIAG */          TERMP_BOLD              /* TTYPE_DIAG */
 };  };
   
 static  int               arg_hasattr(int, size_t,  static  int               arg_hasattr(int, const struct mdoc_node *);
                                 const struct mdoc_arg *);  static  int               arg_getattr(int, const struct mdoc_node *);
 static  int               arg_getattr(int, size_t,  static  size_t            arg_offset(const struct mdoc_argv *);
                                 const struct mdoc_arg *);  static  size_t            arg_width(const struct mdoc_argv *);
 static  size_t            arg_offset(const struct mdoc_arg *);  
 static  size_t            arg_width(const struct mdoc_arg *);  
 static  int               arg_listtype(const struct mdoc_node *);  static  int               arg_listtype(const struct mdoc_node *);
   
 /*  /*
Line 282  const struct termact *termacts = __termacts;
Line 280  const struct termact *termacts = __termacts;
   
   
 static size_t  static size_t
 arg_width(const struct mdoc_arg *arg)  arg_width(const struct mdoc_argv *arg)
 {  {
         size_t           v;          size_t           v;
         int              i, len;          int              i, len;
Line 314  arg_width(const struct mdoc_arg *arg)
Line 312  arg_width(const struct mdoc_arg *arg)
 static int  static int
 arg_listtype(const struct mdoc_node *n)  arg_listtype(const struct mdoc_node *n)
 {  {
         const struct mdoc_block *bl;  
         int              i, len;          int              i, len;
   
         bl = &n->data.block;          assert(MDOC_BLOCK == n->type);
         len = (int)bl->argc;  
   
           len = n->args ? n->args->argc : 0;
   
         for (i = 0; i < len; i++)          for (i = 0; i < len; i++)
                 switch (bl->argv[i].arg) {                  switch (n->args->argv[i].arg) {
                 case (MDOC_Bullet):                  case (MDOC_Bullet):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (MDOC_Dash):                  case (MDOC_Dash):
Line 339  arg_listtype(const struct mdoc_node *n)
Line 337  arg_listtype(const struct mdoc_node *n)
                 case (MDOC_Item):                  case (MDOC_Item):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (MDOC_Ohang):                  case (MDOC_Ohang):
                         return(bl->argv[i].arg);                          return(n->args->argv[i].arg);
                 default:                  default:
                         break;                          break;
                 }                  }
Line 350  arg_listtype(const struct mdoc_node *n)
Line 348  arg_listtype(const struct mdoc_node *n)
   
   
 static size_t  static size_t
 arg_offset(const struct mdoc_arg *arg)  arg_offset(const struct mdoc_argv *arg)
 {  {
   
         /* TODO */          /* TODO */
Line 364  arg_offset(const struct mdoc_arg *arg)
Line 362  arg_offset(const struct mdoc_arg *arg)
   
   
 static int  static int
 arg_hasattr(int arg, size_t argc, const struct mdoc_arg *argv)  arg_hasattr(int arg, const struct mdoc_node *n)
 {  {
   
         return(-1 != arg_getattr(arg, argc, argv));          return(-1 != arg_getattr(arg, n));
 }  }
   
   
 static int  static int
 arg_getattr(int arg, size_t argc, const struct mdoc_arg *argv)  arg_getattr(int arg, const struct mdoc_node *n)
 {  {
         int              i;          int              i;
   
         for (i = 0; i < (int)argc; i++)          if (NULL == n->args)
                 if (argv[i].arg == arg)                  return(-1);
           for (i = 0; i < (int)n->args->argc; i++)
                   if (n->args->argv[i].arg == arg)
                         return(i);                          return(i);
         return(-1);          return(-1);
 }  }
Line 414  termp_dq_post(DECL_ARGS)
Line 414  termp_dq_post(DECL_ARGS)
 static int  static int
 termp_it_pre_block(DECL_ARGS)  termp_it_pre_block(DECL_ARGS)
 {  {
         const struct mdoc_node  *n;  
         const struct mdoc_block *bl;  
   
         n = node->parent->parent;  
         bl = &n->data.block;  
   
         newln(p);          newln(p);
         if ( ! arg_hasattr(MDOC_Compact, bl->argc, bl->argv))          if ( ! arg_hasattr(MDOC_Compact, node->parent->parent))
                 if (node->prev || n->prev)                  if (node->prev || node->parent->parent->prev)
                         vspace(p);                          vspace(p);
   
         return(1);          return(1);
Line 433  termp_it_pre_block(DECL_ARGS)
Line 428  termp_it_pre_block(DECL_ARGS)
 static int  static int
 termp_it_pre(DECL_ARGS)  termp_it_pre(DECL_ARGS)
 {  {
         const struct mdoc_block *bl;          const struct mdoc_node *bl;
         char             buf[7];          char             buf[7];
         int              i, type;          int              i, type;
         size_t           width, offset;          size_t           width, offset;
Line 443  termp_it_pre(DECL_ARGS)
Line 438  termp_it_pre(DECL_ARGS)
   
         /* Get ptr to list block, type, etc. */          /* Get ptr to list block, type, etc. */
   
         bl = &node->parent->parent->parent->data.block;          bl = node->parent->parent->parent;
         type = arg_listtype(node->parent->parent->parent);          type = arg_listtype(bl);
   
         /* Save parent attributes. */          /* Save parent attributes. */
   
Line 454  termp_it_pre(DECL_ARGS)
Line 449  termp_it_pre(DECL_ARGS)
   
         /* Get list width and offset. */          /* Get list width and offset. */
   
         i = arg_getattr(MDOC_Width, bl->argc, bl->argv);          i = arg_getattr(MDOC_Width, bl);
         width = i >= 0 ? arg_width(&bl->argv[i]) : 0;          width = i >= 0 ? arg_width(&bl->args->argv[i]) : 0;
   
         i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);          i = arg_getattr(MDOC_Offset, bl);
         offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;          offset = i >= 0 ? arg_offset(&bl->args->argv[i]) : 0;
   
         /*          /*
          * List-type can override the width in the case of fixed-head           * List-type can override the width in the case of fixed-head
Line 725  termp_st_pre(DECL_ARGS)
Line 720  termp_st_pre(DECL_ARGS)
 {  {
         const char      *cp;          const char      *cp;
   
         /* XXX - if child isn't text? */          if (node->child) {
         if (node->child)                  if (MDOC_TEXT != node->child->type)
                 if ((cp = mdoc_a2st(node->child->data.text.string)))                          errx(1, "expected text line arguments");
                   if ((cp = mdoc_a2st(node->child->string)))
                         word(p, cp);                          word(p, cp);
           }
         return(0);          return(0);
 }  }
   
Line 750  termp_rv_pre(DECL_ARGS)
Line 747  termp_rv_pre(DECL_ARGS)
 {  {
         int              i;          int              i;
   
         i = arg_getattr(MDOC_Std, node->data.elem.argc,          if (-1 == (i = arg_getattr(MDOC_Std, node)))
                         node->data.elem.argv);                  errx(1, "expected -std argument");
         assert(i >= 0);          if (1 != node->args->argv[i].sz)
                   errx(1, "expected -std argument");
   
         newln(p);          newln(p);
         word(p, "The");          word(p, "The");
   
         p->flags |= ttypes[TTYPE_FUNC_NAME];          p->flags |= ttypes[TTYPE_FUNC_NAME];
         word(p, *node->data.elem.argv[i].value);          word(p, *node->args->argv[i].value);
         p->flags &= ~ttypes[TTYPE_FUNC_NAME];          p->flags &= ~ttypes[TTYPE_FUNC_NAME];
   
         word(p, "() function returns the value 0 if successful;");          word(p, "() function returns the value 0 if successful;");
Line 781  termp_ex_pre(DECL_ARGS)
Line 779  termp_ex_pre(DECL_ARGS)
 {  {
         int              i;          int              i;
   
         i = arg_getattr(MDOC_Std, node->data.elem.argc,          if (-1 == (i = arg_getattr(MDOC_Std, node)))
                         node->data.elem.argv);                  errx(1, "expected -std argument");
         assert(i >= 0);          if (1 != node->args->argv[i].sz)
                   errx(1, "expected -std argument");
   
         word(p, "The");          word(p, "The");
         p->flags |= ttypes[TTYPE_PROG];          p->flags |= ttypes[TTYPE_PROG];
         word(p, *node->data.elem.argv[i].value);          word(p, *node->args->argv[i].value);
         p->flags &= ~ttypes[TTYPE_PROG];          p->flags &= ~ttypes[TTYPE_PROG];
         word(p, "utility exits 0 on success, and >0 if an error occurs.");          word(p, "utility exits 0 on success, and >0 if an error occurs.");
   
Line 833  termp_xr_pre(DECL_ARGS)
Line 832  termp_xr_pre(DECL_ARGS)
 {  {
         const struct mdoc_node *n;          const struct mdoc_node *n;
   
         n = node->child;          if (NULL == (n = node->child))
         assert(n);                  errx(1, "expected text line argument");
           if (MDOC_TEXT != n->type)
                   errx(1, "expected text line argument");
   
         assert(MDOC_TEXT == n->type);          word(p, n->string);
         word(p, n->data.text.string);  
   
         if (NULL == (n = n->next))          if (NULL == (n = n->next))
                 return(0);                  return(0);
           if (MDOC_TEXT != n->type)
                   errx(1, "expected text line argument");
   
         assert(MDOC_TEXT == n->type);  
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         word(p, "(");          word(p, "(");
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         word(p, n->data.text.string);          word(p, n->string);
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         word(p, ")");          word(p, ")");
   
Line 1066  termp_fn_pre(DECL_ARGS)
Line 1067  termp_fn_pre(DECL_ARGS)
 {  {
         const struct mdoc_node *n;          const struct mdoc_node *n;
   
         assert(node->child);          if (NULL == node->child)
         assert(MDOC_TEXT == node->child->type);                  errx(1, "expected text line arguments");
           if (MDOC_TEXT != node->child->type)
                   errx(1, "expected text line arguments");
   
         /* FIXME: can be "type funcname" "type varname"... */          /* FIXME: can be "type funcname" "type varname"... */
   
         p->flags |= ttypes[TTYPE_FUNC_NAME];          p->flags |= ttypes[TTYPE_FUNC_NAME];
         word(p, node->child->data.text.string);          word(p, node->child->string);
         p->flags &= ~ttypes[TTYPE_FUNC_NAME];          p->flags &= ~ttypes[TTYPE_FUNC_NAME];
   
         word(p, "(");          word(p, "(");
   
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         for (n = node->child->next; n; n = n->next) {          for (n = node->child->next; n; n = n->next) {
                 assert(MDOC_TEXT == n->type);                  if (MDOC_TEXT != n->type)
                           errx(1, "expected text line arguments");
                 p->flags |= ttypes[TTYPE_FUNC_ARG];                  p->flags |= ttypes[TTYPE_FUNC_ARG];
                 word(p, n->data.text.string);                  word(p, n->string);
                 p->flags &= ~ttypes[TTYPE_FUNC_ARG];                  p->flags &= ~ttypes[TTYPE_FUNC_ARG];
                 if (n->next)                  if (n->next)
                         word(p, ",");                          word(p, ",");
Line 1129  termp_fa_pre(DECL_ARGS)
Line 1133  termp_fa_pre(DECL_ARGS)
         }          }
   
         for (n = node->child; n; n = n->next) {          for (n = node->child; n; n = n->next) {
                 assert(MDOC_TEXT == n->type);                  if (MDOC_TEXT != n->type)
                           errx(1, "expected text line arguments");
   
                 p->flags |= ttypes[TTYPE_FUNC_ARG];                  p->flags |= ttypes[TTYPE_FUNC_ARG];
                 word(p, n->data.text.string);                  word(p, n->string);
                 p->flags &= ~ttypes[TTYPE_FUNC_ARG];                  p->flags &= ~ttypes[TTYPE_FUNC_ARG];
   
                 if (n->next)                  if (n->next)
Line 1160  termp_va_pre(DECL_ARGS)
Line 1165  termp_va_pre(DECL_ARGS)
 static int  static int
 termp_bd_pre(DECL_ARGS)  termp_bd_pre(DECL_ARGS)
 {  {
         const struct mdoc_block *bl;  
         const struct mdoc_node  *n;          const struct mdoc_node  *n;
         int              i, type;          int                      i, type;
   
         if (MDOC_BLOCK == node->type) {          if (MDOC_BLOCK == node->type) {
                 if (node->prev)                  if (node->prev)
Line 1171  termp_bd_pre(DECL_ARGS)
Line 1175  termp_bd_pre(DECL_ARGS)
         } else if (MDOC_BODY != node->type)          } else if (MDOC_BODY != node->type)
                 return(1);                  return(1);
   
           if (NULL == node->parent->args)
                   errx(1, "missing display type");
   
         pair->offset = p->offset;          pair->offset = p->offset;
         bl = &node->parent->data.block;  
   
         for (type = -1, i = 0; i < (int)bl->argc; i++) {          for (type = -1, i = 0;
                 switch (bl->argv[i].arg) {                          i < (int)node->parent->args->argc; i++) {
                   switch (node->parent->args->argv[i].arg) {
                 case (MDOC_Ragged):                  case (MDOC_Ragged):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (MDOC_Filled):                  case (MDOC_Filled):
Line 1183  termp_bd_pre(DECL_ARGS)
Line 1190  termp_bd_pre(DECL_ARGS)
                 case (MDOC_Unfilled):                  case (MDOC_Unfilled):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (MDOC_Literal):                  case (MDOC_Literal):
                         type = bl->argv[i].arg;                          type = node->parent->args->argv[i].arg;
                         i = (int)bl->argc;                          i = (int)node->parent->args->argc;
                         break;                          break;
                 default:                  default:
                         errx(1, "display type not supported");                          break;
                 }                  }
         }          }
   
         assert(-1 != type);          if (NULL == node->parent->args)
                   errx(1, "missing display type");
   
         i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);          i = arg_getattr(MDOC_Offset, node->parent);
         if (-1 != i) {          if (-1 != i) {
                 assert(1 == bl->argv[i].sz);                  if (1 != node->args->argv[i].sz)
                 p->offset += arg_offset(&bl->argv[i]);                          errx(1, "expected single value");
                   p->offset += arg_offset(&node->args->argv[i]);
         }          }
   
   
         switch (type) {          switch (type) {
         case (MDOC_Literal):          case (MDOC_Literal):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
Line 1216  termp_bd_pre(DECL_ARGS)
Line 1224  termp_bd_pre(DECL_ARGS)
                         warnx("non-text children not yet allowed");                          warnx("non-text children not yet allowed");
                         continue;                          continue;
                 }                  }
                 word(p, n->data.text.string);                  word(p, n->string);
                 flushln(p);                  flushln(p);
         }          }
   
Line 1495  termp_at_pre(DECL_ARGS)
Line 1503  termp_at_pre(DECL_ARGS)
         att = NULL;          att = NULL;
   
         if (node->child) {          if (node->child) {
                 assert(MDOC_TEXT == node->child->type);                  if (MDOC_TEXT != node->child->type)
                 att = mdoc_a2att(node->child->data.text.string);                          errx(1, "expected text line argument");
                   att = mdoc_a2att(node->child->string);
         }          }
   
         if (NULL == att)          if (NULL == att)
Line 1572  termp_fo_pre(DECL_ARGS)
Line 1581  termp_fo_pre(DECL_ARGS)
   
         p->flags |= ttypes[TTYPE_FUNC_NAME];          p->flags |= ttypes[TTYPE_FUNC_NAME];
         for (n = node->child; n; n = n->next) {          for (n = node->child; n; n = n->next) {
                 assert(MDOC_TEXT == n->type);                  if (MDOC_TEXT != n->type)
                 word(p, n->data.text.string);                          errx(1, "expected text line argument");
                   word(p, n->string);
         }          }
         p->flags &= ~ttypes[TTYPE_FUNC_NAME];          p->flags &= ~ttypes[TTYPE_FUNC_NAME];
   
Line 1599  static int
Line 1609  static int
 termp_bf_pre(DECL_ARGS)  termp_bf_pre(DECL_ARGS)
 {  {
         const struct mdoc_node  *n;          const struct mdoc_node  *n;
         const struct mdoc_block *b;  
   
         /* XXX - we skip over possible trailing HEAD tokens. */          if (MDOC_HEAD == node->type) {
   
         if (MDOC_HEAD == node->type)  
                 return(0);                  return(0);
         else if (MDOC_BLOCK != node->type)          } else if (MDOC_BLOCK != node->type)
                 return(1);                  return(1);
   
         b = &node->data.block;          if (NULL == (n = node->head->child)) {
                   if (arg_hasattr(MDOC_Emphasis, node))
         if (NULL == (n = b->head->child)) {  
                 if (arg_hasattr(MDOC_Emphasis, b->argc, b->argv))  
                         TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);                          TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
                 else if (arg_hasattr(MDOC_Symbolic, b->argc, b->argv))                  else if (arg_hasattr(MDOC_Symbolic, node))
                         TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);                          TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
   
                 return(1);                  return(1);
         }          }
   
         assert(MDOC_TEXT == n->type);          if (MDOC_TEXT != n->type)
                   errx(1, "expected text line arguments");
   
         if (0 == strcmp("Em", n->data.text.string))          if (0 == strcmp("Em", n->string))
                 TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);                  TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
         else if (0 == strcmp("Sy", n->data.text.string))          else if (0 == strcmp("Sy", n->string))
                 TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);                  TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
   
         return(1);          return(1);

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.44

CVSweb