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

Diff for /mandoc/mandoc.c between version 1.36 and 1.37

version 1.36, 2011/01/03 22:42:37 version 1.37, 2011/03/07 01:35:51
Line 31 
Line 31 
 #include "mandoc.h"  #include "mandoc.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);
   
   
 int  int
 mandoc_special(char *p)  mandoc_special(char *p)
 {  {
Line 380  a2time(time_t *t, const char *fmt, const char *p)
Line 382  a2time(time_t *t, const char *fmt, const char *p)
 }  }
   
   
 /*  static char *
  * Convert from a manual date string (see mdoc(7) and man(7)) into a  time2a(time_t t)
  * date according to the stipulated date type.  
  */  
 time_t  
 mandoc_a2time(int flags, const char *p)  
 {  {
         time_t           t;          struct tm        tm;
           char             buf[DATESIZE];
           char            *p;
           size_t           nsz, rsz;
           int              isz;
   
         if (MTIME_MDOCDATE & flags) {          localtime_r(&t, &tm);
                 if (0 == strcmp(p, "$" "Mdocdate$"))  
                         return(time(NULL));  
                 if (a2time(&t, "$" "Mdocdate: %b %d %Y $", p))  
                         return(t);  
         }  
   
         if (MTIME_CANONICAL & flags || MTIME_REDUCED & flags)          p = buf;
                 if (a2time(&t, "%b %d, %Y", p))          rsz = DATESIZE;
                         return(t);  
   
         if (MTIME_ISO_8601 & flags)          if (0 == (nsz = strftime(p, rsz, "%B ", &tm)))
                 if (a2time(&t, "%Y-%m-%d", p))                  return(NULL);
                         return(t);  
   
         if (MTIME_REDUCED & flags) {          p += (int)nsz;
                 if (a2time(&t, "%d, %Y", p))          rsz -= nsz;
                         return(t);  
                 if (a2time(&t, "%Y", p))  
                         return(t);  
         }  
   
         return(0);          if (-1 == (isz = snprintf(p, rsz, "%d, ", tm.tm_mday)))
                   return(NULL);
   
           p += isz;
           rsz -= isz;
   
           return(strftime(p, rsz, "%Y", &tm) ? buf : NULL);
   }
   
   
   char *
   mandoc_normdate(char *in, mandocmsg msg, void *data, int ln, int pos)
   {
           char            *out;
           time_t           t;
   
           if (NULL == in || '\0' == *in ||
               0 == strcmp(in, "$" "Mdocdate$")) {
                   (*msg)(MANDOCERR_NODATE, data, ln, pos, NULL);
                   time(&t);
           }
           else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in) &&
               !a2time(&t, "%b %d, %Y", in) &&
               !a2time(&t, "%Y-%m-%d", in)) {
                   (*msg)(MANDOCERR_BADDATE, data, ln, pos, NULL);
                   t = 0;
           }
           out = t ? time2a(t) : NULL;
           return(mandoc_strdup(out ? out : in));
 }  }
   
   

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.37

CVSweb