[main]: parse config path argument

This commit is contained in:
Joshua Vega 2026-01-18 14:15:32 -05:00
parent b252486831
commit 0485a7242d
Signed by: jsvcycling
GPG key ID: E3DD60C9AC7DEF79
3 changed files with 55 additions and 52 deletions

View file

@ -1,22 +0,0 @@
/*
* Copyright (C) 2026 Joshua Vega
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
int getConfig(int argc, char** argv, Config* config)
{
/* TODO */
return 0;
}

View file

@ -1,24 +0,0 @@
/*
* Copyright (C) 2026 Joshua Vega
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CONFIG_H
#define CONFIG_H
typedef struct {
} Config;
int getConfig(const int, char**, Config*);
#endif /* CONFIG_H */

61
main.c
View file

@ -13,18 +13,67 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Config globalConfig;
#define ARG_L_CONFIG_PATH "--config"
#define ARG_S_CONFIG_PATH "-c"
#define ARG_LEN_L_CONFIG_PATH 8
#define ARG_LEN_S_CONFIG_PATH 2
char configPath[1024];
size_t configPathLength = 0;
int parseArguments(int, char**);
void printHelp(void);
int main(int argc, char** argv)
{
int result = getConfig(argc, argv, &globalConfig);
if (result != 0) {
return -1;
if (parseArguments(argc, argv) != 0) {
printHelp();
return 0;
}
printf("Hello world!\n");
return 0;
}
int parseArguments(int argc, char** argv)
{
bool expectConfigPath = false;
for (int argIndex = 1; argIndex < argc; argIndex++) {
const char* arg = argv[argIndex];
if (expectConfigPath) {
size_t length = strlen(arg);
if (length > 1024) {
return 1;
}
memcpy(configPath, arg, length);
configPath[length] = '\0';
configPathLength = length + 1;
printf("Loading config %s\n", configPath);
expectConfigPath = false;
continue;
}
if (!expectConfigPath && (strncmp(arg, ARG_L_CONFIG_PATH, ARG_LEN_L_CONFIG_PATH) || strncmp(arg, ARG_S_CONFIG_PATH, ARG_LEN_S_CONFIG_PATH))) {
printf("Encountered config path argument.\n");
expectConfigPath = true;
} else {
return 1;
}
}
return 0;
}
void printHelp(void)
{
/* TODO */
}