Split up main.c while keeping a single compilation unit
This commit is contained in:
35
src/id_store.c
Normal file
35
src/id_store.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user