From 9b88f96c4db65ff93197d0c31437a4c8239a0132 Mon Sep 17 00:00:00 2001 From: Adam Fordsmand Date: Thu, 11 Nov 2021 19:06:05 +0100 Subject: [PATCH] Added BlogWrite Function --- BlogDB.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/BlogDB.c b/BlogDB.c index 5591d54..6a2858c 100755 --- a/BlogDB.c +++ b/BlogDB.c @@ -11,6 +11,7 @@ static MYSQL* conn2maria(); static int AddPost(char title[], int authorId, char datePosted[], char post[], int tags[], size_t tagSize, MYSQL* con); static int EditPost(int postID, char title[], char post[], MYSQL* con); static int AddFilePost(int authorID, char filePath[], MYSQL* con); +static int BlogWrite(MYSQL* con); static int PullPostData(char* strings[6], int postID, MYSQL* con); static int AddTag(char tagTitle[], MYSQL* con); static int DeleteTag(int tagID, MYSQL* con); @@ -217,7 +218,7 @@ int AddFilePost(int authorID, char filePath[], MYSQL* con) // This is done to remove the

tags for (int i = 4; i < BufferLength; ++i) { - if (Buffer[i + 5] == StringEnd[0]) { + if (Buffer[i + 6] == StringEnd[0]) { Buffer[i - 4] = StringEnd[0]; break; } @@ -255,6 +256,29 @@ int AddFilePost(int authorID, char filePath[], MYSQL* con) return postID; } +// Open a temporary file containing the standard template, +// and add the contents as a post +int BlogWrite(MYSQL* con) +{ + FILE *fp; + char* tmpName = tmpnam(NULL); + + //fp = tmpfile(); + + fp = fopen(tmpName, "w+"); + fprintf(fp, "

\n

\n"); + fclose(fp); + + char* command; + if(0 > asprintf(&command, "$EDITOR %s", tmpName)) exit(1); + system(command); + AddFilePost(1, tmpName, con); + + remove(tmpName); + + return 1; +} + // Pulls a single post's data into the supplied array int PullPostData(char* strings[6], int postID, MYSQL* con) { @@ -933,6 +957,7 @@ int main(int argc, char *argv[]) //TogglePost(81, con); //printf("%s\n", IsEnabled(81, con) ? "True" : "False"); //AddFilePost(1, "/home/adam/Documents/html/linuxenv.html", con); + BlogWrite(con); // ================================= -- 2.30.2