fix: config, major bugs remaining (optarg is NULL)
This commit is contained in:
parent
b9c9b21612
commit
9d3798503d
4 changed files with 37 additions and 18 deletions
|
|
@ -3,7 +3,7 @@ CFLAGS = -std=c99 -Werror -Wall -Wextra -Wvla -pedantic
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
LDLIBS =
|
LDLIBS =
|
||||||
|
|
||||||
LDFLAGS_DBG = -g
|
CFLAGS_DBG = -g
|
||||||
ASAN_DBG_FLAGS = -fsanitize=address
|
ASAN_DBG_FLAGS = -fsanitize=address
|
||||||
|
|
||||||
UTILS_SRCS = src/utils/string/string.c
|
UTILS_SRCS = src/utils/string/string.c
|
||||||
|
|
@ -22,8 +22,14 @@ $(TARGET): $(OBJS)
|
||||||
check:
|
check:
|
||||||
dash tests/run.sh
|
dash tests/run.sh
|
||||||
|
|
||||||
debug: LDFLAGS += LDFLAGS_DBG
|
debug: CFLAGS += $(CFLAGS_DBG)
|
||||||
debug:
|
debug: $(OBJS)
|
||||||
|
$(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
|
|
||||||
|
asan: CFLAGS += $(CFLAGS_DBG)
|
||||||
|
asan: LDFLAGS += $(ASAN_DBG_FLAGS)
|
||||||
|
asan: $(OBJS)
|
||||||
$(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) $(LDLIBS)
|
$(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
||||||
BIN
httpd/httpd
Executable file
BIN
httpd/httpd
Executable file
Binary file not shown.
|
|
@ -28,10 +28,25 @@
|
||||||
|
|
||||||
static void print_help(char *program_name)
|
static void print_help(char *program_name)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [OPTION]\n", program_name);
|
printf("Usage: %s [OPTIONS]..\n", program_name);
|
||||||
puts("");
|
puts("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Just to reduce the number of lines inside handle_opt to not
|
||||||
|
static int parse_daemon_arg(struct config *cfg)
|
||||||
|
{
|
||||||
|
if (strcmp(optarg, "start") == 0)
|
||||||
|
cfg->daemon = START;
|
||||||
|
else if (strcmp(optarg, "stop") == 0)
|
||||||
|
cfg->daemon = STOP;
|
||||||
|
else if (strcmp(optarg, "restart") == 0)
|
||||||
|
cfg->daemon = RESTART;
|
||||||
|
else
|
||||||
|
return ARG_INVALID;
|
||||||
|
|
||||||
|
return ARG_VALID;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns 0 if argument is valid, otherwise
|
// Returns 0 if argument is valid, otherwise
|
||||||
static int handle_opt(char **argv, char opt, struct config *cfg)
|
static int handle_opt(char **argv, char opt, struct config *cfg)
|
||||||
{
|
{
|
||||||
|
|
@ -52,15 +67,7 @@ static int handle_opt(char **argv, char opt, struct config *cfg)
|
||||||
{
|
{
|
||||||
// Daemon
|
// Daemon
|
||||||
case 'd':
|
case 'd':
|
||||||
if (strcmp(optarg, "start") == 0)
|
return parse_daemon_arg(cfg);
|
||||||
cfg->daemon = START;
|
|
||||||
else if (strcmp(optarg, "stop") == 0)
|
|
||||||
cfg->daemon = STOP;
|
|
||||||
else if (strcmp(optarg, "restart") == 0)
|
|
||||||
cfg->daemon = RESTART;
|
|
||||||
else
|
|
||||||
return ARG_INVALID;
|
|
||||||
return ARG_VALID;
|
|
||||||
|
|
||||||
// Server name
|
// Server name
|
||||||
case 's':
|
case 's':
|
||||||
|
|
@ -143,16 +150,18 @@ struct config *parse_configuration(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
char opt;
|
char opt;
|
||||||
int optindex;
|
// int optindex;
|
||||||
while ((opt = getopt_long(argc, argv, "*", options, &optindex)) != -1)
|
while ((opt = getopt_long(argc, argv, "dhspirl:", options, NULL)) != -1)
|
||||||
{
|
{
|
||||||
int err = handle_opt(argv, opt, config);
|
int err = handle_opt(argv, opt, config);
|
||||||
if (err != ARG_VALID)
|
if (err != ARG_VALID)
|
||||||
{
|
{
|
||||||
if (err == ARG_INVALID)
|
if (err == ARG_INVALID)
|
||||||
printf("%s: Invalid argument '%s'", argv[0], argv[optindex]);
|
// printf("%s: Invalid argument '%s'\n", argv[0],
|
||||||
|
// argv[optindex]);
|
||||||
|
printf("%s: Invalid argument\n", argv[0]);
|
||||||
if (err == ARG_NOT_IMPLEMENTED)
|
if (err == ARG_NOT_IMPLEMENTED)
|
||||||
printf("%s: This function is not implemented", argv[0]);
|
printf("%s: This function is not implemented\n", argv[0]);
|
||||||
|
|
||||||
free(config->servers);
|
free(config->servers);
|
||||||
free(config);
|
free(config);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
int main(void)
|
#include "config/config.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
// struct config *config = parse_configuration(argc, argv);
|
||||||
|
parse_configuration(argc, argv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue