Changeset: f5e8c486d7d1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f5e8c486d7d1
Modified Files:
        monetdb5/modules/atoms/mtime.c
Branch: Feb2013
Log Message:

Ported lots of recent mtime changes in default branch to Feb2013 branch.


diffs (truncated from 1977 to 300 lines):

diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -224,30 +224,40 @@
 
 tzone tzone_local;
 
-static str MONTHS[13] = { NULL, "january", "february", "march", "april", 
"may", "june",
+static const char *MONTHS[13] = {
+       NULL, "january", "february", "march", "april", "may", "june",
        "july", "august", "september", "october", "november", "december"
 };
 
-static str DAYS[8] = { NULL, "monday", "tuesday", "wednesday", "thursday",
-                               "friday", "saturday", "sunday"
+static const char *DAYS[8] = {
+       NULL, "monday", "tuesday", "wednesday", "thursday",
+       "friday", "saturday", "sunday"
 };
-static str COUNT1[7] = { NULL, "first", "second", "third", "fourth", "fifth", 
"last" };
-static str COUNT2[7] = { NULL, "1st", "2nd", "3rd", "4th", "5th", "last" };
-static int LEAPDAYS[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 
};
-//static int NOLEAPDAYS[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 
31 };
-static int CUMDAYS[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 
334, 365 };
-static int CUMLEAPDAYS[13] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 
305, 335, 366 };
-
-date DATE_MAX, DATE_MIN;               /* often used dates; computed once */
-
-#define YEAR_MAX       5867411
-#define YEAR_MIN       -YEAR_MAX
-#define MONTHDAYS(m,y) (((m)!=2)?LEAPDAYS[m]:leapyear(y)?29:28)
-#define YEARDAYS(y)    (leapyear(y)?366:365)
-#define LEAPYEARS(y)   (leapyears(y)+((y)>=0))
-#define DATE(d,m,y)    
((m)>0&&(m)<=12&&(d)>0&&(y)!=0&&(y)>=YEAR_MIN&&(y)<=YEAR_MAX&&(d)<=MONTHDAYS(m,y))
-#define TIME(h,m,s,x)  ((h)>=0&&(h)<24&&(m)>=0&&(m)<60&&(s)>=0&&(s)<60&&(x)>=0 
&&(x)<1000)
-#define LOWER(c)       (((c) >= 'A' && (c) <= 'Z') ? (c)+'a'-'A' : (c))
+static const char *COUNT1[7] = {
+       NULL, "first", "second", "third", "fourth", "fifth", "last"
+};
+static const char *COUNT2[7] = {
+       NULL, "1st", "2nd", "3rd", "4th", "5th", "last"
+};
+static int LEAPDAYS[13] = {
+       0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+};
+static int CUMDAYS[13] = {
+       0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
+};
+static int CUMLEAPDAYS[13] = {
+       0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366
+};
+
+static date DATE_MAX, DATE_MIN;                /* often used dates; computed 
once */
+
+#define YEAR_MAX               5867411
+#define YEAR_MIN               (-YEAR_MAX)
+#define MONTHDAYS(m,y) ((m) != 2 ? LEAPDAYS[m] : leapyear(y) ? 29 : 28)
+#define YEARDAYS(y)            (leapyear(y) ? 366 : 365)
+#define DATE(d,m,y)            ((m) > 0 && (m) <= 12 && (d) > 0 && (y) != 0 && 
(y) >= YEAR_MIN && (y) <= YEAR_MAX && (d) <= MONTHDAYS(m, y))
+#define TIME(h,m,s,x)  ((h) >= 0 && (h) < 24 && (m) >= 0 && (m) < 60 && (s) >= 
0 && (s) < 60 && (x) >= 0 && (x) < 1000)
+#define LOWER(c)               ((c) >= 'A' && (c) <= 'Z' ? (c) + 'a' - 'A' : 
(c))
 
 /*
  * auxiliary functions
@@ -264,32 +274,12 @@ static union {
 timestamp *timestamp_nil = NULL;
 static tzone *tzone_nil = NULL;
 
-static void date_prelude(void);
-
 int TYPE_date;
 int TYPE_daytime;
 int TYPE_timestamp;
 int TYPE_tzone;
 int TYPE_rule;
 
-static bat *
-monettime_prelude(void)
-{
-       ts_nil.nilval = lng_nil;
-       tz_nil.nilval = lng_nil;
-
-       timestamp_nil = &ts_nil.ts;
-       tzone_nil = &tz_nil.tz;
-
-       TYPE_date = ATOMindex("date");
-       TYPE_daytime = ATOMindex("daytime");
-       TYPE_timestamp = ATOMindex("timestamp");
-       TYPE_tzone = ATOMindex("timezone");
-       TYPE_rule = ATOMindex("rule");
-       date_prelude();
-       return NULL;
-}
-
 static int synonyms = TRUE;
 
 #define leapyear(y)            ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 
== 0))
@@ -306,7 +296,7 @@ leapyears(int year)
        /* count the 400-fold years */
        int y400 = year / 400;
 
-       return y4 + y400 - y100;        /* may be negative */
+       return y4 + y400 - y100 + (year >= 0);  /* may be negative */
 }
 
 static date
@@ -322,24 +312,27 @@ todate(int day, int month, int year)
                        n++;
                n += CUMDAYS[month - 1];
                /* current year does not count as leapyear */
-               n += 365 * year + LEAPYEARS(year >= 0 ? year - 1 : year);
+               n += 365 * year + leapyears(year >= 0 ? year - 1 : year);
        }
        return n;
 }
 
 void
-fromdate(int n, int *d, int *m, int *y)
+fromdate(date n, int *d, int *m, int *y)
 {
        int day, month, year;
 
-       if ( n == int_nil){
-               if( d) *d = int_nil;
-               if( m) *m = int_nil;
-               if( y) *y = int_nil;
+       if (n == date_nil) {
+               if (d)
+                       *d = int_nil;
+               if (m)
+                       *m = int_nil;
+               if (y)
+                       *y = int_nil;
                return;
        }
        year = n / 365;
-       day = (n - year * 365) - LEAPYEARS(year >= 0 ? year - 1 : year);
+       day = (n - year * 365) - leapyears(year >= 0 ? year - 1 : year);
        if (n < 0) {
                year--;
                while (day >= 0) {
@@ -353,32 +346,40 @@ fromdate(int n, int *d, int *m, int *y)
                        day += YEARDAYS(year);
                }
        }
-       if ( d == 0 && m == 0) {
-               if( y) *y = (year <= 0) ? year - 1 : year;      /* HACK: hide 
year 0 */
+       if (d == 0 && m == 0) {
+               if (y)
+                       *y = (year <= 0) ? year - 1 : year;     /* HACK: hide 
year 0 */
                return;
        }
 
        day++;
-       if ( leapyear(year)){
-               for (month = day/31==0?1:day/31; month <= 12; month++) 
-               if ( day > CUMLEAPDAYS[month-1] && day <= CUMLEAPDAYS[month]){
-                       if( m) *m = month;
-                       if (d == 0) return;
-                       break;
-               }
-               day -= CUMLEAPDAYS[month-1];
-       } else{
-               for (month = day/31==0?1:day/31; month <= 12; month++) 
-               if ( day > CUMDAYS[month-1] && day <= CUMDAYS[month]){
-                       if( m) *m = month;
-                       if (d == 0) return;
-                       break;
-               }
-               day -= CUMDAYS[month-1];
+       if (leapyear(year)) {
+               for (month = day / 31 == 0 ? 1 : day / 31; month <= 12; month++)
+                       if (day > CUMLEAPDAYS[month - 1] && day <= 
CUMLEAPDAYS[month]) {
+                               if (m)
+                                       *m = month;
+                               if (d == 0)
+                                       return;
+                               break;
+                       }
+               day -= CUMLEAPDAYS[month - 1];
+       } else {
+               for (month = day / 31 == 0 ? 1 : day / 31; month <= 12; month++)
+                       if (day > CUMDAYS[month - 1] && day <= CUMDAYS[month]) {
+                               if (m)
+                                       *m = month;
+                               if (d == 0)
+                                       return;
+                               break;
+                       }
+               day -= CUMDAYS[month - 1];
        }
-       if( d) *d = day;
-       if( m) *m = month;
-       if( y) *y = (year <= 0) ? year - 1 : year;      /* HACK: hide year 0 */
+       if (d)
+               *d = day;
+       if (m)
+               *m = month;
+       if (y)
+               *y = (year <= 0) ? year - 1 : year;     /* HACK: hide year 0 */
 }
 
 static daytime
@@ -408,7 +409,7 @@ fromtime(int n, int *hour, int *min, int
 
 /* matches regardless of case and extra spaces */
 static int
-fleximatch(str s, str pat, int min)
+fleximatch(const char *s, const char *pat, int min)
 {
        int hit, spacy = 0;
 
@@ -430,7 +431,7 @@ fleximatch(str s, str pat, int min)
 }
 
 static int
-parse_substr(int *ret, str s, int min, str list[], int size)
+parse_substr(int *ret, const char *s, int min, const char *list[], int size)
 {
        int j = 0, i = 0;
 
@@ -453,10 +454,16 @@ date_dayofweek(date v)
        return (v % 7 + 12) % 7 + 1;
 }
 
-#define SKIP_DAYS(d,w,i) d += i; w = (w + i)%7; if (w <= 0) w += 7;
+#define SKIP_DAYS(d, w, i)                                             \
+       do {                                                                    
        \
+               d += i;                                                         
        \
+               w = (w + i) % 7;                                                
\
+               if (w <= 0)                                                     
        \
+                       w += 7;                                                 
        \
+       } while (0)
 
 static date
-compute_rule(rule *val, int y)
+compute_rule(const rule *val, int y)
 {
        int m = val->s.month, cnt = ABS(val->s.day - DAY_ZERO);
        date d = todate(1, m, y);
@@ -495,10 +502,10 @@ compute_rule(rule *val, int y)
        return d;
 }
 
-#define BEFORE(d1,m1,d2,m2) (d1 < d2 || (d1 == d2 && m1 <= m2))
+#define BEFORE(d1, m1, d2, m2) ((d1) < (d2) || ((d1) == (d2) && (m1) <= (m2)))
 
 static int
-timestamp_inside(timestamp *ret, timestamp *t, tzone *z, lng offset)
+timestamp_inside(timestamp *ret, timestamp *t, const tzone *z, lng offset)
 {
        /* starts with GMT time t, and returns whether it is in the DST for z */
        lng add = (offset != (lng) 0) ? offset : (get_offset(z)) * (lng) 60000;
@@ -516,7 +523,7 @@ timestamp_inside(timestamp *ret, timesta
        start_msecs = start.s.minutes * 60000;
        end_msecs = end.s.minutes * 60000;
 
-       fromdate((int) ret->days, 0, 0, &year);
+       fromdate(ret->days, NULL, NULL, &year);
        start_days = compute_rule(&start, year);
        end_days = compute_rule(&end, year);
 
@@ -541,7 +548,7 @@ date_fromstr(str buf, int *len, date **d
        if (*len < (int) sizeof(date)) {
                if (*d)
                        GDKfree(*d);
-               *d = (date *) GDKzalloc(*len = sizeof(date));
+               *d = (date *) GDKmalloc(*len = sizeof(date));
        }
        **d = date_nil;
        if (yearneg == 0 && !GDKisdigit(buf[0])) {
@@ -617,13 +624,13 @@ date_tostr(str *buf, int *len, date *val
 {
        int day, month, year;
 
-       fromdate((int) *val, &day, &month, &year);
+       fromdate(*val, &day, &month, &year);
        /* longest possible string: "-5867411-01-01" i.e. 14 chars
           without NUL (see definition of YEAR_MIN/YEAR_MAX above) */
        if (*len < 15) {
                if (*buf)
                        GDKfree(*buf);
-               *buf = (str) GDKzalloc(*len = 15);
+               *buf = (str) GDKmalloc(*len = 15);
        }
        if (*val == date_nil || !DATE(day, month, year)) {
                strcpy(*buf, "nil");
@@ -644,7 +651,7 @@ daytime_fromstr(str buf, int *len, dayti
        if (*len < (int) sizeof(daytime)) {
                if (*ret)
                        GDKfree(*ret);
-               *ret = (daytime *) GDKzalloc(*len = sizeof(daytime));
+               *ret = (daytime *) GDKmalloc(*len = sizeof(daytime));
        }
        **ret = daytime_nil;
        if (!GDKisdigit(buf[pos])) {
@@ -684,7 +691,7 @@ daytime_fromstr(str buf, int *len, dayti
 int
 daytime_tz_fromstr(str buf, int *len, daytime **ret)
 {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to