Compare commits

...

7 Commits

2 changed files with 126 additions and 0 deletions

View File

126
focussg.c Normal file
View File

@ -0,0 +1,126 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include "BlogDB.h"
static int ArgNewPost();
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 ArgNewPost()
{
BlogWrite(NULL);
}
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(" -n, --new Open up $EDITOR and add saved post to database\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);
}
int VersionMessage()
{
printf("Pre-Release\n");
exit(0);
}
int ShortArg(char currentArg[], int argIndex, char *argv[])
{
char* options;
options = &currentArg[1];
int count = strlen(options);
if (count == 0) { HelpMessage(); exit(0); }
for (int i = 0; i < count; ++i) {
switch (options[i]) {
case 'n':
ArgNewPost();
break;
case 'h':
HelpMessage();
break;
case 'V':
VersionMessage();
break;
case 0: // Missing character, should never happen
exit(1);
break;
default:
HelpMessage();
break;
}
}
}
int LongArg(char currentArg[], int argIndex, char *argv[])
{
char* option;
option = &currentArg[2];
if (strcmp(option, "help") == 0)
HelpMessage();
else if (strcmp(option, "new") == 0)
ArgNewPost();
else if (strcmp(option, "add-author") == 0)
ArgAddAuthor();
else if (strcmp(option, "version") == 0)
VersionMessage();
else if (strcmp(option, "") == 0)
HelpMessage();
else
HelpMessage();
}
int main(int argc, char *argv[])
{
if (argc == 1) HelpMessage();
for (int i = 1; i < argc; ++i)
{
if (argv[i][0] != '-')
HelpMessage();
else if (argv[i][1] != '-')
ShortArg(argv[i], i, argv);
else
LongArg(argv[i], i, argv);
}
return 0;
}