summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2019-12-28 01:56:15 +1030
committerDaniel Jones <admin@danieljon.es>2019-12-28 01:56:15 +1030
commit93a4e3f741a8e37967915fd8b51f651992662d76 (patch)
treedd4f735b0f7c8a85d591de6f6b2998b121f2f18d
parent39b4a8695a0e357e3f4a65e290cf3a3c1ca39b82 (diff)
downloadwebsitegenerator-93a4e3f741a8e37967915fd8b51f651992662d76.tar.gz
websitegenerator-93a4e3f741a8e37967915fd8b51f651992662d76.zip
implement gettime()
-rw-r--r--pages.c18
-rw-r--r--pages.h3
2 files changed, 14 insertions, 7 deletions
diff --git a/pages.c b/pages.c
index b6c396a..d9e2e8f 100644
--- a/pages.c
+++ b/pages.c
@@ -307,6 +307,7 @@ replaceinpage(const char *outfile, const char *toreplace, struct fileorstring *s
* replace 'toreplace' in file 'outfile' taking 'infile' as input
* return 1 on success, 0 on failure
*/
+
long substrpos = -1;
substrpos = findstring(frontpage_index_output, toreplace);
@@ -329,9 +330,16 @@ replaceinpage(const char *outfile, const char *toreplace, struct fileorstring *s
}
char
-*gettime()
+*gettime(char *buffer, size_t size)
{
- return "10/10/2019";
+ /*
+ * put the current date into a buffer and return it
+ */
+
+ time_t t = time(NULL);
+ struct tm tm = *localtime(&t);
+ snprintf(buffer, size, "%d/%d/%d", tm.tm_mday, tm.tm_mon+1, tm.tm_year + 1900);
+ return buffer;
}
int
@@ -357,10 +365,11 @@ frontpage(int flags)
return 0;
}
+ char date[255];
struct fileorstring index = {frontpage_index, NULL};
struct fileorstring title = {NULL, frontpage_title};
struct fileorstring info = {NULL, frontpage_info};
- struct fileorstring time = {NULL, gettime()};
+ struct fileorstring time = {NULL, gettime(date, 255)};
if (!replaceinpage(frontpage_index_output, content_string, &index) ||
!replaceinpage(frontpage_index_output, title_string, &title) ||
!replaceinpage(frontpage_index_output, info_string, &info) ||
@@ -369,9 +378,6 @@ frontpage(int flags)
fprintf(stderr, "unable to generate frontpage\n");
return 0;
}
- //remove("title.tmp");
- //remove("date.tmp");
- //remove("info.tmp");
return 1;
}
diff --git a/pages.h b/pages.h
index 3c34d98..5beb835 100644
--- a/pages.h
+++ b/pages.h
@@ -20,6 +20,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <time.h>
struct fileorstring
{
@@ -33,7 +34,7 @@ long findstring(const char *file, const char *str);
int deletebytes(const char *file, long offset, size_t bytes);
int writeatbyte(const char *dest, struct fileorstring *source, long offset);
int replaceinpage(const char *outfile, const char *toreplace, struct fileorstring *source);
-char *gettime();
+char *gettime(char *buffer, size_t size);
int createtmpfile(const char *name, const char *content, size_t size);
/* generators (to be put into the pages array) */