summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2018-10-29 14:03:56 +1030
committerdaniel-Jones <daniel@danieljon.es>2018-10-29 14:03:56 +1030
commit5ced1e3c67a80e55947d68489ace603eb970b82e (patch)
tree545b1d92e302d2be66660356931b2fc5d41510ae
parentec3a10a44d7a40d7f80277ad65daaf1515c8c751 (diff)
downloadwebsitegen-master.tar.gz
websitegen-master.zip
some more work, created a settings struct and began a function to get all values we needHEADmaster
-rw-r--r--main.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/main.c b/main.c
index c1f1718..a9e47ce 100644
--- a/main.c
+++ b/main.c
@@ -18,16 +18,44 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include "util.h"
#include "replace.h"
#include "cfg.h"
+struct
+settings
+{
+ /*
+ * the values here are retrieved from the config file
+ * the default sizes are sane for my purposes
+ */
+
+ /* index */
+ char indextitle[30]; /* title of the index */
+ char indexsrc[30]; /* index source file */
+
+ /* blog */
+ char blogtitle[30]; /* title of blog pages */
+ char blogheader[256]; /* header for each blog page */
+ char blogindir[30]; /* directory under ./input/ that contains the blog posts */
+ char blogoutdir[30]; /* directory under ./output/ that will hold final blog pages */
+ int blogpostsperpage; /* number of blog posts per page */
+};
+
+/* definitions */
+void
+retrievevalues(struct cfgfile *cfg, struct settings *info);
+
+int
+main(void);
int
main(void)
{
+ /* setup the cfg parser */
struct cfgfile *cfg = malloc(sizeof(struct cfgfile));
if (!cfgsetup(cfg, "settings.cfg"))
{
@@ -35,20 +63,21 @@ main(void)
cfgfree(cfg);
exit(1);
}
- char test[256];
- cfggetvalue(cfg, "blogtitle", test, sizeof(test));
- puts(test);
- char val[3];
- cfggetvalue(cfg, "postsperpage", val, sizeof(val));
- printf("%d\n", atoi(val)*2);
- cfgfree(cfg);
- char *content = readfilecontent("templates/template.txt");
- if (!content)
- perror("unable to read file");
- char *replaced = replaceinmemory(content, "{CONTENT}", "test");
- puts(replaced);
- free(content);
- free(replaced);
+ /* create settings struct and fill it */
+ struct settings info = {0};
+ retrievevalues(cfg, &info);
+ puts(info.indexsrc);
+ cfgfree(cfg);
return 0;
}
+
+void
+retrievevalues(struct cfgfile *cfg, struct settings *info)
+{
+ /* index */
+ cfggetvalue(cfg, "indextitle", info->indextitle, sizeof(info->indextitle));
+ cfggetvalue(cfg, "indexsrc", info->indexsrc, sizeof(info->indexsrc));
+
+ /* blog */
+}