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

Diff for /mandoc/mdoc_term.c between version 1.212 and 1.225

version 1.212, 2011/01/25 15:28:56 version 1.225, 2011/04/04 16:21:51
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
Line 32 
Line 32 
 #include "out.h"  #include "out.h"
 #include "term.h"  #include "term.h"
 #include "mdoc.h"  #include "mdoc.h"
 #include "chars.h"  
 #include "main.h"  #include "main.h"
   
 #define INDENT            5  #define INDENT            5
Line 312  print_mdoc_node(DECL_ARGS)
Line 311  print_mdoc_node(DECL_ARGS)
   
         memset(&npair, 0, sizeof(struct termpair));          memset(&npair, 0, sizeof(struct termpair));
         npair.ppair = pair;          npair.ppair = pair;
   
         switch (n->type) {  
         case (MDOC_TEXT):  
                 if (' ' == *n->string && MDOC_LINE & n->flags)  
                         term_newln(p);  
                 term_word(p, n->string);  
                 break;  
         case (MDOC_TBL):  
                 term_tbl(p, n->span);  
                 break;  
         default:  
                 if (termacts[n->tok].pre && ENDBODY_NOT == n->end)  
                         chld = (*termacts[n->tok].pre)  
                                 (p, &npair, m, n);  
                 break;  
         }  
   
         /*          /*
          * Keeps only work until the end of a line.  If a keep was           * Keeps only work until the end of a line.  If a keep was
Line 359  print_mdoc_node(DECL_ARGS)
Line 342  print_mdoc_node(DECL_ARGS)
              (n->parent && MDOC_SYNPRETTY & n->parent->flags)))               (n->parent && MDOC_SYNPRETTY & n->parent->flags)))
                 p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);                  p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
   
           /*
            * After the keep flags have been set up, we may now
            * produce output.  Note that some pre-handlers do so.
            */
   
           switch (n->type) {
           case (MDOC_TEXT):
                   if (' ' == *n->string && MDOC_LINE & n->flags)
                           term_newln(p);
                   if (MDOC_DELIMC & n->flags)
                           p->flags |= TERMP_NOSPACE;
                   term_word(p, n->string);
                   if (MDOC_DELIMO & n->flags)
                           p->flags |= TERMP_NOSPACE;
                   break;
           case (MDOC_EQN):
                   term_word(p, n->eqn->data);
                   break;
           case (MDOC_TBL):
                   term_tbl(p, n->span);
                   break;
           default:
                   if (termacts[n->tok].pre && ENDBODY_NOT == n->end)
                           chld = (*termacts[n->tok].pre)
                                   (p, &npair, m, n);
                   break;
           }
   
         if (chld && n->child)          if (chld && n->child)
                 print_mdoc_nodelist(p, &npair, m, n->child);                  print_mdoc_nodelist(p, &npair, m, n->child);
   
Line 369  print_mdoc_node(DECL_ARGS)
Line 380  print_mdoc_node(DECL_ARGS)
                 break;                  break;
         case (MDOC_TBL):          case (MDOC_TBL):
                 break;                  break;
           case (MDOC_EQN):
                   break;
         default:          default:
                 if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)                  if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)
                         break;                          break;
Line 403  print_mdoc_node(DECL_ARGS)
Line 416  print_mdoc_node(DECL_ARGS)
 static void  static void
 print_mdoc_foot(struct termp *p, const void *arg)  print_mdoc_foot(struct termp *p, const void *arg)
 {  {
         char            buf[DATESIZ], os[BUFSIZ];  
         const struct mdoc_meta *m;          const struct mdoc_meta *m;
   
         m = (const struct mdoc_meta *)arg;          m = (const struct mdoc_meta *)arg;
Line 418  print_mdoc_foot(struct termp *p, const void *arg)
Line 430  print_mdoc_foot(struct termp *p, const void *arg)
          * SYSTEM                  DATE                    SYSTEM           * SYSTEM                  DATE                    SYSTEM
          */           */
   
         time2a(m->date, buf, DATESIZ);  
         strlcpy(os, m->os, BUFSIZ);  
   
         term_vspace(p);          term_vspace(p);
   
         p->offset = 0;          p->offset = 0;
         p->rmargin = (p->maxrmargin -          p->rmargin = (p->maxrmargin -
                         term_strlen(p, buf) + term_len(p, 1)) / 2;                          term_strlen(p, m->date) + term_len(p, 1)) / 2;
         p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;          p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
   
         term_word(p, os);          term_word(p, m->os);
         term_flushln(p);          term_flushln(p);
   
         p->offset = p->rmargin;          p->offset = p->rmargin;
         p->rmargin = p->maxrmargin - term_strlen(p, os);          p->rmargin = p->maxrmargin - term_strlen(p, m->os);
         p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;          p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
   
         term_word(p, buf);          term_word(p, m->date);
         term_flushln(p);          term_flushln(p);
   
         p->offset = p->rmargin;          p->offset = p->rmargin;
Line 443  print_mdoc_foot(struct termp *p, const void *arg)
Line 452  print_mdoc_foot(struct termp *p, const void *arg)
         p->flags &= ~TERMP_NOBREAK;          p->flags &= ~TERMP_NOBREAK;
         p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;          p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
   
         term_word(p, os);          term_word(p, m->os);
         term_flushln(p);          term_flushln(p);
   
         p->offset = 0;          p->offset = 0;
Line 1151  static int
Line 1160  static int
 termp_ns_pre(DECL_ARGS)  termp_ns_pre(DECL_ARGS)
 {  {
   
         p->flags |= TERMP_NOSPACE;          if ( ! (MDOC_LINE & n->flags))
                   p->flags |= TERMP_NOSPACE;
         return(1);          return(1);
 }  }
   
Line 1173  termp_rs_pre(DECL_ARGS)
Line 1183  termp_rs_pre(DECL_ARGS)
 static int  static int
 termp_rv_pre(DECL_ARGS)  termp_rv_pre(DECL_ARGS)
 {  {
         const struct mdoc_node  *nn;          int              nchild;
   
         term_newln(p);          term_newln(p);
         term_word(p, "The");          term_word(p, "The");
   
         for (nn = n->child; nn; nn = nn->next) {          nchild = n->nchild;
           for (n = n->child; n; n = n->next) {
                 term_fontpush(p, TERMFONT_BOLD);                  term_fontpush(p, TERMFONT_BOLD);
                 term_word(p, nn->string);                  term_word(p, n->string);
                 term_fontpop(p);                  term_fontpop(p);
   
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 if (nn->next && NULL == nn->next->next)                  term_word(p, "()");
                         term_word(p, "(), and");  
                 else if (nn->next)                  if (nchild > 2 && n->next) {
                         term_word(p, "(),");                          p->flags |= TERMP_NOSPACE;
                 else                          term_word(p, ",");
                         term_word(p, "()");                  }
   
                   if (n->next && NULL == n->next->next)
                           term_word(p, "and");
         }          }
   
         if (n->child && n->child->next)          if (nchild > 1)
                 term_word(p, "functions return");                  term_word(p, "functions return");
         else          else
                 term_word(p, "function returns");                  term_word(p, "function returns");
Line 1214  termp_rv_pre(DECL_ARGS)
Line 1229  termp_rv_pre(DECL_ARGS)
 static int  static int
 termp_ex_pre(DECL_ARGS)  termp_ex_pre(DECL_ARGS)
 {  {
         const struct mdoc_node  *nn;          int              nchild;
   
           term_newln(p);
         term_word(p, "The");          term_word(p, "The");
   
         for (nn = n->child; nn; nn = nn->next) {          nchild = n->nchild;
           for (n = n->child; n; n = n->next) {
                 term_fontpush(p, TERMFONT_BOLD);                  term_fontpush(p, TERMFONT_BOLD);
                 term_word(p, nn->string);                  term_word(p, n->string);
                 term_fontpop(p);                  term_fontpop(p);
                 p->flags |= TERMP_NOSPACE;  
                 if (nn->next && NULL == nn->next->next)                  if (nchild > 2 && n->next) {
                         term_word(p, ", and");                          p->flags |= TERMP_NOSPACE;
                 else if (nn->next)  
                         term_word(p, ",");                          term_word(p, ",");
                 else                  }
                         p->flags &= ~TERMP_NOSPACE;  
                   if (n->next && NULL == n->next->next)
                           term_word(p, "and");
         }          }
   
         if (n->child && n->child->next)          if (nchild > 1)
                 term_word(p, "utilities exit");                  term_word(p, "utilities exit");
         else          else
                 term_word(p, "utility exits");                  term_word(p, "utility exits");
   
         term_word(p, "0 on success, and >0 if an error occurs.");          term_word(p, "0 on success, and >0 if an error occurs.");
         p->flags |= TERMP_SENTENCE;  
   
           p->flags |= TERMP_SENTENCE;
         return(0);          return(0);
 }  }
   
Line 1278  termp_bl_post(DECL_ARGS)
Line 1296  termp_bl_post(DECL_ARGS)
                 term_newln(p);                  term_newln(p);
 }  }
   
   
 /* ARGSUSED */  /* ARGSUSED */
 static int  static int
 termp_xr_pre(DECL_ARGS)  termp_xr_pre(DECL_ARGS)
 {  {
         const struct mdoc_node *nn;  
   
         if (NULL == n->child)          if (NULL == (n = n->child))
                 return(0);                  return(0);
   
         assert(MDOC_TEXT == n->child->type);          assert(MDOC_TEXT == n->type);
         nn = n->child;          term_word(p, n->string);
   
         term_word(p, nn->string);          if (NULL == (n = n->next))
         if (NULL == (nn = nn->next))  
                 return(0);                  return(0);
   
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         term_word(p, "(");          term_word(p, "(");
         term_word(p, nn->string);          p->flags |= TERMP_NOSPACE;
   
           assert(MDOC_TEXT == n->type);
           term_word(p, n->string);
   
           p->flags |= TERMP_NOSPACE;
         term_word(p, ")");          term_word(p, ")");
   
         return(0);          return(0);
 }  }
   
   
 /*  /*
  * This decides how to assert whitespace before any of the SYNOPSIS set   * This decides how to assert whitespace before any of the SYNOPSIS set
  * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain   * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
Line 1526  termp_fn_pre(DECL_ARGS)
Line 1546  termp_fn_pre(DECL_ARGS)
   
         p->flags |= TERMP_NOSPACE;          p->flags |= TERMP_NOSPACE;
         term_word(p, "(");          term_word(p, "(");
           p->flags |= TERMP_NOSPACE;
   
         for (nn = n->child->next; nn; nn = nn->next) {          for (nn = n->child->next; nn; nn = nn->next) {
                 term_fontpush(p, TERMFONT_UNDER);                  term_fontpush(p, TERMFONT_UNDER);
                 term_word(p, nn->string);                  term_word(p, nn->string);
                 term_fontpop(p);                  term_fontpop(p);
   
                 if (nn->next)                  if (nn->next) {
                           p->flags |= TERMP_NOSPACE;
                         term_word(p, ",");                          term_word(p, ",");
                   }
         }          }
   
           p->flags |= TERMP_NOSPACE;
         term_word(p, ")");          term_word(p, ")");
   
         if (MDOC_SYNPRETTY & n->flags)          if (MDOC_SYNPRETTY & n->flags) {
                   p->flags |= TERMP_NOSPACE;
                 term_word(p, ";");                  term_word(p, ";");
           }
   
         return(0);          return(0);
 }  }
Line 1561  termp_fa_pre(DECL_ARGS)
Line 1587  termp_fa_pre(DECL_ARGS)
                 term_word(p, nn->string);                  term_word(p, nn->string);
                 term_fontpop(p);                  term_fontpop(p);
   
                 if (nn->next)                  if (nn->next) {
                           p->flags |= TERMP_NOSPACE;
                         term_word(p, ",");                          term_word(p, ",");
                   }
         }          }
   
         if (n->child && n->next && n->next->tok == MDOC_Fa)          if (n->child && n->next && n->next->tok == MDOC_Fa) {
                   p->flags |= TERMP_NOSPACE;
                 term_word(p, ",");                  term_word(p, ",");
           }
   
         return(0);          return(0);
 }  }
Line 1677  termp_bd_post(DECL_ARGS)
Line 1707  termp_bd_post(DECL_ARGS)
 static int  static int
 termp_bx_pre(DECL_ARGS)  termp_bx_pre(DECL_ARGS)
 {  {
         char             buf[3];  
   
         if (NULL != (n = n->child)) {          if (NULL != (n = n->child)) {
                 term_word(p, n->string);                  term_word(p, n->string);
Line 1689  termp_bx_pre(DECL_ARGS)
Line 1718  termp_bx_pre(DECL_ARGS)
         }          }
   
         if (NULL != (n = n->next)) {          if (NULL != (n = n->next)) {
                 buf[0] = '-';  
                 buf[1] = toupper((unsigned char)*n->string);  
                 buf[2] = '\0';  
   
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 term_word(p, buf);                  term_word(p, "-");
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 term_word(p, n->string + 1);                  term_word(p, n->string);
         }          }
   
         return(0);          return(0);
Line 1708  static int
Line 1733  static int
 termp_xx_pre(DECL_ARGS)  termp_xx_pre(DECL_ARGS)
 {  {
         const char      *pp;          const char      *pp;
           int              flags;
   
         pp = NULL;          pp = NULL;
         switch (n->tok) {          switch (n->tok) {
Line 1733  termp_xx_pre(DECL_ARGS)
Line 1759  termp_xx_pre(DECL_ARGS)
                 break;                  break;
         }          }
   
         assert(pp);  
         term_word(p, pp);          term_word(p, pp);
         return(1);          if (n->child) {
                   flags = p->flags;
                   p->flags |= TERMP_KEEP;
                   term_word(p, n->child->string);
                   p->flags = flags;
           }
           return(0);
 }  }
   
   
Line 2000  termp_fo_pre(DECL_ARGS)
Line 2031  termp_fo_pre(DECL_ARGS)
         } else if (MDOC_BODY == n->type) {          } else if (MDOC_BODY == n->type) {
                 p->flags |= TERMP_NOSPACE;                  p->flags |= TERMP_NOSPACE;
                 term_word(p, "(");                  term_word(p, "(");
                   p->flags |= TERMP_NOSPACE;
                 return(1);                  return(1);
         }          }
   
Line 2023  termp_fo_post(DECL_ARGS)
Line 2055  termp_fo_post(DECL_ARGS)
         if (MDOC_BODY != n->type)          if (MDOC_BODY != n->type)
                 return;                  return;
   
           p->flags |= TERMP_NOSPACE;
         term_word(p, ")");          term_word(p, ")");
   
         if (MDOC_SYNPRETTY & n->flags)          if (MDOC_SYNPRETTY & n->flags) {
                   p->flags |= TERMP_NOSPACE;
                 term_word(p, ";");                  term_word(p, ";");
           }
 }  }
   
   
Line 2100  termp____post(DECL_ARGS)
Line 2135  termp____post(DECL_ARGS)
         if (NULL == n->parent || MDOC_Rs != n->parent->tok)          if (NULL == n->parent || MDOC_Rs != n->parent->tok)
                 return;                  return;
   
           p->flags |= TERMP_NOSPACE;
         if (NULL == n->next) {          if (NULL == n->next) {
                 term_word(p, ".");                  term_word(p, ".");
                 p->flags |= TERMP_SENTENCE;                  p->flags |= TERMP_SENTENCE;
Line 2136  termp_lk_pre(DECL_ARGS)
Line 2172  termp_lk_pre(DECL_ARGS)
   
         term_fontpop(p);          term_fontpop(p);
   
           p->flags |= TERMP_NOSPACE;
         term_word(p, ":");          term_word(p, ":");
   
         term_fontpush(p, TERMFONT_BOLD);          term_fontpush(p, TERMFONT_BOLD);
Line 2187  termp__t_post(DECL_ARGS)
Line 2224  termp__t_post(DECL_ARGS)
          * If we're in an `Rs' and there's a journal present, then quote           * If we're in an `Rs' and there's a journal present, then quote
          * us instead of underlining us (for disambiguation).           * us instead of underlining us (for disambiguation).
          */           */
         if (n->parent && MDOC_Rs == n->parent->tok &&          if (n->parent && MDOC_Rs == n->parent->tok &&
                         n->parent->norm->Rs.quote_T)                          n->parent->norm->Rs.quote_T)
                 termp_quote_post(p, pair, m, n);                  termp_quote_post(p, pair, m, n);
   

Legend:
Removed from v.1.212  
changed lines
  Added in v.1.225

CVSweb