summaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authorlordjaxom <lordjaxom>2004-12-19 22:03:02 +0000
committerlordjaxom <lordjaxom>2004-12-19 22:03:02 +0000
commit9aeb43d010d2452890d2c04832f1dfda8d963c4d (patch)
tree4907fb636d40fc14a8f4d53ce33540afab3119cb /common.c
parentac920774dee48c0a85b3c6fc8c6785c1a5dd8f6d (diff)
downloadvdr-plugin-text2skin-9aeb43d010d2452890d2c04832f1dfda8d963c4d.tar.gz
vdr-plugin-text2skin-9aeb43d010d2452890d2c04832f1dfda8d963c4d.tar.bz2
Initial revision
Diffstat (limited to 'common.c')
-rw-r--r--common.c77
1 files changed, 73 insertions, 4 deletions
diff --git a/common.c b/common.c
index cac3fab..e589235 100644
--- a/common.c
+++ b/common.c
@@ -1,5 +1,5 @@
/*
- * $Id: common.c,v 1.5 2004/12/17 19:56:16 lordjaxom Exp $
+ * $Id: common.c,v 1.1 2004/12/19 22:03:09 lordjaxom Exp $
*/
#include "common.h"
@@ -89,7 +89,8 @@ const char *ChannelBouquet(const cChannel *Channel, int Number) {
#endif
}
*/
-cxType TimeType(time_t Time, const std::string &Format) {
+cxType TimeType(time_t Time, const std::string &Format)
+{
static char result[1000];
struct tm tm_r, *tm;
tm = localtime_r(&Time, &tm_r);
@@ -101,10 +102,78 @@ cxType TimeType(time_t Time, const std::string &Format) {
} else
return Time;
}
- return false;
+ return cxType::False;
+}
+
+cxType DurationType(uint Index, const std::string &Format)
+{
+ static char result[1000];
+ if (Index > 0) {
+ if (Format.length() > 0) {
+ const char *ptr = Format.c_str();
+ char *res = result;
+ enum { normal, format } state = normal;
+ while (*ptr && res < result + sizeof(result)) {
+ int n = 0;
+ int f = (Index % FRAMESPERSEC) + 1;
+ int s = (Index / FRAMESPERSEC);
+ int m = s / 60 % 60;
+ int h = s / 3600;
+ s %= 60;
+ 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);
+ break;
+
+ case 'm':
+ n = snprintf(res, sizeof(result) - (res - result), "%d", m + (h * 60));
+ break;
+
+ case 'S':
+ n = snprintf(res, sizeof(result) - (res - result), "%02d", s);
+ break;
+
+ case 'f':
+ n = snprintf(res, sizeof(result) - (res - result), "%d", f);
+ break;
+
+ case '%':
+ n = 1;
+ *res = '%';
+ break;
+ }
+ res += n;
+ state = normal;
+ break;
+ }
+ ++ptr;
+ }
+ return result;
+ } else
+ return (int)Index;
+ }
+ return cxType::False;
}
-bool ParseVar(const char *Text, const char *Name, std::string &Value) {
+bool ParseVar(const char *Text, const char *Name, std::string &Value)
+{
const char *ptr1, *ptr2;
char *str;
bool res = false;