diff options
author | Vincent Torri <vincent.torri@gmail.com> | 2012-10-26 09:01:52 +0000 |
---|---|---|
committer | Vincent Torri <vincent.torri@gmail.com> | 2012-10-26 09:01:52 +0000 |
commit | 5bdb5d376373dab8bf624388cac520094be95b63 (patch) | |
tree | e494c3a000eeb506e63cd55a77f310767633e0d8 /src/lib/embryo/embryo_time.c | |
parent | 124e0d4afdff0937d8be8014f4dea5f78aa9f76f (diff) |
merge: add embryo
please check and report problems (not cosmetic ones)
someone should update the efl.spec.in file, i don't know that stuff
SVN revision: 78512
Diffstat (limited to 'src/lib/embryo/embryo_time.c')
-rw-r--r-- | src/lib/embryo/embryo_time.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/lib/embryo/embryo_time.c b/src/lib/embryo/embryo_time.c new file mode 100644 index 0000000000..8725377b0c --- /dev/null +++ b/src/lib/embryo/embryo_time.c | |||
@@ -0,0 +1,95 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <sys/time.h> | ||
6 | #include <time.h> | ||
7 | |||
8 | #ifdef _MSC_VER | ||
9 | # include <winsock2.h> | ||
10 | #endif | ||
11 | |||
12 | #ifdef HAVE_EVIL | ||
13 | # include <Evil.h> | ||
14 | #endif | ||
15 | |||
16 | #ifdef HAVE_EXOTIC | ||
17 | # include <Exotic.h> | ||
18 | #endif | ||
19 | |||
20 | #include <Eina.h> | ||
21 | |||
22 | #include "Embryo.h" | ||
23 | #include "embryo_private.h" | ||
24 | |||
25 | /* exported time api */ | ||
26 | |||
27 | static Embryo_Cell | ||
28 | _embryo_time_seconds(Embryo_Program *ep EINA_UNUSED, Embryo_Cell *params EINA_UNUSED) | ||
29 | { | ||
30 | struct timeval timev; | ||
31 | double t; | ||
32 | float f; | ||
33 | |||
34 | gettimeofday(&timev, NULL); | ||
35 | t = (double)(timev.tv_sec - ((timev.tv_sec / (60 * 60 * 24)) * (60 * 60 * 24))) | ||
36 | + (((double)timev.tv_usec) / 1000000); | ||
37 | f = (float)t; | ||
38 | return EMBRYO_FLOAT_TO_CELL(f); | ||
39 | } | ||
40 | |||
41 | static Embryo_Cell | ||
42 | _embryo_time_date(Embryo_Program *ep, Embryo_Cell *params) | ||
43 | { | ||
44 | static time_t last_tzset = 0; | ||
45 | struct timeval timev; | ||
46 | struct tm *tm; | ||
47 | time_t tt; | ||
48 | |||
49 | if (params[0] != (8 * sizeof(Embryo_Cell))) return 0; | ||
50 | gettimeofday(&timev, NULL); | ||
51 | tt = (time_t)(timev.tv_sec); | ||
52 | if ((tt > (last_tzset + 1)) || | ||
53 | (tt < (last_tzset - 1))) | ||
54 | { | ||
55 | last_tzset = tt; | ||
56 | tzset(); | ||
57 | } | ||
58 | tm = localtime(&tt); | ||
59 | if (tm) | ||
60 | { | ||
61 | Embryo_Cell *cptr; | ||
62 | double t; | ||
63 | float f; | ||
64 | |||
65 | cptr = embryo_data_address_get(ep, params[1]); | ||
66 | if (cptr) *cptr = tm->tm_year + 1900; | ||
67 | cptr = embryo_data_address_get(ep, params[2]); | ||
68 | if (cptr) *cptr = tm->tm_mon + 1; | ||
69 | cptr = embryo_data_address_get(ep, params[3]); | ||
70 | if (cptr) *cptr = tm->tm_mday; | ||
71 | cptr = embryo_data_address_get(ep, params[4]); | ||
72 | if (cptr) *cptr = tm->tm_yday; | ||
73 | cptr = embryo_data_address_get(ep, params[5]); | ||
74 | if (cptr) *cptr = (tm->tm_wday + 6) % 7; | ||
75 | cptr = embryo_data_address_get(ep, params[6]); | ||
76 | if (cptr) *cptr = tm->tm_hour; | ||
77 | cptr = embryo_data_address_get(ep, params[7]); | ||
78 | if (cptr) *cptr = tm->tm_min; | ||
79 | cptr = embryo_data_address_get(ep, params[8]); | ||
80 | t = (double)tm->tm_sec + (((double)timev.tv_usec) / 1000000); | ||
81 | f = (float)t; | ||
82 | if (cptr) *cptr = EMBRYO_FLOAT_TO_CELL(f); | ||
83 | |||
84 | } | ||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | /* functions used by the rest of embryo */ | ||
89 | |||
90 | void | ||
91 | _embryo_time_init(Embryo_Program *ep) | ||
92 | { | ||
93 | embryo_program_native_call_add(ep, "seconds", _embryo_time_seconds); | ||
94 | embryo_program_native_call_add(ep, "date", _embryo_time_date); | ||
95 | } | ||