[main]: parse config path argument
This commit is contained in:
parent
b252486831
commit
0485a7242d
3 changed files with 55 additions and 52 deletions
61
main.c
61
main.c
|
|
@ -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 */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue