From bf48f5ec87e8dfb62fd9666c2b047ef57ed8ee68 Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 4 Mar 2014 18:32:17 +0100 Subject: mruby-time: remove trailing whitespace --- mrbgems/mruby-time/src/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 2e72c5c53..e0e7cf4ce 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -406,7 +406,7 @@ mrb_time_zone(mrb_state *mrb, mrb_value self) tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time); if (tm->timezone <= MRB_TIMEZONE_NONE) return mrb_nil_value(); if (tm->timezone >= MRB_TIMEZONE_LAST) return mrb_nil_value(); - return mrb_str_new_static(mrb, + return mrb_str_new_static(mrb, timezone_names[tm->timezone].name, timezone_names[tm->timezone].len); } -- cgit v1.2.3 From c0887971078c58a59a62b6460bd639ad261bc491 Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 4 Mar 2014 18:33:17 +0100 Subject: mruby-time: rearrange header order --- mrbgems/mruby-time/src/time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index e0e7cf4ce..499aaa423 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -4,10 +4,9 @@ ** See Copyright Notice in mruby.h */ - -#include "mruby.h" #include #include +#include "mruby.h" #include "mruby/class.h" #include "mruby/data.h" -- cgit v1.2.3 From f9c88e9c68efbd5dde0e3b106a9dc7c3c5a1df36 Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 4 Mar 2014 22:07:47 +0100 Subject: mruby-time: fix two tiny typos in comments --- mrbgems/mruby-time/src/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 499aaa423..55638f638 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -34,7 +34,7 @@ #endif /* timegm(3) */ -/* mktime() creates tm structure for localtime; timegm() is for UTF time */ +/* mktime() creates tm structure for localtime; timegm() is for UTC time */ /* define following macro to use probably faster timegm() on the platform */ /* #define USE_SYSTEM_TIMEGM */ @@ -80,7 +80,7 @@ timegm(struct tm *tm) } #endif -/* Since we are limited to using ISO C89, this implementation is based +/* Since we are limited to using ISO C99, this implementation is based * on time_t. That means the resolution of time is only precise to the * second level. Also, there are only 2 timezones, namely UTC and LOCAL. */ -- cgit v1.2.3 From 333840ba6113dbc3cb6688922083ab8c17cd4c37 Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 4 Mar 2014 18:34:04 +0100 Subject: mruby-time: mrb_time_type should be const --- mrbgems/mruby-time/src/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 55638f638..76e71a17b 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -119,7 +119,7 @@ struct mrb_time { struct tm datetime; }; -static struct mrb_data_type mrb_time_type = { "Time", mrb_free }; +static const struct mrb_data_type mrb_time_type = { "Time", mrb_free }; /** Updates the datetime of a mrb_time based on it's timezone and seconds setting. Returns self on success, NULL of failure. */ -- cgit v1.2.3 From e34b69f58276545187a6e92ba4a089016b99daee Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 4 Mar 2014 21:07:29 +0100 Subject: mruby-time: store strings directly instead of pointers to them --- mrbgems/mruby-time/src/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 76e71a17b..81269c1ce 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -104,11 +104,11 @@ static mrb_timezone_name timezone_names[] = { { NULL, 0 } }; -static const char *mon_names[] = { +static const char mon_names[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", }; -static const char *wday_names[] = { +static const char wday_names[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", }; -- cgit v1.2.3 From 9b3033bb5366c38a03046028b40af04d4e57ddf9 Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 4 Mar 2014 21:08:55 +0100 Subject: mruby-time: timezone_names should be const --- mrbgems/mruby-time/src/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 81269c1ce..55a2e11c6 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -97,7 +97,7 @@ typedef struct mrb_timezone_name { size_t len; } mrb_timezone_name; -static mrb_timezone_name timezone_names[] = { +static const mrb_timezone_name timezone_names[] = { { "none", sizeof("none") - 1 }, { "UTC", sizeof("UTC") - 1 }, { "LOCAL", sizeof("LOCAL") - 1 }, -- cgit v1.2.3 From 96d3bc2811ab593c3a48fb235d5c49260ee3ac67 Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 4 Mar 2014 21:33:09 +0100 Subject: mruby-time: store timezone name directly --- mrbgems/mruby-time/src/time.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 55a2e11c6..88e201742 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -93,15 +93,14 @@ enum mrb_timezone { }; typedef struct mrb_timezone_name { - const char *name; + const char name[8]; size_t len; } mrb_timezone_name; static const mrb_timezone_name timezone_names[] = { { "none", sizeof("none") - 1 }, - { "UTC", sizeof("UTC") - 1 }, + { "UTC", sizeof("UTC") - 1 }, { "LOCAL", sizeof("LOCAL") - 1 }, - { NULL, 0 } }; static const char mon_names[12][4] = { -- cgit v1.2.3 From 69b231ece5fff7fe0c4c97514fc1bdd8150b714a Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 4 Mar 2014 21:40:17 +0100 Subject: mruby-time: fix indentation in mrb_time_asctime --- mrbgems/mruby-time/src/time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 88e201742..9cf7c2fd7 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -422,10 +422,10 @@ mrb_time_asctime(mrb_state *mrb, mrb_value self) tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time); d = &tm->datetime; len = snprintf(buf, sizeof(buf), "%s %s %02d %02d:%02d:%02d %s%d", - wday_names[d->tm_wday], mon_names[d->tm_mon], d->tm_mday, - d->tm_hour, d->tm_min, d->tm_sec, - tm->timezone == MRB_TIMEZONE_UTC ? "UTC " : "", - d->tm_year + 1900); + wday_names[d->tm_wday], mon_names[d->tm_mon], d->tm_mday, + d->tm_hour, d->tm_min, d->tm_sec, + tm->timezone == MRB_TIMEZONE_UTC ? "UTC " : "", + d->tm_year + 1900); return mrb_str_new(mrb, buf, len); } -- cgit v1.2.3