Improving readability of qresult function.

This commit is contained in:
2017-03-19 17:47:52 -07:00
parent 09a972b4d3
commit ea45b27a6a

View File

@ -5,6 +5,7 @@
#include <sqlite3.h>
#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("<TR>");
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("<TD><a href='/cgi/cts?map=%s'>%s</a></TD>", 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("<TD><a href='/cgi/cts?map=%s'>%s</a></TD>", field, field);
} else if (i == 2 && (*c == 'm' || *c == '\0')) {
print_time(sqlite3_column_text(sp, i));
print_time(field);
} else {
printf("<TD>%s</TD>", sqlite3_column_text(sp, i));
printf("<TD>%s</TD>", field);
}
}
printf("</TR>");
@ -149,3 +156,4 @@ void getquery(const char *qs) {
executequery(qf, qs);
free(qf);
}