From c9aeb10f33c1bfcfefb6bfe85f99bab2e89a08fc Mon Sep 17 00:00:00 2001 From: Adam Fordsmand Date: Wed, 28 Sep 2022 23:00:45 +0200 Subject: [PATCH] Implemented the add-author argument --- focussg.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/focussg.c b/focussg.c index ee2499c..bee781d 100644 --- a/focussg.c +++ b/focussg.c @@ -5,19 +5,44 @@ #include #include "BlogDB.h" +static int ArgAddAuthor(); static int HelpMessage(); static int VersionMessage(); static int ShortArg(char currentArg[], int argIndex, char *argv[]); static int LongArg(char currentArg[], int argIndex, char *argv[]); +int ArgAddAuthor() +{ + printf("In order to add a new author provide the following information:\n"); + + // Define buffers + char firstName[255]; + char lastName[255]; + char email[255]; + + printf("First name : "); + scanf("%s", &firstName); + + printf("Last name : "); + scanf("%s", &lastName); + + printf("Email : "); + scanf("%s", &email); + + int userId = AddAuthor(firstName, lastName, email, NULL); + + printf("User %s %s (%s) was created with userid %d\n", firstName, lastName, email, userId); +} + int HelpMessage() { printf("Usage: focussg [OPTION]\n"); printf("FoCuSSG (Fordsmand's C Static Site Generator)\n"); printf("\n"); - printf(" -h, --help Show this help message.\n"); - printf(" -V, --version Show the version number of FoCuSSG.\n"); + printf(" --add-author Add another author to the database\n"); + printf(" -h, --help Show this help message.\n"); + printf(" -V, --version Show the version number of FoCuSSG.\n"); exit(0); } @@ -61,6 +86,8 @@ int LongArg(char currentArg[], int argIndex, char *argv[]) if (strcmp(option, "help") == 0) HelpMessage(); + else if (strcmp(option, "add-author") == 0) + ArgAddAuthor(); else if (strcmp(option, "version") == 0) VersionMessage(); else if (strcmp(option, "") == 0) -- 2.30.2