commit 3f14090d694f40dea28c9b984ad98800ee713230
parent a670ce3cb1ef98f9f3ea4fe92433d6477bbf3e08
Author: hhvn <dev@hhvn.uk>
Date: Fri, 12 Nov 2021 15:30:42 +0000
config.c hirc.h main.c: configuration/macro file
Diffstat:
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/config.c b/config.c
@@ -1,6 +1,7 @@
#include <ncurses.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#include "hirc.h"
char *valname[] = {
@@ -289,6 +290,21 @@ config_set(char *name, char *val) {
free(str);
}
+void
+config_read(char *filename) {
+ char buf[8192];
+ FILE *file;
+
+ if ((file = fopen(filename, "rb")) == NULL) {
+ ui_error("cannot open file '%s': %s", filename, strerror(errno));
+ return;
+ }
+
+ while (read_line(fileno(file), buf, sizeof(buf)))
+ if (*buf == '/')
+ command_eval(buf);
+}
+
int
config_colour_self(long num) {
if (num >= 0 && num <= 99)
diff --git a/hirc.h b/hirc.h
@@ -140,6 +140,7 @@ void config_set(char *name, char *str);
void config_setl(char *name, long num);
void config_sets(char *name, char *str);
void config_setr(char *name, long a, long b);
+void config_read(char *filename);
int config_colour_self(long num);
int config_colour_range(long a, long b);
int config_nicklist_location(long num);
diff --git a/main.c b/main.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <libgen.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
@@ -202,13 +203,18 @@ sighandler(int signal) {
}
int
-main(int argc, char **argv) {
+main(int argc, char *argv[]) {
struct Selected oldselected;
struct Server *sp;
FILE *file;
int i, refreshed, inputrefreshed;
long pinginact, reconnectinterval, maxreconnectinterval;
+ if (argc > 2) {
+ fprintf(stderr, "usage: %s [configfile]", dirname(argv[0]));
+ return EXIT_FAILURE;
+ }
+
main_buf = emalloc(sizeof(struct HistInfo));
main_buf->activity = Activity_ignore;
main_buf->unread = 0;
@@ -218,6 +224,9 @@ main(int argc, char **argv) {
ui_init();
+ if (argc == 2)
+ config_read(argv[1]);
+
for (;;) {
if (serv_poll(&servers, 5) < 0) {
perror("serv_poll()");