Implement actual arg parsing
This commit is contained in:
parent
dd9a450042
commit
db0b922e11
60
calathea.c
60
calathea.c
|
@ -5,6 +5,7 @@
|
|||
#include <dirent.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include <argp.h>
|
||||
#include <cmark.h>
|
||||
|
||||
// Structure defining the content and metadata of a single page
|
||||
|
@ -217,40 +218,43 @@ char * substitute_string(char dest[], char sub[], char *start, char *end) {
|
|||
return compiled;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char pagesLocation[256] = "./pages";
|
||||
int initialInboundCapacity = 2;
|
||||
char templateFileName[256] = "./template.html";
|
||||
char outputDirectoryName[256] = "./build";
|
||||
static struct argp_option options[] = {
|
||||
{ "src", 's', "dir", 0, "Source directory of pages", 0 },
|
||||
{ "template", 't', "file", 0, "Template file path", 0 },
|
||||
{ "output", 'o', "dir", 0, "Output directory", 0 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
/*** Argument Parsing ***/
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--pages") == 0) {
|
||||
// We only want to do this if a directory was actually supplied
|
||||
if (i + 1 < argc) {
|
||||
i++;
|
||||
strcpy(pagesLocation, argv[i]);
|
||||
static char *pagesLocation = "./pages";
|
||||
static char *templateFileName = "./template.html";
|
||||
static char *outputDirectoryName = "./build";
|
||||
|
||||
static int parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
switch (key) {
|
||||
case 's': {
|
||||
pagesLocation = arg;
|
||||
break;
|
||||
}
|
||||
} else if (strcmp(argv[i], "--template") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
i++;
|
||||
strcpy(templateFileName, argv[i]);
|
||||
case 't': {
|
||||
templateFileName = arg;
|
||||
break;
|
||||
}
|
||||
} else if (strcmp(argv[i], "--output-dir") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
i++;
|
||||
strcpy(outputDirectoryName, argv[i]);
|
||||
}
|
||||
} else if (strcmp(argv[i], "--incoming-cap") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
i++;
|
||||
initialInboundCapacity = atoi(argv[i]);
|
||||
}
|
||||
} else {
|
||||
printf("Unknown argument: %s\n", argv[i]);
|
||||
case 'o': {
|
||||
outputDirectoryName = arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int initialInboundCapacity = 2;
|
||||
|
||||
struct argp argp = {options, parse_opt, 0, 0 };
|
||||
|
||||
argp_parse(&argp, argc, argv, 0, 0, 0);
|
||||
|
||||
char *templateContent = read_file(templateFileName);
|
||||
|
||||
if (templateContent == NULL) {
|
||||
|
|
Loading…
Reference in New Issue