Skip to content

Commit 8b04432

Browse files
committed
jimp: introduce jimp_begin()
1 parent a465d70 commit 8b04432

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

examples/03_parsing_database.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,15 @@ typedef struct {
7070
size_t capacity;
7171
} Numbers;
7272

73-
int main()
73+
int main(void)
7474
{
75-
// const char *file_path = "profile.json";
76-
// const char *file_path = "numbers.json";
77-
// const char *file_path = "profiles.json";
78-
// const char *file_path = "empty.json";
79-
// const char *file_path = "one.json";
8075
const char *file_path = "database.json";
76+
8177
String_Builder sb = {0};
8278
if (!read_entire_file(file_path, &sb)) return 1;
83-
Jimp jimp = {
84-
.file_path = file_path,
85-
.start = sb.items,
86-
.end = sb.items + sb.count,
87-
.point = sb.items,
88-
};
79+
80+
Jimp jimp = {0};
81+
jimp_begin(&jimp, file_path, sb.items, sb.count);
8982

9083
People ps = {0};
9184
Numbers xs = {0};

jimp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ typedef struct {
5353

5454
// TODO: how do null-s fit into this entire system?
5555

56+
void jimp_begin(Jimp *jimp, const char *file_path, const char *input, size_t input_size);
57+
5658
/// If succeeds puts the freshly parsed boolean into jimp->boolean.
5759
/// Any consequent calls to the jimp_* functions may invalidate jimp->boolean.
5860
bool jimp_boolean(Jimp *jimp);
@@ -206,6 +208,14 @@ static bool jimp__get_token(Jimp *jimp)
206208
return false;
207209
}
208210

211+
void jimp_begin(Jimp *jimp, const char *file_path, const char *input, size_t input_size)
212+
{
213+
jimp->file_path = file_path;
214+
jimp->start = input;
215+
jimp->end = input + input_size;
216+
jimp->point = input;
217+
}
218+
209219
void jimp_diagf(Jimp *jimp, const char *fmt, ...)
210220
{
211221
long line_number = 0;

0 commit comments

Comments
 (0)