Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_OBJECTS})
add_compile_definitions(_XOPEN_SOURCE=700)


# CTest-Unterstützung aktivieren
enable_testing()

# --- Add tools ---
add_subdirectory(tools)
Expand Down
2 changes: 1 addition & 1 deletion src/common/iniparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static bool is_digit(char ch) {
}

static bool is_key_char(char ch) {
return is_letter(ch) || is_digit(ch) || ch == '.' || ch == '-' || ch == '_';
return is_letter(ch) || is_digit(ch) || ch == '.' || ch == '-' || ch == '_' || ch == ':';
}

static bool is_at_end(const IniParser *parser) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/iniparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<WS> ::= ' ' | '\t'

<LETTER> ::= [a-zA-Z]
<KEY_CHAR> ::= <LETTER> | <DIGIT> | '.' | '-' | '_'
<KEY_CHAR> ::= <LETTER> | <DIGIT> | '.' | '-' | '_' | ':'
<KEY> ::= <KEY_CHAR> <KEY_CHAR>*

*****************************************/
Expand Down
3 changes: 3 additions & 0 deletions src/common/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ void String_Set(String *str, String src) {
}

void String_Take(String *dst, String *src) {
if (!dst || ! src) {
return;
}
String_Deinit(dst);
*dst = String_TakeCStr(src->bytes);

Expand Down
2 changes: 1 addition & 1 deletion src/common/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void String_Set(String *str, String src);
*
* Its for situation where dst is already initialized and your want to fill it
* with the content of another string without moving memory around.
* dst will be deinitialized!
* src will be deinitialized!
*/
void String_Take(String *dst, String *src);

Expand Down
19 changes: 19 additions & 0 deletions src/common/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ void *Table_Get(const Table *table, const char *key) {
if (!table) {
logFatal("Invalid table in Table_Get().");
}
if (table->used == 0) {
return NULL;
}
if (!key) {
logWarn("Table_Get() was called with key == NULL.");
return NULL;
Expand All @@ -236,6 +239,9 @@ void Table_Delete(Table *table, const char *key) {
if (!table) {
logFatal("Invalid table in Table_Delete().");
}
if (table->used == 0) {
return;
}
if (!key) {
logWarn("Table_Delete() is called with key == NULL.");
return;
Expand All @@ -255,6 +261,9 @@ bool Table_Has(const Table *table, const char *key) {
if (!table) {
logFatal("Invalid table in Table_Has().");
}
if (table->used == 0) {
return false;
}
if (!key) {
logWarn("Table_Has() was called with key == NULL.");
return false;
Expand All @@ -267,10 +276,20 @@ bool Table_HasOwnership(const Table *table, const char *key) {
if (!table) {
logFatal("Invalid table in Table_HasOwnership().");
}
if (table->used == 0) {
return false;
}
if (!key) {
logWarn("Table_HasOwnership() was called with key == NULL.");
return false;
}
TableSlot *slot = find_slot(table, key);
return (slot->state == TABLE_SLOT_USED && slot->destructor != NULL);
}

size_t Table_GetUsage(const Table *table) {
if (!table) {
return 0;
}
return table->used;
}
4 changes: 4 additions & 0 deletions src/common/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,9 @@ bool Table_Has(const Table *table, const char *key);
*/
bool Table_HasOwnership(const Table *table, const char *key);

/**
* @brief Return the current number of non-free table slots.
*/
size_t Table_GetUsage(const Table *table);

#endif
24 changes: 24 additions & 0 deletions src/common/tableiterator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "tableiterator.h"

TableIterator TableIterator_Begin(const Table *table) {
return (TableIterator){
.table = table,
.index = -1,
.current = NULL
};
}

bool TableIterator_Next(TableIterator *it) {
if (!it || !it->table) {
return false;
}
for (size_t i = (size_t)(it->index + 1); i < it->table->capacity; i++) {
TableSlot *slot = &it->table->slots[i];
if (slot->state == TABLE_SLOT_USED) {
it->index = i;
it->current = slot;
return true;
}
}
return false;
}
17 changes: 17 additions & 0 deletions src/common/tableiterator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef TABLEITERATOR_H
#define TABLEITERATOR_H

#include <sys/types.h>
#include <stdbool.h>
#include "table.h"

typedef struct _TableIterator {
const Table *table;
ssize_t index;
const TableSlot *current;
} TableIterator;

TableIterator TableIterator_Begin(const Table *table);
bool TableIterator_Next(TableIterator *it);

#endif
Comment thread
defname marked this conversation as resolved.
Loading