breaking more things

This commit is contained in:
Emil 2023-08-03 03:29:11 -06:00
parent aed06c9dec
commit 8f5db62a49
4 changed files with 19 additions and 9 deletions

4
creds.txt Normal file
View File

@ -0,0 +1,4 @@
username=probotic
server=irc.rizon.net
port=6667
channel=#/g/chad

View File

@ -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);

View File

@ -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)))

View File

@ -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