about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-05-20 21:42:51 +0200
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-05-20 21:42:51 +0200
commitbee1aa3d3c48cf9600cf0502fb78ac8ca3c9972c (patch)
treea8435498fcd7d6ca91644436536f405a9244fe71
parenta6a280037842ac79655355a9d200aafee00a61ba (diff)
refactor: split definitions from core.h into template.h and entry.h
core.h was originally introduced to prevent double header inclusions,
but thanks to the C preprocessor this isn't necessary at all and we can
just get rid of this header.
-rw-r--r--Makefile5
-rw-r--r--README.md2
-rw-r--r--core.h58
-rw-r--r--doc/man/man1/sternenblog.cgi.11
-rw-r--r--entry.c1
-rw-r--r--entry.h30
-rw-r--r--index.c2
-rw-r--r--index.h3
-rw-r--r--main.c3
-rw-r--r--template.h19
-rw-r--r--templates/simple.c3
11 files changed, 55 insertions, 72 deletions
diff --git a/Makefile b/Makefile
index 97529d6..ea40383 100644
--- a/Makefile
+++ b/Makefile
@@ -5,10 +5,10 @@ ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
 sternenblog.cgi: xml.o entry.o index.o stringutil.o cgiutil.o timeutil.o $(TEMPLATE).o main.o
 	$(CC) $(CFLAGS) -o $@ $^
 
-main.o: main.c core.h timeutil.h config.h
+main.o: main.c timeutil.h config.h
 	$(CC) $(CFLAGS) -c -o main.o $<
 
-$(TEMPLATE).o: $(TEMPLATE).c core.h config.h xml.h cgiutil.h timeutil.h stringutil.h
+$(TEMPLATE).o: $(TEMPLATE).c config.h xml.h cgiutil.h timeutil.h stringutil.h
 	$(CC) $(CFLAGS) -I$(ROOT_DIR) -c -o $@ $<
 
 entry.o: config.h entry.c
@@ -38,7 +38,6 @@ install: assets/favicon.ico assets/sternenblog.css doc sternenblog.cgi
 	$(INSTALL) -Dm644 assets/favicon.ico --target-directory $(PREFIX)$(WEB_PATH)/
 	# man pages
 	$(INSTALL) -Dm644 doc/man/man1/sternenblog.cgi.1 --target-directory $(PREFIX)$(MAN_PATH)/man1/
-	$(INSTALL) -Dm644 doc/man/man3/core.h.3 --target-directory $(PREFIX)$(MAN_PATH)/man3/
 	$(INSTALL) -Dm644 doc/man/man3/config.example.h.3 --target-directory $(PREFIX)$(MAN_PATH)/man3/
 	$(INSTALL) -Dm644 doc/man/man3/template.h.3 --target-directory $(PREFIX)$(MAN_PATH)/man3/
 	$(INSTALL) -Dm644 doc/man/man3/xml.h.3 --target-directory $(PREFIX)$(MAN_PATH)/man3/
diff --git a/README.md b/README.md
index 3cee016..287299f 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ the possible customizations are detailed in the
 ## templating and development
 
 templating is unstable at the moment. for the current state
-you have to refer to `core.h` and `template.h`.
+you have to refer to `entry.h` and `template.h`.
 
 you can generate documentation from all source files using `make doc`
 which requires `doxygen` to be installed.
diff --git a/core.h b/core.h
deleted file mode 100644
index 81804fa..0000000
--- a/core.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*!
- * @file core.h
- * @brief Central type definitions of sternenblog
- */
-
-#ifndef STERNENBLOG_CORE_H
-#define STERNENBLOG_CORE_H
-
-#include <time.h>
-
-/*!
- * @brief Resolved blog entry
- *
- * Represents a resolved entry and should only be
- * constructed using `make_entry()` and populated using
- * `entry_get_text()`.
- *
- * If constructed correctly, you can expect such an entry to exist.
- *
- * Use `free_entry()` to free allocated `char *` in an `entry`
- * constructed by `make_entry()` (and `entry_get_text()`).
- *
- * @see make_entry
- * @see entry_get_text
- * @see free_entry
- * @see make_index
- */
-struct entry {
-    // mandatory: part of each well-formed entry
-    time_t time;       //!< last modification time of the entry
-    char *path;        //!< path (on disk) to the entry
-    char *link;        //!< absolute path on the http server to the entry
-    char *title;       //!< title of the post, currently `PATH_INFO` without the initial slash
-    size_t text_size;  //!< size of text, -1 to indicate it's missing
-    // optional: may be NULL, depending on context
-    char *text;        //!< contents of the entry (mmap-ed file) or `NULL`
-};
-
-/*!
- * @brief Supported response types
- *
- * This enum describes the types of responses sternenblog can generate:
- *
- * * a single entry
- * * an index
- * * an error page
- * * a (atom) feed
- *
- * Used internally for routing and passed to the template for context.
- */
-enum page_type {
-  PAGE_TYPE_ENTRY,
-  PAGE_TYPE_INDEX,
-  PAGE_TYPE_ERROR,
-  PAGE_TYPE_FEED,
-};
-
-#endif
diff --git a/doc/man/man1/sternenblog.cgi.1 b/doc/man/man1/sternenblog.cgi.1
index 5cab28e..242e6e6 100644
--- a/doc/man/man1/sternenblog.cgi.1
+++ b/doc/man/man1/sternenblog.cgi.1
@@ -313,7 +313,6 @@ header.
 .Sh SEE ALSO
 .Xr cgiutil.h 3 ,
 .Xr config.example.h 3 ,
-.Xr core.h 3 ,
 .Xr entry.h 3 ,
 .Xr index.h 3 ,
 .Xr main.c 3 ,
diff --git a/entry.c b/entry.c
index 8bb6476..aac705d 100644
--- a/entry.c
+++ b/entry.c
@@ -10,7 +10,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "core.h"
 #include "config.h" // TODO: make independent?
 #include "cgiutil.h"
 #include "entry.h"
diff --git a/entry.h b/entry.h
index 66e76bb..c0b9a2f 100644
--- a/entry.h
+++ b/entry.h
@@ -6,7 +6,35 @@
 #ifndef STERNENBLOG_ENTRY_H
 #define STERNENBLOG_ENTRY_H
 
-#include "core.h"
+#include <time.h>
+
+/*!
+ * @brief Resolved blog entry
+ *
+ * Represents a resolved entry and should only be
+ * constructed using `make_entry()` and populated using
+ * `entry_get_text()`.
+ *
+ * If constructed correctly, you can expect such an entry to exist.
+ *
+ * Use `free_entry()` to free allocated `char *` in an `entry`
+ * constructed by `make_entry()` (and `entry_get_text()`).
+ *
+ * @see make_entry
+ * @see entry_get_text
+ * @see free_entry
+ * @see make_index
+ */
+struct entry {
+    // mandatory: part of each well-formed entry
+    time_t time;       //!< last modification time of the entry
+    char *path;        //!< path (on disk) to the entry
+    char *link;        //!< absolute path on the http server to the entry
+    char *title;       //!< title of the post, currently `PATH_INFO` without the initial slash
+    size_t text_size;  //!< size of text, -1 to indicate it's missing
+    // optional: may be NULL, depending on context
+    char *text;        //!< contents of the entry (mmap-ed file) or `NULL`
+};
 
 /*!
  * @brief Construct an entry for a given `PATH_INFO`
diff --git a/index.c b/index.c
index bb94bb9..9cf673e 100644
--- a/index.c
+++ b/index.c
@@ -6,8 +6,6 @@
 #include <string.h>
 #include <sys/types.h>
 
-#include "core.h"
-#include "entry.h"
 #include "index.h"
 
 /*!
diff --git a/index.h b/index.h
index ae0a91b..de009d7 100644
--- a/index.h
+++ b/index.h
@@ -6,9 +6,10 @@
 #ifndef STERNENBLOG_INDEX_H
 #define STERNENBLOG_INDEX_H
 
-#include "core.h"
 #include <stdbool.h>
 
+#include "entry.h"
+
 /*!
  * @brief Build index of given `blog_dir`
  *
diff --git a/main.c b/main.c
index 4b01b64..d7a9987 100644
--- a/main.c
+++ b/main.c
@@ -49,7 +49,7 @@
  *
  * @subsection int_doc Internals
  *
- * core.h defines the central type of sternenblog, `struct entry`.
+ * entry.h defines the central type of sternenblog, `struct entry`.
  * Entries is essentially all sternenblog knows and handles.
  * It either builds an index (listing) of them using `make_index()`
  * from index.h or gets a single one using `make_entry()` from entry.h
@@ -86,7 +86,6 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "core.h"
 #include "config.h"
 #include "cgiutil.h"
 #include "entry.h"
diff --git a/template.h b/template.h
index 21ff38b..64ced30 100644
--- a/template.h
+++ b/template.h
@@ -21,7 +21,24 @@
 #ifndef STERNENBLOG_TEMPLATE_H
 #define STERNENBLOG_TEMPLATE_H
 
-#include "core.h"
+/*!
+ * @brief Supported response types
+ *
+ * This enum describes the types of responses sternenblog can generate:
+ *
+ * * a single entry
+ * * an index
+ * * an error page
+ * * a (atom) feed
+ *
+ * Used internally for routing and passed to the template for context.
+ */
+enum page_type {
+  PAGE_TYPE_ENTRY,
+  PAGE_TYPE_INDEX,
+  PAGE_TYPE_ERROR,
+  PAGE_TYPE_FEED,
+};
 
 /*!
  * @brief (Meta) data about the page being served
diff --git a/templates/simple.c b/templates/simple.c
index f1f8bdf..9db3ebc 100644
--- a/templates/simple.c
+++ b/templates/simple.c
@@ -2,8 +2,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
-#include <core.h>
+#include <entry.h>
 #include <template.h>
 #include <config.h>
 #include <cgiutil.h>