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