aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_utilities.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 21:30:40 +1000
committerDavid Walter Seikel2012-01-04 21:30:40 +1000
commitae7ee5b32b8adf8970aa398bbe0d0318b10225d4 (patch)
tree9419a232788e81901a587c4a728bec2670528d93 /LuaSL/src/LuaSL_utilities.c
parentAdded a basic .gitignore file. (diff)
downloadSledjHamr-ae7ee5b32b8adf8970aa398bbe0d0318b10225d4.zip
SledjHamr-ae7ee5b32b8adf8970aa398bbe0d0318b10225d4.tar.gz
SledjHamr-ae7ee5b32b8adf8970aa398bbe0d0318b10225d4.tar.bz2
SledjHamr-ae7ee5b32b8adf8970aa398bbe0d0318b10225d4.tar.xz
Skeleton of the GUI test harness for the LuaSL script engine.
Diffstat (limited to 'LuaSL/src/LuaSL_utilities.c')
-rw-r--r--LuaSL/src/LuaSL_utilities.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/LuaSL/src/LuaSL_utilities.c b/LuaSL/src/LuaSL_utilities.c
new file mode 100644
index 0000000..1675a92
--- /dev/null
+++ b/LuaSL/src/LuaSL_utilities.c
@@ -0,0 +1,101 @@
1#include "LuaSL.h"
2
3
4// "01:03:52 01-01-1973\n\0"
5# define DATE_TIME_LEN 21
6
7
8char dateTime[DATE_TIME_LEN];
9
10
11static
12void _ggg_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args)
13{
14 FILE *f = data;
15 char dt[DATE_TIME_LEN + 1];
16 char fileTab[256], funcTab[256];
17
18 getDateTime(NULL, dt, NULL);
19 dt[19] = '\0';
20 if (12 > strlen(file))
21 snprintf(fileTab, sizeof(fileTab), "%s\t\t", file);
22 else
23 snprintf(fileTab, sizeof(fileTab), "%s\t", file);
24 snprintf(funcTab, sizeof(funcTab), "\t%s", fnc);
25 fprintf(f, "%s ", dt);
26 if (f == stderr)
27 eina_log_print_cb_stderr(d, level, fileTab, funcTab, line, fmt, data, args);
28 else if (f == stdout)
29 eina_log_print_cb_stdout(d, level, fileTab, funcTab, line, fmt, data, args);
30 fflush(f);
31}
32
33void loggingStartup(gameGlobals *game)
34{
35 game->logDom = eina_log_domain_register("LuaSL", NULL);
36 if (game->logDom < 0)
37 {
38 EINA_LOG_CRIT("could not register log domain 'LuaSL'");
39 }
40 // TODO - should unregister this later.
41 eina_log_level_set(EINA_LOG_LEVEL_DBG);
42 eina_log_domain_level_set("LuaSL", EINA_LOG_LEVEL_DBG);
43// TODO - use a different domain for those things we need to log for legal reasons.
44// Setup a callback that calls both the usual stderr callback AND the file one,
45// but sending ggg domain messages to one file, and legal ones to another.
46// Don't bother sending the ggg ones to the file if we are not embedded, we can see them on the terminal.
47 eina_log_print_cb_set(_ggg_log_print_cb, stderr);
48}
49
50char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut)
51{
52 struct tm *newTime;
53 time_t szClock;
54 char *date = dateTime;
55
56 // Get time in seconds
57 time(&szClock);
58 // Convert time to struct tm form
59 newTime = localtime(&szClock);
60
61 if (nowOut)
62 *nowOut = newTime;
63 if (dateOut)
64 date = dateOut;
65 if (timeOut)
66 *timeOut = szClock;
67
68 // format
69 strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime);
70 return (dateTime);
71}
72
73float timeDiff(struct timeval *now, struct timeval *then)
74{
75 if (0 == gettimeofday(now, 0))
76 {
77 struct timeval thisTime = { 0, 0 };
78 double result = 0.0;
79
80//fprintf(stderr, " %ld . %ld\n", now->tv_sec, now->tv_usec);
81//fprintf(stderr, "minus %ld . %ld\n", then->tv_sec, then->tv_usec);
82
83 thisTime.tv_sec = now->tv_sec;
84 thisTime.tv_usec = now->tv_usec;
85 if (thisTime.tv_usec < then->tv_usec)
86 {
87 thisTime.tv_sec--;
88 thisTime.tv_usec += 1000000;
89 }
90 thisTime.tv_usec -= then->tv_usec;
91 thisTime.tv_sec -= then->tv_sec;
92 result = ((double) thisTime.tv_usec) / ((double) 1000000.0);
93 result += thisTime.tv_sec;
94//fprintf(stderr, "equals %lf\n", result);
95//fflush(stderr);
96 return result;
97 }
98 else
99 return 0.0;
100}
101