summaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2010-05-04 21:03:19 +0200
committermrwastl <mrwastl@users.sourceforge.net>2010-05-04 21:03:19 +0200
commit8a4168bd0d2e468604755398f18be1fba9046aa0 (patch)
tree56558e0517e3b63483a2813146563eaf0371c666 /common.c
parent75ebec3efc4879fc8bee8a3ecfe71809d9fccefd (diff)
downloadvdr-plugin-graphlcd-8a4168bd0d2e468604755398f18be1fba9046aa0.tar.gz
vdr-plugin-graphlcd-8a4168bd0d2e468604755398f18be1fba9046aa0.tar.bz2
initial git upload, based on graphlcd-0.2.0-pre2
Diffstat (limited to 'common.c')
-rw-r--r--common.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/common.c b/common.c
new file mode 100644
index 0000000..8b03502
--- /dev/null
+++ b/common.c
@@ -0,0 +1,105 @@
+#include <time.h>
+
+#include <glcdskin/type.h>
+
+#include <vdr/plugin.h>
+
+GLCD::cType TimeType(time_t Time, const std::string &Format)
+{
+ static char result[1000];
+ struct tm tm_r, *tm;
+ tm = localtime_r(&Time, &tm_r);
+
+ if (Time > 0)
+ {
+ if (Format.length() > 0)
+ {
+ strftime(result, sizeof(result), Format.c_str(), tm);
+
+ GLCD::cType r = result;
+ return r;
+ } else
+ return Time;
+ }
+ return false;
+}
+
+GLCD::cType DurationType(int Index, const std::string &Format)
+{
+ static char result[1000];
+ if (Index > 0)
+ {
+ if (Format.length() > 0)
+ {
+ uint update = 0;
+ const char *ptr = Format.c_str();
+ char *res = result;
+ enum { normal, format } state = normal;
+ int n = 0;
+ int f = (Index % FRAMESPERSEC) + 1;
+ int s = (Index / FRAMESPERSEC);
+ int m = s / 60 % 60;
+ int h = s / 3600;
+ s %= 60;
+ while (*ptr && res < result + sizeof(result))
+ {
+ switch (state)
+ {
+ case normal:
+ if (*ptr == '%')
+ state = format;
+ else
+ *(res++) = *ptr;
+ break;
+
+ case format:
+ switch (*ptr)
+ {
+ case 'H':
+ n = snprintf(res, sizeof(result) - (res - result), "%02d", h);
+ break;
+
+ case 'k':
+ n = snprintf(res, sizeof(result) - (res - result), "% 2d", h);
+ break;
+
+ case 'M':
+ n = snprintf(res, sizeof(result) - (res - result), "%02d", m);
+ update = 1000*60;
+ break;
+
+ case 'm':
+ n = snprintf(res, sizeof(result) - (res - result), "%d", m + (h * 60));
+ update = 1000*60;
+ break;
+
+ case 'S':
+ n = snprintf(res, sizeof(result) - (res - result), "%02d", s);
+ update = 1000;
+ break;
+
+ case 'f':
+ n = snprintf(res, sizeof(result) - (res - result), "%d", f);
+ update = 1000;
+ break;
+
+ case '%':
+ n = 1;
+ *res = '%';
+ break;
+ }
+ res += n;
+ state = normal;
+ break;
+ }
+ ++ptr;
+ }
+
+ GLCD::cType r = result;
+ r.SetUpdate(update);
+ return r;
+ } else
+ return (int)Index;
+ }
+ return false;
+}