Cleanup code and update clang-format

This commit is contained in:
Alex D. 2021-09-11 19:45:33 +00:00
parent 6a0123a52b
commit 9855146f8b
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 186 additions and 222 deletions

View File

@ -1,41 +1,61 @@
---
BasedOnStyle: LLVM
AlignConsecutiveMacros: 'true'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'true'
AlignEscapedNewlines: Left
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLoopsOnASingleLine: 'true'
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: AllDefinitions
AlwaysBreakBeforeMultilineStrings: 'false'
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Linux
BreakStringLiterals: 'false'
ColumnLimit: '150'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
Cpp11BracedListStyle: 'false'
IncludeBlocks: Regroup
IndentCaseLabels: 'true'
IndentPPDirectives: None
IndentWidth: '8'
Standard: Auto
Language: Cpp
PointerAlignment: Left
ReflowComments: 'true'
SortIncludes: 'true'
SpaceAfterCStyleCast: 'true'
SpaceAfterLogicalNot: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'true'
SpaceBeforeParens: ControlStatements
SpacesInCStyleCastParentheses: 'false'
Standard: Cpp11
TabWidth: '8'
BasedOnStyle: LLVM
ColumnLimit: 0
IndentWidth: 8
TabWidth: 8
UseTab: ForIndentation
AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakStringLiterals: false
BreakConstructorInitializers: AfterColon
IndentCaseLabels: true
IndentPPDirectives: None
IndentGotoLabels: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
IncludeBlocks: Regroup
InsertTrailingCommas: Wrapped
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeParens: Always
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
...

150
llist.c
View File

@ -86,36 +86,29 @@ struct corelibs_llist_interface const cl_llist = {
};
static cl_llist_err
corelibs_llist_create(void* c, void (*const f)(void*), cl_llist_t** s)
{
corelibs_llist_create (void *c, void (*const f) (void *), cl_llist_t **s) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (s == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (!err) {
cl_llist_t *cur = malloc (sizeof (*cur));
if (cur == NULL) {
err = CORELIBS_LLIST_ERR_MEM_ALLOC;
goto ret;
}
if (cur != NULL) {
cur->prev = NULL;
cur->next = NULL;
cur->cont = c;
cur->free = f;
*s = cur;
ret:
} else {
err = CORELIBS_LLIST_ERR_MEM_ALLOC;
}
}
return err;
}
static cl_llist_err
corelibs_llist_free_list(cl_llist_t* l)
{
corelibs_llist_free_list (cl_llist_t *l) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (l == NULL) {
err = CORELIBS_LLIST_ERR_MEM_NULL;
goto ret;
}
if (l == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (!err) {
// Free previous elements if we have any
if (l->prev != NULL) {
for (cl_llist_t *p = l->prev; p != NULL;) {
@ -131,35 +124,25 @@ corelibs_llist_free_list(cl_llist_t* l)
p = p->next;
corelibs_llist_remove (c);
}
ret:
}
return err;
}
static cl_llist_err
corelibs_llist_free_elem(cl_llist_t* l)
{
corelibs_llist_free_elem (cl_llist_t *l) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (l == NULL) {
err = CORELIBS_LLIST_ERR_MEM_NULL;
goto ret;
}
if (l == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (!err) {
corelibs_llist_remove (l);
ret:
}
return err;
}
static cl_llist_err
corelibs_llist_link(uintmax_t cnt, ...)
{
corelibs_llist_link (uintmax_t cnt, ...) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (cnt <= 1) {
err = CORELIBS_LLIST_ERR_ARGS_MIS;
goto ret;
}
if (cnt <= 1) err = CORELIBS_LLIST_ERR_ARGS_MIS;
if (!err) {
va_list ap;
va_start (ap, cnt);
@ -177,117 +160,78 @@ corelibs_llist_link(uintmax_t cnt, ...)
}
va_end (ap);
ret:
}
return err;
}
static cl_llist_err
corelibs_llist_rep(cl_llist_t* dest, cl_llist_t* src)
{
corelibs_llist_rep (cl_llist_t *dest, cl_llist_t *src) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (src == NULL || dest == NULL) {
err = CORELIBS_LLIST_ERR_MEM_NULL;
goto ret;
}
if (src == NULL || dest == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (!err) {
if (dest->prev != NULL) dest->prev->next = src;
if (dest->next != NULL) dest->next->prev = src;
corelibs_llist_free_elem (dest);
ret:
}
return err;
}
static cl_llist_err
corelibs_llist_get_next(const cl_llist_t* e, cl_llist_t** save)
{
corelibs_llist_get_next (const cl_llist_t *e, cl_llist_t **save) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (e == NULL || save == NULL) {
err = CORELIBS_LLIST_ERR_MEM_NULL;
goto ret;
}
if (e->next == NULL) {
err = CORELIBS_LLIST_ERR_UNDEF;
goto ret;
}
if (e == NULL || save == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (e->next == NULL) err = CORELIBS_LLIST_ERR_UNDEF;
if (!err) {
*save = e->next;
ret:
}
return err;
}
static cl_llist_err
corelibs_llist_get_prev(const cl_llist_t* e, cl_llist_t** save)
{
corelibs_llist_get_prev (const cl_llist_t *e, cl_llist_t **save) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (e == NULL || save == NULL) {
err = CORELIBS_LLIST_ERR_MEM_NULL;
goto ret;
}
if (e->prev == NULL) {
err = CORELIBS_LLIST_ERR_UNDEF;
goto ret;
}
if (e == NULL || save == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (e->prev == NULL) err = CORELIBS_LLIST_ERR_UNDEF;
if (!err) {
*save = e->prev;
ret:
}
return err;
}
static cl_llist_err
corelibs_llist_get_cont(const cl_llist_t* e, void** save)
{
corelibs_llist_get_cont (const cl_llist_t *e, void **save) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (e == NULL || save == NULL) {
err = CORELIBS_LLIST_ERR_MEM_NULL;
goto ret;
}
if (e == NULL || save == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (!err) {
*save = e->cont;
ret:
}
return err;
}
static cl_llist_err
corelibs_llist_set_cont(cl_llist_t* e, void* i)
{
corelibs_llist_set_cont (cl_llist_t *e, void *i) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (e == NULL) {
err = CORELIBS_LLIST_ERR_MEM_NULL;
goto ret;
}
if (e == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (!err) {
e->cont = i;
ret:
}
return err;
}
static cl_llist_err
corelibs_llist_set_free(cl_llist_t* e, void (*const f)(void*))
{
corelibs_llist_set_free (cl_llist_t *e, void (*const f) (void *)) {
cl_llist_err err = CORELIBS_LLIST_ERR_OK;
if (e == NULL) {
err = CORELIBS_LLIST_ERR_MEM_NULL;
goto ret;
}
if (e == NULL) err = CORELIBS_LLIST_ERR_MEM_NULL;
if (!err) {
e->free = f;
ret:
}
return err;
}
// Private function
static void
corelibs_llist_remove(cl_llist_t* e)
{
corelibs_llist_remove (cl_llist_t *e) {
corelibs_llist_link (2, e->prev, e->next);
if (e->free != NULL) e->free (e->cont);
free (e);
}