diff --git a/includes/dbquery.c b/includes/dbquery.c index e52845b..59e1c6e 100644 --- a/includes/dbquery.c +++ b/includes/dbquery.c @@ -5,6 +5,7 @@ #include #include "colors.h" + static inline char *get_filename(const char *c) { char *qout = "queries/mranks.sql"; if (c != NULL) { @@ -78,21 +79,27 @@ static void print_time(const unsigned char *strcs) { // display and format the results of the query. static void qresult(sqlite3_stmt * const sp, const char *c) { +#define ISPLAYERNAME(x, y) (*x == 'm' && y == 1) || \ + (*x == '\0' && y == 3)|| \ + (*x == 'p' && y == 0) +#define ISMAPNAME(x, y) (*x == '\0' && y == 0) ||\ + (*x == 'p' && y == 1) int e; unsigned int i; - unsigned int cc = sqlite3_column_count(sp); + const unsigned int cc = sqlite3_column_count(sp); print_tblheader(c); while ((e = sqlite3_step(sp)) == SQLITE_ROW) { printf(""); - for (i = 0; i < cc; i++) { - if ((*c == 'm' && i == 1) || (*c == '\0' && i == 3) || (*c == 'p' && i == 0)) { - print_plname(sqlite3_column_text(sp, i)); - } else if ((i == 0 && *c == '\0') || (i == 1 && *c == 'p') ) { - printf("%s", sqlite3_column_text(sp, i), sqlite3_column_text(sp, i)); + for (i = 0; i < cc; ++i) { + unsigned const char * const field = sqlite3_column_text(sp, i); + if (ISPLAYERNAME(c, i)) { + print_plname(field); + } else if (ISMAPNAME(c, i)) { + printf("%s", field, field); } else if (i == 2 && (*c == 'm' || *c == '\0')) { - print_time(sqlite3_column_text(sp, i)); + print_time(field); } else { - printf("%s", sqlite3_column_text(sp, i)); + printf("%s", field); } } printf(""); @@ -149,3 +156,4 @@ void getquery(const char *qs) { executequery(qf, qs); free(qf); } +