Removed unneeded parameter and enum.

This commit is contained in:
2017-03-10 17:43:05 -08:00
parent a51cefc971
commit 51830a8122

20
main.c
View File

@ -4,37 +4,26 @@
#include <string.h> #include <string.h>
#include <sqlite3.h> #include <sqlite3.h>
typedef enum { inline char *get_filename(const char c) {
MAP,
PLAYER,
OVERVIEW,
NONE
} Querytype;
inline char *get_filename(const char c, Querytype *q) {
char *qout; char *qout;
switch(c) { switch(c) {
default: default:
qout = "queries/mranks.sql"; qout = "queries/mranks.sql";
*q = OVERVIEW;
break; break;
case 'm': case 'm':
qout = "queries/mleaderboard-ojoin.sql"; qout = "queries/mleaderboard-ojoin.sql";
*q = MAP;
break; break;
case 'p': case 'p':
qout = "queries/rplayers.sql"; qout = "queries/rplayers.sql";
*q = PLAYER;
break; break;
case 't': case 't':
qout = "queries/test.txt"; qout = "queries/test.txt";
*q = NONE;
break; break;
} }
return qout; return qout;
} }
bool executequery(const char *sql, const char *p, int tbl) { bool executequery(const char *sql, const char *p) {
sqlite3 *db; sqlite3 *db;
char *error; char *error;
int con = sqlite3_open("db/cts.db", &db); int con = sqlite3_open("db/cts.db", &db);
@ -69,8 +58,7 @@ bool executequery(const char *sql, const char *p, int tbl) {
// containing the data from query files. // containing the data from query files.
void getquery(const char *qs) { void getquery(const char *qs) {
char *qf, *qp; char *qf, *qp;
Querytype qt; char *fname = get_filename(qs[0]);
char *fname = get_filename(qs[0], &qt);
if (fname != NULL) { if (fname != NULL) {
FILE *f = fopen(fname, "r"); FILE *f = fopen(fname, "r");
if (f != NULL && qf != NULL) { if (f != NULL && qf != NULL) {
@ -86,7 +74,7 @@ void getquery(const char *qs) {
} }
qp = strchr(qs, '=') + 1; // increment to exclude '=' qp = strchr(qs, '=') + 1; // increment to exclude '='
printf("%x: \n\n%s\n", qf, qf); printf("%x: \n\n%s\n", qf, qf);
executequery(qf, qp, qt); executequery(qf, qp);
free(qf); free(qf);
} }