Split up main.c while keeping a single compilation unit

This commit is contained in:
2026-05-17 14:30:52 +02:00
parent 87db03d189
commit cd0ef696d7
5 changed files with 241 additions and 237 deletions

35
src/id_store.c Normal file
View File

@@ -0,0 +1,35 @@
typedef struct {
Noh_String path;
Noh_String id;
} Id;
typedef struct {
Id *elems;
size_t count;
size_t capacity;
} Id_Store;
Id_Store id_store = {0};
SV get_id(SV path) {
for (size_t i = 0; i < id_store.count; i++) {
if (noh_sv_eq(path, noh_sv_from_string(id_store.elems[i].path)))
return noh_sv_from_string(id_store.elems[i].id);
}
uuid_t uuid;
uuid_generate(uuid);
char uuid_str[36];
uuid_unparse(uuid, uuid_str);
Noh_String new_id = {0};
noh_string_append_cstr(&new_id, "urn:uuid:");
noh_string_append_cstr(&new_id, uuid_str);
Noh_String stored_path = {0};
noh_string_append_sv(&stored_path, path);
noh_da_append(&id_store, ((Id){ .path = stored_path, .id = new_id }));
return noh_sv_from_string(new_id);
}