Skip to content

Commit

Permalink
Updated some formatter with PRIu64 macro
Browse files Browse the repository at this point in the history
  • Loading branch information
codepr committed Dec 11, 2024
1 parent 711b970 commit cd3fb1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
19 changes: 10 additions & 9 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ static ssize_t tokenize_select(Lexer *l, Token *tokens, size_t capacity)
} else if (strncmp(token.p, "AT", token.length) == 0) {
tokens[i].type = TOKEN_AT;
token = lexer_next(l);
if (sscanf(token.p, "%lli", &(int64_t){0}) == 1)
if (sscanf(token.p, "%" PRId64, &(int64_t){0}) == 1)
strncpy(tokens[i].value, token.p, token.length);
} else if (strncmp(token.p, "RANGE", token.length) == 0) {
tokens[i].type = TOKEN_RANGE;
token = lexer_next(l);
if (sscanf(token.p, "%lli", &(int64_t){0}) == 1)
if (sscanf(token.p, "%" PRId64, &(int64_t){0}) == 1)
strncpy(tokens[i].value, token.p, token.length);
// TOOD error here, missing the start timestamp
} else if (strncmp(token.p, "TO", token.length) == 0) {
tokens[i].type = TOKEN_TO;
token = lexer_next(l);
if (sscanf(token.p, "%lli", &(int64_t){0}) == 1)
if (sscanf(token.p, "%" PRId64, &(int64_t){0}) == 1)
strncpy(tokens[i].value, token.p, token.length);
// TOOD error here, missing the start timestamp
} else if (strncmp(token.p, "WHERE", token.length) == 0) {
Expand All @@ -199,7 +199,7 @@ static ssize_t tokenize_select(Lexer *l, Token *tokens, size_t capacity)
} else if (strncmp(token.p, "BY", token.length) == 0) {
tokens[i].type = TOKEN_BY;
token = lexer_next(l);
if (sscanf(token.p, "%llu", &(uint64_t){0}) == 1)
if (sscanf(token.p, "%" PRIu64, &(uint64_t){0}) == 1)
strncpy(tokens[i].value, token.p, token.length);
// TOOD error here, missing the start timestamp
} else {
Expand All @@ -217,7 +217,7 @@ static ssize_t tokenize_select(Lexer *l, Token *tokens, size_t capacity)
tokens[i].type = TOKEN_OPERATOR_NE;
}
token = lexer_next(l);
if (sscanf(token.p, "%llu", &(uint64_t){0}) == 1)
if (sscanf(token.p, "%" PRIu64, &(uint64_t){0}) == 1)
strncpy(tokens[i].value, token.p, token.length);
}
}
Expand Down Expand Up @@ -428,7 +428,7 @@ static void print_insert(const Statement_Insert *insert)
printf("INSERT\n\t%s\nINTO\n\t%s\n", insert->ts_name, insert->db_name);
printf("VALUES\n\t");
for (size_t i = 0; i < insert->record_len; ++i) {
printf("(%llu, %.2f) ", insert->records[i].timestamp,
printf("(%" PRId64 ", %.2f) ", insert->records[i].timestamp,
insert->records[i].value);
}
printf("\n");
Expand All @@ -438,16 +438,17 @@ static void print_select(const Statement_Select *select)
{
printf("SELECT\n\t%s\nFROM\n\t%s\n", select->ts_name, select->db_name);
if (select->mask & SM_SINGLE)
printf("AT\n\t%lli\n", select->start_time);
printf("AT\n\t%" PRId64 "\n", select->start_time);
else if (select->mask & SM_RANGE)
printf("RANGE\n\t%lli TO %lli\n", select->start_time, select->end_time);
printf("RANGE\n\t%" PRId64 " TO %" PRId64 "\n", select->start_time,
select->end_time);
if (select->mask & SM_WHERE)
printf("WHERE\n\t%s %i %.2lf\n", select->where.key,
select->where.operator, select->where.value);
if (select->mask & SM_AGGREGATE)
printf("AGGREAGATE\n\t%i\n", select->af);
if (select->mask & SM_BY)
printf("BY\n\t%llu\n", select->interval);
printf("BY\n\t%" PRIu64 "\n", select->interval);
}

void print_statement(const Statement *statement)
Expand Down
3 changes: 2 additions & 1 deletion src/protocol.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "protocol.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>

Expand Down Expand Up @@ -81,7 +82,7 @@ ssize_t encode_response(const Response *r, uint8_t *dst)
while (j < r->array_response.length) {
// Timestamp
dst[i++] = ':';
n = snprintf((char *)dst + i, 21, "%llu",
n = snprintf((char *)dst + i, 21, "%" PRIu64,
r->array_response.records[j].timestamp);
i += n;
dst[i++] = '\r';
Expand Down
4 changes: 3 additions & 1 deletion src/roach_cli.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "client.h"
#include "protocol.h"
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
Expand Down Expand Up @@ -44,7 +45,8 @@ static void print_response(const Response *rs)
printf("%s\n", rs->string_response.message);
} else {
for (size_t i = 0; i < rs->array_response.length; ++i)
printf("%llu %.6f\n", rs->array_response.records[i].timestamp,
printf("%" PRIu64 " %.6f\n",
rs->array_response.records[i].timestamp,
rs->array_response.records[i].value);
}
}
Expand Down

0 comments on commit cd3fb1d

Please sign in to comment.