Now displays formatted time.

This commit is contained in:
2017-03-12 23:20:57 -07:00
parent 0a9b9a2ef6
commit 32c7286040
2 changed files with 38 additions and 12 deletions

48
main.c
View File

@ -22,11 +22,12 @@ inline char *get_filename(const char *c) {
return qout;
}
inline void print_tblheader(const char *c) {
char *out;
switch (*c) {
inline int print_tblheader(const char *c) {
char *labels;
int idx = -1;
switch (*c) {
default:
out = "<TABLE class='center'>\
labels = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='4'> <H3><BR>Map List</H3> </TH>\
<TR>\
<TH class='columnname'>Name</TH>\
@ -34,18 +35,20 @@ inline void print_tblheader(const char *c) {
<TH class='columnname'>Best Time</TH>\
<TH class='columnname'>Held By</TH>\
</TR>";
idx = 2;
break;
case 'm':
out = "<TABLE class='center'>\
labels = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='3'><H3><BR>Leaderboard</H3></TH>\
<TR>\
<TH class='columnname'>Rank</TH>\
<TH class='columnname'>Name</TH>\
<TH class='columnname'>Time</TH>\
</TR>";
idx = 2;
break;
case 'p':
out = "<TABLE class='center'>\
labels = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='3'> <H3><BR>Ranks</H3> </TH>\
<TR>\
<TH class='columnname'>Name</TH>\
@ -54,19 +57,42 @@ inline void print_tblheader(const char *c) {
</TR>";
break;
}
printf("%s", out);
printf("%s", labels);
return idx;
}
// input is an integer as a string.
// the time is in centiseconds.
// this means the longest XDF run this can support is
// 21,474,836.47 seconds
// someone would need to idle in-game for 248 days
void print_time(const char *strcs) {
const unsigned int num = strtoul(strcs, NULL, 10);
unsigned int s = num/100;
const unsigned int cs = num % 100;
const unsigned int min = s/60;
s = s % 60;
if (min > 0) {
printf("<TD>%u:%.2u.%.2u</TD>", min, s, cs);
} else {
printf("<TD>%u.%.2u</TD>", s, cs);
}
}
// display and format the results of the query.
void qresult(sqlite3_stmt *sp, const char *c) {
void qresult(sqlite3_stmt * const sp, const char *c) {
int e;
unsigned int i;
unsigned int cc = sqlite3_column_count(sp);
print_tblheader(c);
unsigned int cc = sqlite3_column_count(sp);
const int cvt = print_tblheader(c);
while ((e = sqlite3_step(sp)) == SQLITE_ROW) {
printf("<TR>");
for (i = 0; i < cc; i++) {
printf("<TD>%s</TD>", sqlite3_column_text(sp, i));
if (i != cvt) {
printf("<TD>%s</TD>", sqlite3_column_text(sp, i));
} else {
print_time(sqlite3_column_text(sp, i));
}
}
printf("</TR>");
}

View File

@ -1,4 +1,4 @@
select trank, tvalue, ifnull(alias, "Unregistered Player")
select trank, ifnull(alias, "Unregistered Player"), tvalue
from Cts_times, Cts_ranks
left join Id2alias
on idvalue = cryptokey