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

Diff for /mandoc/out.c between version 1.9 and 1.25

version 1.9, 2009/11/07 14:14:15 version 1.25, 2010/08/24 12:18:49
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>   * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 14 
Line 14 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   #ifdef HAVE_CONFIG_H
   #include "config.h"
   #endif
   
 #include <sys/types.h>  #include <sys/types.h>
   
 #include <assert.h>  #include <assert.h>
Line 25 
Line 29 
   
 #include "out.h"  #include "out.h"
   
 #ifdef __linux__  
 extern  size_t    strlcat(char *, const char *, size_t);  
 #endif  
   
 /*  /*
  * Convert a `scaling unit' to a consistent form, or fail.  Scaling   * Convert a `scaling unit' to a consistent form, or fail.  Scaling
  * units are documented in groff.7, mdoc.7, man.7.   * units are documented in groff.7, mdoc.7, man.7.
Line 116  a2roffsu(const char *src, struct roffsu *dst, enum rof
Line 116  a2roffsu(const char *src, struct roffsu *dst, enum rof
                 return(0);                  return(0);
         }          }
   
           /* FIXME: do this in the caller. */
         if ((dst->scale = atof(buf)) < 0)          if ((dst->scale = atof(buf)) < 0)
                 dst->scale = 0;                  dst->scale = 0;
         dst->unit = unit;          dst->unit = unit;
         dst->pt = hasd;  
   
         return(1);          return(1);
 }  }
   
Line 167  time2a(time_t t, char *dst, size_t sz)
Line 166  time2a(time_t t, char *dst, size_t sz)
 }  }
   
   
 /* Returns length of parsed string. */  
 int  int
 a2roffdeco(enum roffdeco *d,  a2roffdeco(enum roffdeco *d, const char **word, size_t *sz)
                 const char **word, size_t *sz)  
 {  {
         int              j, type, sv, t, lim;          int              i, j, lim;
           char             term, c;
         const char      *wp;          const char      *wp;
           enum roffdeco    dd;
   
         *d = DECO_NONE;          *d = DECO_NONE;
           lim = i = 0;
           term = '\0';
         wp = *word;          wp = *word;
         type = 1;  
   
         switch (*wp) {          switch ((c = wp[i++])) {
         case ('\0'):  
                 return(0);  
   
         case ('('):          case ('('):
                 wp++;  
                 if ('\0' == *wp)  
                         return(1);  
                 if ('\0' == *(wp + 1))  
                         return(2);  
   
                 *d = DECO_SPECIAL;                  *d = DECO_SPECIAL;
                 *sz = 2;                  lim = 2;
                 *word = wp;                  break;
                 return(3);          case ('F'):
                   /* FALLTHROUGH */
           case ('f'):
                   *d = 'F' == c ? DECO_FFONT : DECO_FONT;
   
         case ('*'):                  switch (wp[i++]) {
                 wp++;  
   
                 switch (*wp) {  
                 case ('\0'):  
                         return(1);  
   
                 case ('('):                  case ('('):
                         wp++;                          lim = 2;
                         if ('\0' == *wp)                          break;
                                 return(2);  
                         if ('\0' == *(wp + 1))  
                                 return(3);  
   
                         *d = DECO_RESERVED;  
                         *sz = 2;  
                         *word = wp;  
                         return(4);  
   
                 case ('['):                  case ('['):
                         type = 0;                          term = ']';
                         break;                          break;
   
                 default:  
                         *d = DECO_RESERVED;  
                         *sz = 1;  
                         *word = wp;  
                         return(2);  
                 }  
                 break;  
   
 #if 0  
         case ('s'):  
                 wp++;  
   
                 /* This closely follows mandoc_special(). */  
                 if ('\0' == *wp)  
                         return(1);  
   
                 t = 0;  
                 lim = 1;  
   
                 if (*wp == '\'') {  
                         lim = 0;  
                         t = 1;  
                         ++wp;  
                 } else if (*wp == '[') {  
                         lim = 0;  
                         t = 2;  
                         ++wp;  
                 } else if (*wp == '(') {  
                         lim = 2;  
                         t = 3;  
                         ++wp;  
                 }  
   
                 if (*wp == '+' || *wp == '-')  
                         ++wp;  
   
                 if (*wp == '\'') {  
                         if (t) {  
                                 *word = wp;  
                                 return;  
                         }  
                         lim = 0;  
                         t = 1;  
                         ++wp;  
                 } else if (*wp == '[') {  
                         if (t) {  
                                 *word = wp;  
                                 return;  
                         }  
                         lim = 0;  
                         t = 2;  
                         ++wp;  
                 } else if (*wp == '(') {  
                         if (t) {  
                                 *word = wp;  
                                 return;  
                         }  
                         lim = 2;  
                         t = 3;  
                         ++wp;  
                 }  
   
                 if ( ! isdigit((u_char)*wp)) {  
                         *word = --wp;  
                         return;  
                 }  
   
                 for (j = 0; isdigit((u_char)*wp); j++) {  
                         if (lim && j >= lim)  
                                 break;  
                         ++wp;  
                 }  
   
                 if (t && t < 3) {  
                         if (1 == t && *wp != '\'') {  
                                 *word = --wp;  
                                 return;  
                         }  
                         if (2 == t && *wp != ']') {  
                                 *word = --wp;  
                                 return;  
                         }  
                         ++wp;  
                 }  
                 *word = --wp;  
                 return;  
 #endif  
   
         case ('f'):  
                 wp++;  
   
                 switch (*wp) {  
                 case ('\0'):  
                         return(1);  
                 case ('3'):                  case ('3'):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case ('B'):                  case ('B'):
                         *d = DECO_BOLD;                          *d = DECO_BOLD;
                         break;                          return(i);
                 case ('2'):                  case ('2'):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case ('I'):                  case ('I'):
                         *d = DECO_ITALIC;                          *d = DECO_ITALIC;
                         break;                          return(i);
                 case ('P'):                  case ('P'):
                         *d = DECO_PREVIOUS;                          *d = DECO_PREVIOUS;
                         break;                          return(i);
                 case ('1'):                  case ('1'):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case ('R'):                  case ('R'):
                         *d = DECO_ROMAN;                          *d = DECO_ROMAN;
                           return(i);
                   default:
                           i--;
                           lim = 1;
                         break;                          break;
                   }
                   break;
           case ('M'):
                   /* FALLTHROUGH */
           case ('m'):
                   /* FALLTHROUGH */
           case ('*'):
                   if ('*' == c)
                           *d = DECO_RESERVED;
   
                   switch (wp[i++]) {
                   case ('('):
                           lim = 2;
                           break;
                   case ('['):
                           term = ']';
                           break;
                 default:                  default:
                           i--;
                           lim = 1;
                         break;                          break;
                 }                  }
                   break;
           case ('h'):
                   /* FALLTHROUGH */
           case ('v'):
                   /* FALLTHROUGH */
           case ('s'):
                   j = 0;
                   if ('+' == wp[i] || '-' == wp[i]) {
                           i++;
                           j = 1;
                   }
   
                 return(2);                  switch (wp[i++]) {
                   case ('('):
                           lim = 2;
                           break;
                   case ('['):
                           term = ']';
                           break;
                   case ('\''):
                           term = '\'';
                           break;
                   case ('0'):
                           j = 1;
                           /* FALLTHROUGH */
                   default:
                           i--;
                           lim = 1;
                           break;
                   }
   
                   if ('+' == wp[i] || '-' == wp[i]) {
                           if (j)
                                   return(i);
                           i++;
                   }
   
                   break;
         case ('['):          case ('['):
                   *d = DECO_SPECIAL;
                   term = ']';
                 break;                  break;
           case ('c'):
                   *d = DECO_NOSPACE;
                   return(i);
           case ('z'):
                   *d = DECO_NONE;
                   if ('\\' == wp[i]) {
                           *word = &wp[++i];
                           return(i + a2roffdeco(&dd, word, sz));
                   } else
                           lim = 1;
                   break;
         default:          default:
                 *d = DECO_SPECIAL;                  *d = DECO_SSPECIAL;
                 *word = wp;                  i--;
                 *sz = 1;                  lim = 1;
                 return(1);                  break;
         }          }
   
         *word = ++wp;          assert(term || lim);
         for (j = 0; *wp && ']' != *wp; wp++, j++)          *word = &wp[i];
                 /* Loop... */ ;  
   
         if ('\0' == *wp)          if (term) {
                 return(j + 1);                  j = i;
                   while (wp[i] && wp[i] != term)
                           i++;
                   if ('\0' == wp[i]) {
                           *d = DECO_NONE;
                           return(i);
                   }
   
         *d = type ? DECO_SPECIAL : DECO_RESERVED;                  assert(i >= j);
         *sz = j;                  *sz = (size_t)(i - j);
         return (j + 2);  
                   return(i + 1);
           }
   
           assert(lim > 0);
           *sz = (size_t)lim;
   
           for (j = 0; wp[i] && j < lim; j++)
                   i++;
           if (j < lim)
                   *d = DECO_NONE;
   
           return(i);
 }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.25

CVSweb