aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-09-19 14:46:47 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-09-19 14:46:47 +0200
commit53569c91e4ebdbba96e6286f846dead1d427e6e2 (patch)
tree70d9e65a3e175d034349dbfb17e1044b752a1334
parent3f2a9bc6638dbe09bd8c70fdac068555659e58ac (diff)
downloadcforum-53569c91e4ebdbba96e6286f846dead1d427e6e2.tar.gz
Use single header file
There are drawbacks with this approach, but the benefit -- for a small-ish project -- is that the single header file can serve as a very good overview and guide for people exploring the code for the first time.
-rw-r--r--README14
-rw-r--r--cforum.c7
-rw-r--r--cforum.h97
-rw-r--r--ctl.c5
-rw-r--r--ctl.h7
-rw-r--r--db.c2
-rw-r--r--db.h41
-rw-r--r--err.c1
-rw-r--r--err.h1
-rw-r--r--query.c2
-rw-r--r--query.h17
-rw-r--r--site.h13
12 files changed, 107 insertions, 100 deletions
diff --git a/README b/README
index 93d4c80..9a80f3c 100644
--- a/README
+++ b/README
@@ -8,16 +8,12 @@ C89, it can be run on practically any UNIX system.
It is also rather small:
wc -l *.c *.h */*.t */*.lex
- 101 cforum.c
- 299 ctl.c
+ 96 cforum.c
+ 296 ctl.c
268 db.c
- 10 err.c
+ 11 err.c
144 query.c
- 6 ctl.h
- 40 db.h
- 0 err.h
- 16 query.h
- 12 site.h
+ 96 cforum.h
3 t/err.t
1 t/foot.t
29 t/front.t
@@ -26,4 +22,4 @@ It is also rather small:
28 t/post.t
12 t/user.t
95 mktpl/mktpl.lex
- 1117 total
+ 1132 total
diff --git a/cforum.c b/cforum.c
index 999ae78..a7d5d7d 100644
--- a/cforum.c
+++ b/cforum.c
@@ -3,12 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
-#include "ctl.h" /* Controllers. */
-#include "db.h" /* Database functions. Defines global variable db. */
-#include "err.h" /* HTTP errors. */
-#include "site.h" /* Site settings. Defines global struct site. */
-#include "query.h" /* Query functions. Defines global struct query. */
+#include "cforum.h"
#define MAXMSG 300
diff --git a/cforum.h b/cforum.h
new file mode 100644
index 0000000..13d0d30
--- /dev/null
+++ b/cforum.h
@@ -0,0 +1,97 @@
+#include <sqlite3.h>
+
+/***** Types *****/
+
+enum method{
+ GET,
+ POST
+};
+
+struct att{
+ int id;
+ int post;
+ int bytes; /* Size of data. */
+ char *name;
+ char *desc;
+ char *mime;
+ char *data;
+};
+
+struct post{
+ int id;
+ int parent;
+ int user;
+ int created;
+ int edited;
+ char *subject;
+ char *text;
+};
+
+struct user{
+ int id;
+ int created;
+ char *name;
+ char *full;
+ char *hash;
+};
+
+struct query{
+ int method;
+ int length; /* Content length. */
+ char *string;
+};
+
+struct site{
+ char *name;
+};
+
+/***** Functions *****/
+
+/* ctl.c */
+void newatt(void);
+void newpost(void);
+void newuser(void);
+void showatt(int);
+void showfront(void);
+void showpost(int);
+void showuser(int);
+
+/* db.c */
+int addatt(struct att *);
+int adduser(struct user *);
+struct att *getatt(sqlite3_stmt *);
+struct post *getpost(sqlite3_stmt *);
+struct user *getuser(sqlite3_stmt *);
+struct att *nextatt(sqlite3_stmt *);
+struct post *nextpost(sqlite3_stmt *);
+struct user *nextuser(sqlite3_stmt *);
+sqlite3_stmt *selectbyint(char *, char *, int);
+
+/* err.c */
+void srverr(char *);
+
+/* query.c */
+char *nextparam(enum method, int *, int);
+void setquery(void);
+char *split(char *);
+int urldecode(char *, int);
+
+/***** Definitions *****/
+
+#define TRUNCATED(s) s[-1]
+
+/* Maximum allowed Content-Length for various forms. */
+#define MAXATTDATA 4096
+#define MAXUSERDATA 512
+#define MAXPOSTDATA 4096
+
+/* Maximum size of user information, incl. NUL. */
+#define MAXUSERNAME 40
+#define MAXUSERFULL 128
+#define MAXUSERPASS 128
+
+/***** Variables *****/
+
+sqlite3 *db;
+struct query query;
+struct site site; \ No newline at end of file
diff --git a/ctl.c b/ctl.c
index 91761cc..2bda5a7 100644
--- a/ctl.c
+++ b/ctl.c
@@ -3,10 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include "err.h"
-#include "db.h"
-#include "query.h"
-#include "site.h"
+#include "cforum.h"
/* Print UNIX timestamp as written date. */
void
diff --git a/ctl.h b/ctl.h
deleted file mode 100644
index 95c66af..0000000
--- a/ctl.h
+++ /dev/null
@@ -1,7 +0,0 @@
-void newatt(void);
-void newpost(void);
-void newuser(void);
-void showatt(int);
-void showfront(void);
-void showpost(int);
-void showuser(int); \ No newline at end of file
diff --git a/db.c b/db.c
index a6391a6..0db8d1f 100644
--- a/db.c
+++ b/db.c
@@ -4,7 +4,7 @@
#include <string.h>
#include <sqlite3.h>
#include <time.h>
-#include "db.h"
+#include "cforum.h"
static char * strdupn(const unsigned char *);
diff --git a/db.h b/db.h
deleted file mode 100644
index 1385b98..0000000
--- a/db.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <sqlite3.h>
-
-sqlite3 *db;
-
-struct att{
- int id;
- int post;
- int bytes; /* Size of data. */
- char *name;
- char *desc;
- char *mime;
- char *data;
-};
-
-struct post{
- int id;
- int parent;
- int user;
- int created;
- int edited;
- char *subject;
- char *text;
-};
-
-struct user{
- int id;
- int created;
- char *name;
- char *full;
- char *hash;
-};
-
-int addatt(struct att *);
-int adduser(struct user *);
-struct att *getatt(sqlite3_stmt *);
-struct post *getpost(sqlite3_stmt *);
-struct user *getuser(sqlite3_stmt *);
-struct att *nextatt(sqlite3_stmt *);
-struct post *nextpost(sqlite3_stmt *);
-struct user *nextuser(sqlite3_stmt *);
-sqlite3_stmt *selectbyint(char *, char *, int); \ No newline at end of file
diff --git a/err.c b/err.c
index dd15ebd..07a50a2 100644
--- a/err.c
+++ b/err.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include "cforum.h"
void
srverr(char *err)
diff --git a/err.h b/err.h
deleted file mode 100644
index bf218f5..0000000
--- a/err.h
+++ /dev/null
@@ -1 +0,0 @@
-void srverr(char *); \ No newline at end of file
diff --git a/query.c b/query.c
index 96cfbcb..8f54ead 100644
--- a/query.c
+++ b/query.c
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "query.h"
+#include "cforum.h"
/*
* Return an allocated string containing the next parameter ("key=value").
diff --git a/query.h b/query.h
deleted file mode 100644
index d9c7ac9..0000000
--- a/query.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#define TRUNCATED(s) s[-1]
-
-struct query{
- int method;
- int length; /* Content length. */
- char *string;
-} query;
-
-enum method{
- GET,
- POST
-};
-
-char *nextparam(enum method, int *, int);
-void setquery(void);
-char *split(char *);
-int urldecode(char *, int); \ No newline at end of file
diff --git a/site.h b/site.h
deleted file mode 100644
index 8c70a64..0000000
--- a/site.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* Maximum allowed Content-Length for various forms. */
-#define MAXATTDATA 4096
-#define MAXUSERDATA 512
-#define MAXPOSTDATA 4096
-
-/* Maximum size of user information, incl. NUL. */
-#define MAXUSERNAME 40
-#define MAXUSERFULL 128
-#define MAXUSERPASS 128
-
-struct site{
- char *name;
-} site; \ No newline at end of file