#include "bbs.h" #include #include #include extern struct bbs_config conf; char *undefined = "Undefined String"; char **strings; int string_count; void chomp(char *string) { while (strlen(string) && (string[strlen(string)-1] == '\r' || string[strlen(string)-1] == '\n')) { string[strlen(string)-1] = '\0'; } } char *parse_newlines(char *string) { char *newstring = (char *)malloc(strlen(string) + 1); int pos = 0; int i; for (i=0;i= string_count) { return undefined; } return strings[offset]; } void load_strings() { FILE *fptr; char buffer[1024]; if (conf.string_file == NULL) { fprintf(stderr, "Strings file can not be undefined!\n"); exit(-1); } fptr = fopen(conf.string_file, "r"); if (!fptr) { fprintf(stderr, "Unable to open strings file!\n"); exit(-1); } string_count = 0; fgets(buffer, 1024, fptr); while (!feof(fptr)) { chomp(buffer); if (string_count == 0) { strings = (char **)malloc(sizeof(char *)); } else { strings = (char **)realloc(strings, sizeof(char *) * (string_count + 1)); } strings[string_count] = parse_newlines(buffer); string_count++; fgets(buffer, 1024, fptr); } fclose(fptr); }