summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-03 16:03:30 +0000
committerSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-03 16:03:30 +0000
commit9903d559f0f7b1bad0946e5791a457ffe33a0df5 (patch)
tree59ec4544c25e841f10fdfb9fb12313ec5ade4408
parent63cf033a92dd903e14cbf59570d1044b87be6d58 (diff)
downloadvdr-plugin-live-9903d559f0f7b1bad0946e5791a457ffe33a0df5.tar.gz
vdr-plugin-live-9903d559f0f7b1bad0946e5791a457ffe33a0df5.tar.bz2
- added function for datetime formatting
-rw-r--r--Makefile19
-rw-r--r--tools.cpp27
-rw-r--r--tools.h13
3 files changed, 50 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 0bef030..823af42 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
#
# Makefile for a Video Disk Recorder plugin
#
-# $Id: Makefile,v 1.8 2007/01/03 15:46:03 lordjaxom Exp $
+# $Id: Makefile,v 1.9 2007/01/03 16:03:30 lordjaxom Exp $
# The official name of this plugin.
# This name will be used in the '-P...' option of VDR to load the plugin.
@@ -54,9 +54,10 @@ SUBDIRS = httpd
### The object files (add further files here):
-OBJS = $(PLUGIN).o thread.o tntconfig.o setup.o i18n.o
+PLUGINOBJS = $(PLUGIN).o thread.o tntconfig.o setup.o i18n.o
-WEBS = styles.o menu.o channels.o schedule.o whats_on_now.o
+WEBOBJS = tools.o
+WEBSITE = styles.o menu.o channels.o schedule.o whats_on_now.o
### Default rules:
@@ -89,7 +90,7 @@ all: libvdr-$(PLUGIN).so libtnt-$(PLUGIN).so
MAKEDEP = $(CXX) -MM -MG
DEPFILE = .dependencies
$(DEPFILE): Makefile
- @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.cpp) > $@
+ @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(PLUGINOBJS:%.o=%.cpp) > $@
-include $(DEPFILE)
@@ -100,15 +101,15 @@ SUBDIRS:
make -C $$dir CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" lib$$dir.a ; \
done
-libvdr-$(PLUGIN).so: $(OBJS) SUBDIRS
- $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) $(LIBS) -o $@
+libvdr-$(PLUGIN).so: $(PLUGINOBJS) SUBDIRS
+ $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(PLUGINOBJS) $(LIBS) -o $@
@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
-libtnt-$(PLUGIN).so: $(WEBS)
+libtnt-$(PLUGIN).so: $(WEBOBJS) $(WEBSITE)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $^
@cp --remove-destination $@ $(LIBDIR)/$@
-dist: clean $(WEBS:%.o=%.cpp)
+dist: clean $(WEBSITE:%.o=%.cpp)
@-rm -rf $(TMPDIR)/$(ARCHIVE)
@mkdir $(TMPDIR)/$(ARCHIVE)
@cp -a * $(TMPDIR)/$(ARCHIVE)
@@ -117,7 +118,7 @@ dist: clean $(WEBS:%.o=%.cpp)
@echo Distribution package created as $(PACKAGE).tgz
clean:
- @-rm -f $(OBJS) $(WEBS) $(WEBS:%.o=%.cpp) $(DEPFILE) *.so *.tgz core* *~
+ @-rm -f $(PLUGINOBJS) $(WEBOBJS) $(WEBSITE) $(WEBDATA:%.o=%.cpp) $(DEPFILE) *.so *.tgz core* *~
@for dir in $(SUBDIRS); do \
make -C $$dir clean ; \
done
diff --git a/tools.cpp b/tools.cpp
new file mode 100644
index 0000000..3eda4b8
--- /dev/null
+++ b/tools.cpp
@@ -0,0 +1,27 @@
+#include <sstream>
+#include <stdexcept>
+#include "tools.h"
+
+namespace vdrlive {
+
+using namespace std;
+
+string FormatDateTime( char const* format, time_t time )
+{
+ struct tm tm_r;
+ if ( localtime_r( &time, &tm_r ) == 0 ) {
+ ostringstream builder;
+ builder << "cannot represent timestamp " << time << " as local time";
+ throw runtime_error( builder.str() );
+ }
+
+ char result[ 256 ];
+ if ( strftime( result, sizeof( result ), format, &tm_r ) == 0 ) {
+ ostringstream builder;
+ builder << "representation of timestamp " << time << " exceeds " << sizeof( result ) << " bytes";
+ throw runtime_error( builder.str() );
+ }
+ return result;
+}
+
+}
diff --git a/tools.h b/tools.h
new file mode 100644
index 0000000..4a01ca8
--- /dev/null
+++ b/tools.h
@@ -0,0 +1,13 @@
+#ifndef VDR_LIVE_TOOLS_H
+#define VDR_LIVE_TOOLS_H
+
+#include <ctime>
+#include <string>
+
+namespace vdrlive {
+
+std::string FormatDateTime( char const* format, time_t time );
+
+} // namespace vdrlive
+
+#endif // VDR_LIVE_TOOLS_H