Compare commits
2 Commits
340046a264
...
bc843ffd4a
Author | SHA1 | Date |
---|---|---|
luca0N! | bc843ffd4a | |
luca0N! | 83ec72e80c |
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2022 luca0N!
|
||||
* Copyright (C) 2022-2023 luca0N!
|
||||
*
|
||||
* This file is part of Static Website Generator (swg).
|
||||
*
|
||||
|
@ -22,66 +22,22 @@
|
|||
#include "ConfigUtils.hxx"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
#include "Common.hxx"
|
||||
|
||||
void parse_config(SwgContext *ctx, std::string const &path) {
|
||||
std::string ctxCfgPath = path;
|
||||
ctxCfgPath += "/swg.cfg";
|
||||
|
||||
FILE *ctxCfgFile = fopen(ctxCfgPath.c_str(), "r");
|
||||
|
||||
if (ctxCfgFile == NULL) {
|
||||
std::cerr << "error: cannot open swg.cfg file, are you sure "
|
||||
<< path << " is a valid SWG directory?" << std::endl;
|
||||
perror(ctxCfgPath.c_str());
|
||||
exit(RETURN_FAILED_INVALID_DIRECTORY);
|
||||
}
|
||||
|
||||
int buflen = 16;
|
||||
char cbuf[buflen];
|
||||
|
||||
// Yes, this looks ugly, but it works for now. Will probably optimize
|
||||
// this in the future :)
|
||||
//
|
||||
// TODO: Optimize config file interpretation
|
||||
|
||||
std::list<std::string> lines = { "" };
|
||||
while (fgets(cbuf, buflen, ctxCfgFile) != NULL) {
|
||||
int eol = -1;
|
||||
for (int c = 0; c < buflen; c++) {
|
||||
if (cbuf[c] == '\0') {
|
||||
break;
|
||||
} else if (cbuf[c] == '\n') {
|
||||
eol = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (eol > -1) {
|
||||
cbuf[eol] = '\0';
|
||||
*(--lines.end()) += cbuf;
|
||||
lines.insert(lines.end(), "");
|
||||
} else
|
||||
*(--lines.end()) += cbuf;
|
||||
}
|
||||
|
||||
fclose(ctxCfgFile);
|
||||
|
||||
std::cout << "Done loading configuration file in memory" << std::endl;
|
||||
|
||||
// Parse configuration file
|
||||
|
||||
enum ConfigNamespace { General, Blogs };
|
||||
ConfigNamespace ns;
|
||||
|
||||
int blogCount = 0;
|
||||
Blog *currentBlog = NULL; // (Blog*) malloc(sizeof(Blog));
|
||||
Blog *currentBlog = NULL;
|
||||
|
||||
// currentBlog->name = "asd";
|
||||
|
||||
for (std::string line : lines) {
|
||||
std::ifstream cfg_stream(path);
|
||||
// Parse configuration file
|
||||
for (std::string line; std::getline(cfg_stream, line);) {
|
||||
// Skip comment lines
|
||||
if (line.c_str()[0] == '#')
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue