#include #include #include #include #include char *parse_string(char *in, char *name); struct { char server[50]; char port[10]; char nick[20]; char channel[30]; char quitmsg[1024]; } info; int main(int argc, char *argv[]) { FILE *file = 0; char *buffer = malloc(1024), *locbuff = malloc(1024); int size = 0; if (argc < 2) { fprintf(stderr, "usage: %s [config_filename]\n", argv[0]); exit(1); } if ((file = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], argv[1], strerror(errno)); exit(1); } while(getline(&buffer, &size, file) && !feof(file)) { #ifdef DEBUG printf("in buffer: \033[1m%s\033[0m", buffer); #endif if ((locbuff = parse_string(buffer, "server")) != 0) { strcpy(info.server, locbuff); continue; } if ((locbuff = parse_string(buffer, "port")) != 0) { strcpy(info.port, locbuff); continue; } if ((locbuff = parse_string(buffer, "nick")) != 0) { strcpy(info.nick, locbuff); continue; } if ((locbuff = parse_string(buffer, "channel")) != 0) { strcpy(info.channel, locbuff); continue; } if ((locbuff = parse_string(buffer, "quitmsg")) != 0) { strcpy(info.quitmsg, locbuff); continue; } } fclose(file); printf("%s@%s:%s - %s (%s)\n", info.nick, info.server, info.port, info.channel, info.quitmsg); return 0; } char *parse_string(char *in, char *name) { int i, j = 0; char *str = malloc(1024); while (1) if (in[j] == ' ' || in[j] == '\t') j++; else break; if (in[j] == '#') return 0; in += j; for (i=0; i