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