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

Diff for /mandoc/mandoc.c between version 1.95 and 1.99

version 1.95, 2015/10/12 00:08:15 version 1.99, 2017/06/01 19:05:37
Line 32 
Line 32 
 #include "mandoc_aux.h"  #include "mandoc_aux.h"
 #include "libmandoc.h"  #include "libmandoc.h"
   
 #define DATESIZE 32  
   
 static  int      a2time(time_t *, const char *, const char *);  static  int      a2time(time_t *, const char *, const char *);
 static  char    *time2a(time_t);  static  char    *time2a(time_t);
   
Line 177  mandoc_escape(const char **end, const char **start, in
Line 175  mandoc_escape(const char **end, const char **start, in
                                 ++*end;                                  ++*end;
                         return ESCAPE_ERROR;                          return ESCAPE_ERROR;
                 }                  }
                 gly = ESCAPE_IGNORE;                  gly = (*start)[-1] == 'h' ? ESCAPE_HORIZ : ESCAPE_IGNORE;
                 term = **start;                  term = **start;
                 *start = ++*end;                  *start = ++*end;
                 break;                  break;
Line 333  mandoc_escape(const char **end, const char **start, in
Line 331  mandoc_escape(const char **end, const char **start, in
                         break;                          break;
                 if (*sz == 6 && (*start)[1] == '0')                  if (*sz == 6 && (*start)[1] == '0')
                         break;                          break;
                   if (*sz == 5 && (*start)[1] == 'D' &&
                       strchr("89ABCDEF", (*start)[2]) != NULL)
                           break;
                 if ((int)strspn(*start + 1, "0123456789ABCDEFabcdef")                  if ((int)strspn(*start + 1, "0123456789ABCDEFabcdef")
                     + 1 == *sz)                      + 1 == *sz)
                         gly = ESCAPE_UNICODE;                          gly = ESCAPE_UNICODE;
Line 477  time2a(time_t t)
Line 478  time2a(time_t t)
          * up to 2 characters for the day + comma + blank           * up to 2 characters for the day + comma + blank
          * 4 characters for the year and a terminating '\0'           * 4 characters for the year and a terminating '\0'
          */           */
   
         p = buf = mandoc_malloc(10 + 4 + 4 + 1);          p = buf = mandoc_malloc(10 + 4 + 4 + 1);
   
         if (0 == (ssz = strftime(p, 10 + 1, "%B ", tm)))          if ((ssz = strftime(p, 10 + 1, "%B ", tm)) == 0)
                 goto fail;                  goto fail;
         p += (int)ssz;          p += (int)ssz;
   
         if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday)))          /*
            * The output format is just "%d" here, not "%2d" or "%02d".
            * That's also the reason why we can't just format the
            * date as a whole with "%B %e, %Y" or "%B %d, %Y".
            * Besides, the present approach is less prone to buffer
            * overflows, in case anybody should ever introduce the bug
            * of looking at LC_TIME.
            */
   
           if ((isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday)) == -1)
                 goto fail;                  goto fail;
         p += isz;          p += isz;
   
         if (0 == strftime(p, 4 + 1, "%Y", tm))          if (strftime(p, 4 + 1, "%Y", tm) == 0)
                 goto fail;                  goto fail;
         return buf;          return buf;
   
Line 499  fail:
Line 510  fail:
 char *  char *
 mandoc_normdate(struct mparse *parse, char *in, int ln, int pos)  mandoc_normdate(struct mparse *parse, char *in, int ln, int pos)
 {  {
         char            *out;  
         time_t           t;          time_t           t;
   
         if (NULL == in || '\0' == *in ||          /* No date specified: use today's date. */
             0 == strcmp(in, "$" "Mdocdate$")) {  
           if (in == NULL || *in == '\0' || strcmp(in, "$" "Mdocdate$") == 0) {
                 mandoc_msg(MANDOCERR_DATE_MISSING, parse, ln, pos, NULL);                  mandoc_msg(MANDOCERR_DATE_MISSING, parse, ln, pos, NULL);
                 time(&t);                  return time2a(time(NULL));
         }          }
         else if (a2time(&t, "%Y-%m-%d", in))  
                 t = 0;          /* Valid mdoc(7) date format. */
         else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in) &&  
             !a2time(&t, "%b %d, %Y", in)) {          if (a2time(&t, "$" "Mdocdate: %b %d %Y $", in) ||
               a2time(&t, "%b %d, %Y", in))
                   return time2a(t);
   
           /* Do not warn about the legacy man(7) format. */
   
           if ( ! a2time(&t, "%Y-%m-%d", in))
                 mandoc_msg(MANDOCERR_DATE_BAD, parse, ln, pos, in);                  mandoc_msg(MANDOCERR_DATE_BAD, parse, ln, pos, in);
                 t = 0;  
         }          /* Use any non-mdoc(7) date verbatim. */
         out = t ? time2a(t) : NULL;  
         return out ? out : mandoc_strdup(in);          return mandoc_strdup(in);
 }  }
   
 int  int

Legend:
Removed from v.1.95  
changed lines
  Added in v.1.99

CVSweb