clang-format
Fix a bunch of trivial formatting issues by running `clang-format`. Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
parent
991b1c4368
commit
ff966a6b4d
166
src/strings.c
166
src/strings.c
@ -1,83 +1,83 @@
|
|||||||
#include "bbs.h"
|
#include "bbs.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
extern struct bbs_config conf;
|
extern struct bbs_config conf;
|
||||||
|
|
||||||
char *undefined = "Undefined String";
|
char *undefined = "Undefined String";
|
||||||
char **strings;
|
char **strings;
|
||||||
int string_count;
|
int string_count;
|
||||||
|
|
||||||
void chomp(char *string) {
|
void chomp(char *string) {
|
||||||
while (strlen(string) && (string[strlen(string)-1] == '\r' || string[strlen(string)-1] == '\n')) {
|
while (strlen(string) && (string[strlen(string)-1] == '\r' || string[strlen(string)-1] == '\n')) {
|
||||||
string[strlen(string)-1] = '\0';
|
string[strlen(string)-1] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *parse_newlines(char *string) {
|
char *parse_newlines(char *string) {
|
||||||
char *newstring = (char *)malloc(strlen(string) + 1);
|
char *newstring = (char *)malloc(strlen(string) + 1);
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<strlen(string);i++) {
|
for (i=0;i<strlen(string);i++) {
|
||||||
if (string[i] == '\\') {
|
if (string[i] == '\\') {
|
||||||
if (i < strlen(string) - 1) {
|
if (i < strlen(string) - 1) {
|
||||||
i++;
|
i++;
|
||||||
if (string[i] == 'n') {
|
if (string[i] == 'n') {
|
||||||
newstring[pos++] = '\n';
|
newstring[pos++] = '\n';
|
||||||
} else if (string[i] == 'r') {
|
} else if (string[i] == 'r') {
|
||||||
newstring[pos++] = '\r';
|
newstring[pos++] = '\r';
|
||||||
} else if (string[i] == '\\') {
|
} else if (string[i] == '\\') {
|
||||||
newstring[pos++] = '\\';
|
newstring[pos++] = '\\';
|
||||||
} else if (string[i] == 'e') {
|
} else if (string[i] == 'e') {
|
||||||
newstring[pos++] = '\e';
|
newstring[pos++] = '\e';
|
||||||
}
|
}
|
||||||
newstring[pos] = '\0';
|
newstring[pos] = '\0';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newstring[pos++] = string[i];
|
newstring[pos++] = string[i];
|
||||||
newstring[pos] = '\0';
|
newstring[pos] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newstring;
|
return newstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_string(int offset) {
|
char *get_string(int offset) {
|
||||||
if (offset >= string_count) {
|
if (offset >= string_count) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings[offset];
|
return strings[offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_strings() {
|
void load_strings() {
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
if (conf.string_file == NULL) {
|
if (conf.string_file == NULL) {
|
||||||
fprintf(stderr, "Strings file can not be undefined!\n");
|
fprintf(stderr, "Strings file can not be undefined!\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fptr = fopen(conf.string_file, "r");
|
fptr = fopen(conf.string_file, "r");
|
||||||
if (!fptr) {
|
if (!fptr) {
|
||||||
fprintf(stderr, "Unable to open strings file!\n");
|
fprintf(stderr, "Unable to open strings file!\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
string_count = 0;
|
string_count = 0;
|
||||||
|
|
||||||
fgets(buffer, 1024, fptr);
|
fgets(buffer, 1024, fptr);
|
||||||
while (!feof(fptr)) {
|
while (!feof(fptr)) {
|
||||||
chomp(buffer);
|
chomp(buffer);
|
||||||
if (string_count == 0) {
|
if (string_count == 0) {
|
||||||
strings = (char **)malloc(sizeof(char *));
|
strings = (char **)malloc(sizeof(char *));
|
||||||
} else {
|
} else {
|
||||||
strings = (char **)realloc(strings, sizeof(char *) * (string_count + 1));
|
strings = (char **)realloc(strings, sizeof(char *) * (string_count + 1));
|
||||||
}
|
}
|
||||||
strings[string_count] = parse_newlines(buffer);
|
strings[string_count] = parse_newlines(buffer);
|
||||||
string_count++;
|
string_count++;
|
||||||
fgets(buffer, 1024, fptr);
|
fgets(buffer, 1024, fptr);
|
||||||
}
|
}
|
||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user