From 8f5db62a493e77afb839cfd6ad6d97daed267f16 Mon Sep 17 00:00:00 2001 From: Emil Date: Thu, 3 Aug 2023 03:29:11 -0600 Subject: [PATCH] breaking more things --- creds.txt | 4 ++++ include/parse.h | 2 +- src/main.c | 6 +++++- src/parse.c | 16 +++++++++------- 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 creds.txt diff --git a/creds.txt b/creds.txt new file mode 100644 index 0000000..1b2cf97 --- /dev/null +++ b/creds.txt @@ -0,0 +1,4 @@ +username=probotic +server=irc.rizon.net +port=6667 +channel=#/g/chad diff --git a/include/parse.h b/include/parse.h index d3ac359..dd7310b 100644 --- a/include/parse.h +++ b/include/parse.h @@ -12,7 +12,7 @@ typedef struct extern creds_t creds; DECL char * slurp(const char * fn); -DECL int parse_pair(char * const buf, size_t const len); +DECL int parse_pair(char const * buf, size_t const len); DECL void parse_command(char * cmd); DECL void clean_creds(void); diff --git a/src/main.c b/src/main.c index a71722a..96a15be 100644 --- a/src/main.c +++ b/src/main.c @@ -84,9 +84,13 @@ main (int argc, { creds.password = argv[1]; } else if (strcmp(arg, "auth") == 0) { + authfile = argv[1]; buf = slurp(authfile); if (!buf) - { PERROR(1); } + { + fprintf(stderr, "file: %s\n", authfile); + PERROR(1); + } authfile = argv[1]; if (parse_pair(buf, strlen(buf))) diff --git a/src/parse.c b/src/parse.c index 6ffa133..87eab76 100644 --- a/src/parse.c +++ b/src/parse.c @@ -115,8 +115,11 @@ parse_pair(char const * buf, size_t const len) /* X macro for handling this data may be better */ for (f = 0; f < ARRAY_SIZE(cred_names[i]); ++i) { + fprintf(stderr, "ARRAY_SIZE(cred_names[i]) = %d\n", + ARRAY_SIZE(cred_names[i])); if (strncmp(buf, cred_names[i], ARRAY_SIZE(cred_names[i])) == 0) { + buf += i; x = i; while (i != '\0' || i != '\n') @@ -124,15 +127,14 @@ parse_pair(char const * buf, size_t const len) x = i - x; switch (i) { - case USERNAME: creds.username = strndup(buf+x); break; - case PASSWORD: creds.password = strndup(buf+x); break; - case CHANNEL: creds.channel = strndup(buf+x); break; - case SERVER: creds.server = strndup(buf+x); break; - case PORT: creds.port = atoi(buf+x); break; + case USERNAME: creds.username = strndup(buf,x); break; + case PASSWORD: creds.password = strndup(buf,x); break; + case CHANNEL: creds.channel = strndup(buf,x); break; + case SERVER: creds.server = strndup(buf,x); break; + case PORT: creds.port = atoi(buf); break; } while (i != '\0' || - i != '\n') - buf[i] = '\0'; + i != '\n'); } #ifndef NDEBUG else