hibot/source/main.c

65 lines
930 B
C
Raw Normal View History

2023-12-15 17:45:27 -05:00
#define PROGRAM_NAME "hibot"
2023-12-15 18:23:46 -05:00
#define _GNU_SOURCE
2023-12-15 17:45:27 -05:00
#include "config.inc"
char * channel;
char * server;
char * port;
2023-12-16 20:38:41 -05:00
typedef enum {
C,
ADA,
} language_t;
2023-12-16 20:51:49 -05:00
language_t language = DEFAULT_LANGUAGE;
2023-12-16 20:38:41 -05:00
typedef void (*syntax_setter_t)(void);
2023-12-15 17:45:27 -05:00
#include "log.h"
2023-12-15 18:27:56 -05:00
#include "syntax.h"
2023-12-15 17:45:27 -05:00
#include "bot.h"
2023-12-16 20:38:41 -05:00
syntax_setter_t syntax_functions[] = {
[C] = &syntax_c,
[ADA] = &syntax_ada,
};
2023-12-15 17:45:27 -05:00
const char help_message[] =
2023-12-17 14:44:35 -05:00
PROGRAM_NAME " <server>:<port> <channel>"
2023-12-15 17:45:27 -05:00
;
signed main(int argc, char * * argv) {
if (argc != 3) {
goto USAGE_ERROR;
}
channel = argv[2];
server = strdup(argv[1]);
port = strchr(server, ':');
if (port) {
*port = '\0';
} else {
goto USAGE_ERROR;
}
++port;
int port_i = 0;
if(!sscanf(port, "%hd", &port_i)) {
goto USAGE_ERROR;
}
2023-12-16 20:51:49 -05:00
log_file = LOG_FILE;
2023-12-15 17:45:27 -05:00
2023-12-16 20:38:41 -05:00
syntax_functions[language]();
2023-12-15 18:27:56 -05:00
2023-12-15 18:23:46 -05:00
connect_bot(server, port_i);
2023-12-15 17:45:27 -05:00
connection_loop();
return 0;
USAGE_ERROR:
puts(help_message);
return 1;
}